test_base.py (2712B)
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 12 # local imports 13 from erc20_pool.unittest import TestERC20Pool 14 from erc20_pool import Pool 15 16 logging.basicConfig(level=logging.DEBUG) 17 logg = logging.getLogger() 18 19 class TestPoolBase(TestERC20Pool): 20 21 def test_deposit(self): 22 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 23 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 24 (tx_hash, o) = c.approve(self.foo_address, self.accounts[0], self.pool_address, 1024) 25 self.rpc.do(o) 26 27 c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 28 (tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 1024) 29 self.rpc.do(o) 30 o = receipt(tx_hash) 31 r = self.rpc.do(o) 32 self.assertEqual(r['status'], 1) 33 34 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 35 o = c.balance_of(self.foo_address, self.pool_address, sender_address=self.accounts[0]) 36 r = self.rpc.do(o) 37 self.assertEqual(int(r, 16), 1024) 38 39 40 def test_swap(self): 41 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 42 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 43 (tx_hash, o) = c.approve(self.foo_address, self.accounts[0], self.pool_address, 1024) 44 self.rpc.do(o) 45 46 c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 47 (tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 1024) 48 self.rpc.do(o) 49 50 nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn) 51 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 52 (tx_hash, o) = c.approve(self.bar_address, self.accounts[1], self.pool_address, 768) 53 self.rpc.do(o) 54 55 c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 56 (tx_hash, o) = c.swap(self.pool_address, self.accounts[1], self.foo_address, self.bar_address, 768) 57 self.rpc.do(o) 58 o = receipt(tx_hash) 59 r = self.rpc.do(o) 60 self.assertEqual(r['status'], 1) 61 62 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 63 o = c.balance_of(self.foo_address, self.accounts[1], sender_address=self.accounts[0]) 64 r = self.rpc.do(o) 65 self.assertEqual(int(r, 16), 768) 66 67 68 if __name__ == '__main__': 69 unittest.main()