erc20-pool

Permissioned ERC20 swap pool for EVM
Info | Log | Files | Refs | README

test_token.py (3326B)


      1 # standard imports
      2 import unittest
      3 import logging
      4 import os
      5 from chainlib.eth.nonce import RPCNonceOracle
      6 from chainlib.eth.tx import receipt
      7 from chainlib.eth.block import block_latest
      8 from hexathon import same as same_hex
      9 from eth_erc20 import ERC20
     10 from giftable_erc20_token import GiftableToken
     11 from erc20_limiter import Limiter
     12 
     13 # local imports
     14 from erc20_pool.unittest import TestERC20PoolLimiter
     15 from erc20_pool import Pool
     16 
     17 logging.basicConfig(level=logging.DEBUG)
     18 logg = logging.getLogger()
     19 
     20 class TestPoolLimit(TestERC20PoolLimiter):
     21 
     22     def test_deposit_limit(self):
     23         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     24         c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     25         (tx_hash, o) = c.approve(self.foo_address, self.accounts[0], self.pool_address, 1024)
     26         self.rpc.do(o)
     27         o = receipt(tx_hash)
     28         r = self.rpc.do(o)
     29         self.assertEqual(r['status'], 1)
     30 
     31         c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     32         (tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 513)
     33         self.rpc.do(o)
     34         o = receipt(tx_hash)
     35         r = self.rpc.do(o)
     36         self.assertEqual(r['status'], 0)
     37 
     38         c = Limiter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     39         (tx_hash, o) = c.set_limit(self.limiter_address, self.accounts[0], self.foo_address, 512, holder_address=self.pool_address)
     40         self.rpc.do(o)
     41         o = receipt(tx_hash)
     42         r = self.rpc.do(o)
     43         self.assertEqual(r['status'], 1)
     44 
     45         o = c.limit_of(self.limiter_address, self.foo_address, self.pool_address, sender_address=self.accounts[0])
     46         r = self.rpc.do(o)
     47         self.assertEqual(int(r, 16), 512)
     48 
     49         c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     50         (tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 513)
     51         self.rpc.do(o)
     52         o = receipt(tx_hash)
     53         r = self.rpc.do(o)
     54         self.assertEqual(r['status'], 0)
     55 
     56         c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     57         (tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 512)
     58         self.rpc.do(o)
     59         o = receipt(tx_hash)
     60         r = self.rpc.do(o)
     61         self.assertEqual(r['status'], 1)
     62 
     63         c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     64         (tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 1)
     65         self.rpc.do(o)
     66         o = receipt(tx_hash)
     67         r = self.rpc.do(o)
     68         self.assertEqual(r['status'], 0)
     69 
     70         c = Limiter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     71         (tx_hash, o) = c.set_limit(self.limiter_address, self.accounts[0], self.foo_address, 513, holder_address=self.pool_address)
     72         self.rpc.do(o)
     73         o = receipt(tx_hash)
     74         r = self.rpc.do(o)
     75         self.assertEqual(r['status'], 1)
     76 
     77         c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     78         (tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 1)
     79         self.rpc.do(o)
     80         o = receipt(tx_hash)
     81         r = self.rpc.do(o)
     82         self.assertEqual(r['status'], 1)
     83 
     84 
     85 if __name__ == '__main__':
     86     unittest.main()