erc20-limiter

ERC20 balance limit registry
Info | Log | Files | Refs | README

base.py (1914B)


      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 chainlib.eth.block import block_latest
     12 
     13 # local imports
     14 from erc20_limiter import Limiter
     15 from erc20_limiter.index import LimiterIndex
     16 
     17 logg = logging.getLogger(__name__)
     18 
     19 class TestLimiter(EthTesterCase):
     20 
     21     def setUp(self):
     22         super(TestLimiter, self).setUp()
     23         self.conn = RPCConnection.connect(self.chain_spec, 'default')
     24         self.address = self.publish_limiter()
     25 
     26 
     27     def publish_limiter(self):
     28         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     29         c = Limiter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     30         (tx_hash, o) = c.constructor(self.accounts[0])
     31         self.rpc.do(o)
     32         o = receipt(tx_hash)
     33         r = self.rpc.do(o)
     34         self.assertEqual(r['status'], 1)
     35         address = to_checksum_address(r['contract_address'])
     36         logg.debug('published limiter on address {} with hash {}'.format(address, tx_hash))
     37         return address
     38 
     39 
     40 class TestLimiterIndex(TestLimiter):
     41 
     42     def publish_token_registry(self, holder_address, limiter_address):
     43         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     44         c = LimiterIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     45         (tx_hash, o) = c.constructor(self.accounts[0], holder_address, limiter_address)
     46         self.rpc.do(o)
     47         o = receipt(tx_hash)
     48         r = self.rpc.do(o)
     49         self.assertEqual(r['status'], 1)
     50         address = to_checksum_address(r['contract_address'])
     51         logg.debug('published limiter token registry proxy on address {} with hash {}'.format(address, tx_hash))
     52         return address