base.py (1806B)
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 giftable_erc20_token.unittest import TestGiftableToken 12 from eth_erc20 import ERC20 13 from chainlib.eth.block import block_latest 14 15 # local imports 16 from erc20_vend import Vend 17 18 logg = logging.getLogger(__name__) 19 20 class TestVendCore(TestGiftableToken): 21 22 expire = 0 23 24 def setUp(self): 25 super(TestVendCore, self).setUp() 26 27 self.alice = self.accounts[1] 28 self.bob = self.accounts[2] 29 30 self.token_address = self.address 31 32 c = ERC20(self.chain_spec) 33 o = c.decimals(self.token_address, sender_address=self.accounts[0]) 34 r = self.rpc.do(o) 35 self.token_decimals = c.parse_decimals(r) 36 37 38 def publish(self, mint=False, decimals=0): 39 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 40 c = Vend(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 41 (tx_hash, o) = c.constructor(self.accounts[0], self.token_address, mint=mint, decimals=decimals) 42 self.rpc.do(o) 43 o = receipt(tx_hash) 44 r = self.rpc.do(o) 45 self.assertEqual(r['status'], 1) 46 self.vend_address = to_checksum_address(r['contract_address']) 47 logg.debug('published vend on address {} with hash {}'.format(self.vend_address, tx_hash)) 48 49 50 class TestVend(TestVendCore): 51 52 def setUp(self): 53 super(TestVend, self).setUp() 54 self.publish() 55 56 57 class TestVendParams(TestVendCore): 58 59 def setUp(self): 60 super(TestVendParams, self).setUp() 61 self.publish(lock=True, decimals=2)