eth-erc20

ERC20 interface and example giftable token contract
Info | Log | Files | Refs | LICENSE

base.py (2056B)


      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 
     12 # local imports
     13 from giftable_erc20_token import GiftableToken
     14 
     15 logg = logging.getLogger(__name__)
     16 
     17 
     18 class TestGiftableToken(EthTesterCase):
     19 
     20     expire = 0
     21 
     22     def setUp(self):
     23         super(TestGiftableToken, self).setUp()
     24         self.conn = RPCConnection.connect(self.chain_spec, 'default')
     25        
     26         address = self.publish_giftable_token('Foo Token', 'FOO', 16, expire=self.expire)
     27         self.address = to_checksum_address(address)
     28         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     29         c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     30         self.initial_supply = 1 << 40
     31         (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], self.initial_supply)
     32         r = self.conn.do(o)
     33         o = receipt(tx_hash)
     34         r = self.conn.do(o)
     35         self.assertEqual(r['status'], 1)
     36 
     37 
     38     def publish_giftable_token(self, name, symbol, decimals=16, expire=None):
     39         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     40         c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     41         self.symbol = name
     42         self.name = symbol
     43         self.decimals = decimals
     44         (tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals, expire=expire)
     45         self.rpc.do(o)
     46         o = receipt(tx_hash)
     47         r = self.rpc.do(o)
     48         self.assertEqual(r['status'], 1)
     49         address = r['contract_address'] 
     50         logg.debug('published on address {} with hash {}'.format(address, tx_hash))
     51         return address
     52 
     53 
     54 class TestGiftableExpireToken(TestGiftableToken):
     55 
     56     expire = int(time.time()) + 100000
     57 
     58     def setUp(self):
     59         super(TestGiftableExpireToken, self).setUp()