erc20-pool

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

base.py (3262B)


      1 # standard imports
      2 import logging
      3 import time
      4 
      5 # external imports
      6 from chainlib.eth.unittest.ethtester import EthTesterCase
      7 from chainlib.connection import RPCConnection
      8 from chainlib.eth.nonce import RPCNonceOracle
      9 from chainlib.eth.tx import receipt
     10 from chainlib.eth.address import to_checksum_address
     11 from giftable_erc20_token.unittest import TestGiftableToken
     12 from eth_erc20 import ERC20
     13 from chainlib.eth.block import block_latest
     14 from eth_accounts_index.unittest import TestAccountsIndex
     15 from eth_accounts_index.registry import AccountRegistry
     16 from giftable_erc20_token import GiftableToken
     17 from erc20_limiter.unittest import TestLimiter
     18 
     19 # local imports
     20 from erc20_pool import Pool
     21 
     22 logg = logging.getLogger(__name__)
     23 
     24 hash_of_foo = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
     25 #hash_of_bar = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9'
     26 #hash_of_baz = 'baa5a0964d3320fbc0c6a922140453c8513ea24ab8fd0577034804a967248096'
     27 
     28 
     29 class TestERC20PoolBase(TestGiftableToken):
     30 
     31     expire = 0
     32 
     33     def setUp(self):
     34         super(TestERC20PoolBase, self).setUp()
     35         self.foo_address = self.address
     36         self.publish_tokens()
     37 
     38 
     39     def publish_tokens(self):
     40         self.bar_address = self.publish_giftable_token('Bar Token', 'BAR', 16)
     41         self.baz_address = self.publish_giftable_token('Baz Token', 'BAZ', 16)
     42         self.initial_supply_bar = 1 << 20
     43         self.initial_supply_baz = 1 << 15
     44 
     45         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     46         c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     47         (tx_hash, o) = c.mint_to(self.bar_address, self.accounts[0], self.accounts[1], self.initial_supply_bar)
     48         self.conn.do(o)
     49         o = receipt(tx_hash)
     50         r = self.conn.do(o)
     51         self.assertEqual(r['status'], 1)
     52 
     53         (tx_hash, o) = c.mint_to(self.baz_address, self.accounts[0], self.accounts[2], self.initial_supply_baz)
     54         self.conn.do(o)
     55         o = receipt(tx_hash)
     56         r = self.conn.do(o)
     57         self.assertEqual(r['status'], 1)
     58 
     59 
     60     def publish_pool(self, token_registry=None, token_limiter=None):
     61         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     62         c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     63         (tx_hash, o) = c.constructor(self.accounts[0], "Big Pool", "BIG", 16, token_registry=token_registry, token_limiter=token_limiter)
     64         self.rpc.do(o)
     65         o = receipt(tx_hash)
     66         r = self.rpc.do(o)
     67         self.assertEqual(r['status'], 1)
     68         self.pool_address = to_checksum_address(r['contract_address'])
     69         self.address = self.pool_address
     70         logg.debug('published bar token {}, baz token {}'.format(self.bar_address, self.baz_address))
     71         logg.debug('published pool on address {} with hash {}'.format(self.pool_address, tx_hash))
     72 
     73 
     74 class TestERC20Pool(TestERC20PoolBase):
     75 
     76 
     77     def setUp(self):
     78         super(TestERC20Pool, self).setUp()
     79         self.publish_pool()
     80 
     81 
     82 class TestERC20PoolLimiter(TestERC20PoolBase, TestLimiter):
     83 
     84     def setUp(self):
     85         super(TestERC20PoolLimiter, self).setUp()
     86         self.limiter_address = self.publish_limiter() 
     87         self.publish_pool(token_limiter=self.limiter_address)