erc20-demurrage-token

ERC20 token with redistributed continual demurrage
Info | Log | Files | Refs | README

test_mint.py (2527B)


      1 # standard imports
      2 import os
      3 import unittest
      4 import json
      5 import logging
      6 
      7 # external imports
      8 from chainlib.eth.constant import ZERO_ADDRESS
      9 from chainlib.eth.nonce import RPCNonceOracle
     10 from chainlib.eth.tx import receipt
     11 from chainlib.eth.block import block_latest
     12 from chainlib.eth.block import block_by_number
     13 
     14 # local imports
     15 from erc20_demurrage_token import DemurrageToken
     16 
     17 # test imports
     18 from erc20_demurrage_token.unittest import TestDemurrageDefault
     19 
     20 logging.basicConfig(level=logging.DEBUG)
     21 logg = logging.getLogger()
     22 
     23 testdir = os.path.dirname(__file__)
     24 
     25 class TestAmounts(TestDemurrageDefault):
     26 
     27     def test_mint(self):
     28         o = block_latest()
     29         r = self.rpc.do(o)
     30         o = block_by_number(r)
     31         r = self.rpc.do(o)
     32         tb = r['timestamp']
     33         self.backend.time_travel(self.start_time + 800)
     34         o = block_latest()
     35         r = self.rpc.do(o)
     36         o = block_by_number(r)
     37         r = self.rpc.do(o)
     38         ta = r['timestamp']
     39 
     40         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     41         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     42         (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 1000)
     43         r = self.rpc.do(o)
     44         o = receipt(tx_hash)
     45         r = self.rpc.do(o)
     46         self.assertEqual(r['status'], 1)
     47 
     48 
     49     def test_writer(self):
     50         nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
     51         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     52         (tx_hash, o) = c.mint_to(self.address, self.accounts[1], self.accounts[1], 1000)
     53         r = self.rpc.do(o)
     54         o = receipt(tx_hash)
     55         r = self.rpc.do(o)
     56         self.assertEqual(r['status'], 0)
     57 
     58 
     59         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     60         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     61         (tx_hash, o) = c.add_writer(self.address, self.accounts[0], self.accounts[1])
     62         r = self.rpc.do(o)
     63         o = receipt(tx_hash)
     64         r = self.rpc.do(o)
     65         self.assertEqual(r['status'], 1)
     66 
     67         nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
     68         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     69         (tx_hash, o) = c.mint_to(self.address, self.accounts[1], self.accounts[1], 1000)
     70         r = self.rpc.do(o)
     71         o = receipt(tx_hash)
     72         r = self.rpc.do(o)
     73         self.assertEqual(r['status'], 1)
     74 
     75 
     76 if __name__ == '__main__':
     77     unittest.main()