test_fee.py (3267B)
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 TestPoolFee(TestERC20Pool): 20 21 def test_swap_fee(self): 22 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 23 c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 24 (tx_hash, o) = c.set_fee_address(self.pool_address, self.accounts[0], self.accounts[9]) 25 self.rpc.do(o) 26 o = receipt(tx_hash) 27 r = self.conn.do(o) 28 self.assertEqual(r['status'], 1) 29 30 (tx_hash, o) = c.set_fee(self.pool_address, self.accounts[0], 10000) 31 self.rpc.do(o) 32 o = receipt(tx_hash) 33 r = self.conn.do(o) 34 self.assertEqual(r['status'], 1) 35 36 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 37 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 38 (tx_hash, o) = c.approve(self.foo_address, self.accounts[0], self.pool_address, 1000) 39 self.rpc.do(o) 40 41 c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 42 (tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 1000) 43 self.rpc.do(o) 44 45 nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn) 46 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 47 (tx_hash, o) = c.approve(self.bar_address, self.accounts[1], self.pool_address, 1000) 48 self.rpc.do(o) 49 50 c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 51 (tx_hash, o) = c.swap(self.pool_address, self.accounts[1], self.foo_address, self.bar_address, 1000) 52 self.rpc.do(o) 53 54 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 55 o = c.balance_of(self.foo_address, self.accounts[1], sender_address=self.accounts[0]) 56 r = self.rpc.do(o) 57 self.assertEqual(int(r, 16), 990) 58 59 c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 60 (tx_hash, o) = c.withdraw(self.pool_address, self.accounts[1], self.foo_address) 61 self.rpc.do(o) 62 o = receipt(tx_hash) 63 r = self.conn.do(o) 64 self.assertEqual(r['status'], 0) 65 66 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 67 c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 68 (tx_hash, o) = c.withdraw(self.pool_address, self.accounts[0], self.foo_address) 69 self.rpc.do(o) 70 o = receipt(tx_hash) 71 r = self.conn.do(o) 72 self.assertEqual(r['status'], 1) 73 74 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 75 o = c.balance_of(self.foo_address, self.accounts[9], sender_address=self.accounts[0]) 76 r = self.rpc.do(o) 77 self.assertEqual(int(r, 16), 10) 78 79 80 if __name__ == '__main__': 81 unittest.main()