test_index.py (1550B)
1 # standard imports 2 import unittest 3 import logging 4 5 # external imports 6 from chainlib.eth.nonce import RPCNonceOracle 7 from chainlib.eth.tx import receipt 8 9 # local imports 10 from erc20_limiter import Limiter 11 from erc20_limiter.index import LimiterIndex 12 from erc20_limiter.unittest import TestLimiterIndex 13 14 logging.basicConfig(level=logging.DEBUG) 15 logg = logging.getLogger() 16 17 18 class TestLimiterBase(TestLimiterIndex): 19 20 def setUp(self): 21 super(TestLimiterBase, self).setUp() 22 self.publish_limiter() 23 self.token_registry = self.publish_token_registry(self.accounts[0], self.address) 24 logg.debug('tokenreg {}'.format(self.token_registry)) 25 26 27 def test_limit(self): 28 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 29 30 foo_token = '2c26b46b68ffc68ff99b453c1d30413413422d70' 31 c = LimiterIndex(self.chain_spec) 32 o = c.have(self.token_registry, foo_token, sender_address=self.accounts[0]) 33 r = self.rpc.do(o) 34 self.assertEqual(int(r, 16), 0) 35 36 c = Limiter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 37 (tx_hash, o) = c.set_limit(self.address, self.accounts[0], foo_token, 42) 38 self.rpc.do(o) 39 o = receipt(tx_hash) 40 r = self.rpc.do(o) 41 self.assertEqual(r['status'], 1) 42 43 c = LimiterIndex(self.chain_spec) 44 o = c.have(self.token_registry, foo_token, sender_address=self.accounts[0]) 45 r = self.rpc.do(o) 46 self.assertEqual(int(r, 16), 1) 47 48 49 if __name__ == '__main__': 50 unittest.main() 51