test_supply.py (2958B)
1 # standard imports 2 import unittest 3 import logging 4 import os 5 from chainlib.eth.nonce import RPCNonceOracle 6 from chainlib.eth.contract import ABIContractLogDecoder 7 from chainlib.eth.contract import ABIContractType 8 from chainlib.eth.tx import receipt 9 from eth_erc20 import ERC20 10 from giftable_erc20_token import GiftableToken 11 from hexathon import same as same_hex 12 13 # local imports 14 from erc20_vend.unittest.base import TestVendCore 15 from erc20_vend import Vend 16 17 18 logging.basicConfig(level=logging.DEBUG) 19 logg = logging.getLogger() 20 21 22 class TestVendBase(TestVendCore): 23 24 def test_create_token_event(self): 25 self.publish() 26 27 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 28 c = Vend(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 29 (tx_hash, o) = c.create(self.vend_address, self.accounts[0], 'foo vend', 'FOOVEND') 30 self.rpc.do(o) 31 32 o = c.get_token(self.vend_address, 0, sender_address=self.accounts[0]) 33 r = self.rpc.do(o) 34 vended_token_address = c.parse_token(r) 35 36 c = ERC20(self.chain_spec) 37 o = c.total_supply(vended_token_address, sender_address=self.accounts[0]) 38 r = self.rpc.do(o) 39 self.assertEqual(int(r, 16), self.initial_supply) 40 41 42 def test_create_token_nomint_event(self): 43 self.publish(mint=True) 44 45 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 46 c = Vend(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 47 (tx_hash, o) = c.create(self.vend_address, self.accounts[0], 'foo vend', 'FOOVEND') 48 self.rpc.do(o) 49 50 o = c.get_token(self.vend_address, 0, sender_address=self.accounts[0]) 51 r = self.rpc.do(o) 52 vended_token_address = c.parse_token(r) 53 54 c = ERC20(self.chain_spec) 55 o = c.total_supply(vended_token_address, sender_address=self.accounts[0]) 56 r = self.rpc.do(o) 57 self.assertEqual(int(r, 16), 0) 58 59 vend_amount = 100 60 src_amount = vend_amount * (10 ** self.token_decimals) 61 c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 62 (tx_hash, o) = c.mint_to(self.token_address, self.accounts[0], self.alice, src_amount) 63 self.rpc.do(o) 64 65 nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn) 66 c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 67 (tx_hash, o) = c.approve(self.token_address, self.alice, self.vend_address, src_amount) 68 self.rpc.do(o) 69 70 c = Vend(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 71 (tx_hash, o) = c.deposit(self.vend_address, self.alice, vended_token_address) 72 self.rpc.do(o) 73 74 c = ERC20(self.chain_spec) 75 o = c.total_supply(vended_token_address, sender_address=self.accounts[0]) 76 r = self.rpc.do(o) 77 self.assertEqual(int(r, 16), vend_amount) 78 79 80 if __name__ == '__main__': 81 unittest.main()