erc20-demurrage-token

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

test_seal.py (6518B)


      1 # standard imports
      2 import os
      3 import unittest
      4 import json
      5 import logging
      6 import datetime
      7 
      8 # external imports
      9 from chainlib.eth.constant import ZERO_ADDRESS
     10 from chainlib.eth.nonce import RPCNonceOracle
     11 from chainlib.eth.tx import receipt
     12 from chainlib.eth.block import (
     13         block_latest,
     14         block_by_number,
     15     )
     16 
     17 # local imports
     18 from erc20_demurrage_token import DemurrageToken
     19 from erc20_demurrage_token.seal import ContractState
     20 from erc20_demurrage_token.seal import CONTRACT_SEAL_STATE_MAX
     21 
     22 # test imports
     23 from erc20_demurrage_token.unittest import TestDemurrageDefault
     24 
     25 logging.basicConfig(level=logging.DEBUG)
     26 logg = logging.getLogger()
     27 
     28 testdir = os.path.dirname(__file__)
     29 
     30 
     31 
     32 class TestSeal(TestDemurrageDefault):
     33 
     34     def test_seal_dup(self):
     35         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     36         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     37 
     38         (tx_hash, o) = c.seal(self.address, self.accounts[0], 1)
     39         r = self.rpc.do(o)
     40         o = receipt(tx_hash)
     41         r = self.rpc.do(o)
     42         self.assertEqual(r['status'], 1)
     43 
     44         (tx_hash, o) = c.seal(self.address, self.accounts[0], 1)
     45         r = self.rpc.do(o)
     46         o = receipt(tx_hash)
     47         r = self.rpc.do(o)
     48         self.assertEqual(r['status'], 0)
     49 
     50 
     51     def test_seal_all(self):
     52         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     53         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     54 
     55         (tx_hash, o) = c.seal(self.address, self.accounts[0], CONTRACT_SEAL_STATE_MAX)
     56         r = self.rpc.do(o)
     57         o = receipt(tx_hash)
     58         r = self.rpc.do(o)
     59         self.assertEqual(r['status'], 1)
     60 
     61         o = c.is_sealed(self.address, 0, sender_address=self.accounts[0])
     62         r = self.rpc.do(o)
     63         self.assertTrue(c.parse_is_sealed(r))
     64 
     65 
     66     def test_seal_minter(self):
     67         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     68         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     69     
     70         (tx_hash, o) = c.add_minter(self.address, self.accounts[0], self.accounts[1])
     71         r = self.rpc.do(o)
     72         o = receipt(tx_hash)
     73         r = self.rpc.do(o)
     74         self.assertEqual(r['status'], 1)
     75 
     76         (tx_hash, o) = c.seal(self.address, self.accounts[0], ContractState.MINTER_STATE)
     77         r = self.rpc.do(o)
     78         o = receipt(tx_hash)
     79         r = self.rpc.do(o)
     80         self.assertEqual(r['status'], 1)
     81 
     82         (tx_hash, o) = c.add_minter(self.address, self.accounts[0], self.accounts[2])
     83         r = self.rpc.do(o)
     84         o = receipt(tx_hash)
     85         r = self.rpc.do(o)
     86         self.assertEqual(r['status'], 0)
     87 
     88         o = c.is_sealed(self.address, ContractState.MINTER_STATE, sender_address=self.accounts[0])
     89         r = self.rpc.do(o)
     90         self.assertTrue(c.parse_is_sealed(r))
     91 
     92 
     93     def test_seal_expiry(self):
     94         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     95         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     96     
     97         (tx_hash, o) = c.set_expire_period(self.address, self.accounts[0], 10)
     98         r = self.rpc.do(o)
     99         o = receipt(tx_hash)
    100         r = self.rpc.do(o)
    101         self.assertEqual(r['status'], 1)
    102 
    103         (tx_hash, o) = c.set_expire_period(self.address, self.accounts[0], 20)
    104         r = self.rpc.do(o)
    105         o = receipt(tx_hash)
    106         r = self.rpc.do(o)
    107         self.assertEqual(r['status'], 1)
    108 
    109         (tx_hash, o) = c.seal(self.address, self.accounts[0], ContractState.EXPIRY_STATE)
    110         r = self.rpc.do(o)
    111         o = receipt(tx_hash)
    112         r = self.rpc.do(o)
    113         self.assertEqual(r['status'], 1)
    114 
    115         (tx_hash, o) = c.set_expire_period(self.address, self.accounts[0], 21)
    116         r = self.rpc.do(o)
    117         o = receipt(tx_hash)
    118         r = self.rpc.do(o)
    119         self.assertEqual(r['status'], 0)
    120 
    121         o = c.is_sealed(self.address, ContractState.EXPIRY_STATE, sender_address=self.accounts[0])
    122         r = self.rpc.do(o)
    123         self.assertTrue(c.parse_is_sealed(r))
    124 
    125 
    126     def test_seal_set_sink_address(self):
    127         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    128         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    129     
    130         (tx_hash, o) = c.set_sink_address(self.address, self.accounts[0], self.accounts[3])
    131         r = self.rpc.do(o)
    132         o = receipt(tx_hash)
    133         r = self.rpc.do(o)
    134         self.assertEqual(r['status'], 1)
    135 
    136         (tx_hash, o) = c.set_sink_address(self.address, self.accounts[0], self.accounts[4])
    137         r = self.rpc.do(o)
    138         o = receipt(tx_hash)
    139         r = self.rpc.do(o)
    140         self.assertEqual(r['status'], 1)
    141 
    142         (tx_hash, o) = c.seal(self.address, self.accounts[0], ContractState.SINK_STATE)
    143         r = self.rpc.do(o)
    144         o = receipt(tx_hash)
    145         r = self.rpc.do(o)
    146         self.assertEqual(r['status'], 1)
    147 
    148         (tx_hash, o) = c.set_sink_address(self.address, self.accounts[0], self.accounts[5])
    149         r = self.rpc.do(o)
    150         o = receipt(tx_hash)
    151         r = self.rpc.do(o)
    152         self.assertEqual(r['status'], 0)
    153 
    154         o = c.is_sealed(self.address, ContractState.SINK_STATE, sender_address=self.accounts[0])
    155         r = self.rpc.do(o)
    156         self.assertTrue(c.parse_is_sealed(r))
    157 
    158 
    159     def test_seal_cap(self):
    160         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    161         c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    162     
    163         (tx_hash, o) = c.set_max_supply(self.address, self.accounts[0], 100)
    164         r = self.rpc.do(o)
    165         o = receipt(tx_hash)
    166         r = self.rpc.do(o)
    167         self.assertEqual(r['status'], 1)
    168 
    169         (tx_hash, o) = c.set_max_supply(self.address, self.accounts[0], 200)
    170         r = self.rpc.do(o)
    171         o = receipt(tx_hash)
    172         r = self.rpc.do(o)
    173         self.assertEqual(r['status'], 1)
    174 
    175         (tx_hash, o) = c.seal(self.address, self.accounts[0], ContractState.CAP_STATE)
    176         r = self.rpc.do(o)
    177         o = receipt(tx_hash)
    178         r = self.rpc.do(o)
    179         self.assertEqual(r['status'], 1)
    180 
    181         (tx_hash, o) = c.set_max_supply(self.address, self.accounts[0], 300)
    182         r = self.rpc.do(o)
    183         o = receipt(tx_hash)
    184         r = self.rpc.do(o)
    185         self.assertEqual(r['status'], 0)
    186 
    187         o = c.is_sealed(self.address, ContractState.CAP_STATE, sender_address=self.accounts[0])
    188         r = self.rpc.do(o)
    189         self.assertTrue(c.parse_is_sealed(r))
    190 
    191 
    192 if __name__ == '__main__':
    193     unittest.main()
    194 
    195