test_growth.py (1864B)
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 20 # test imports 21 from erc20_demurrage_token.unittest import TestDemurrageDefault 22 23 logging.basicConfig(level=logging.DEBUG) 24 logg = logging.getLogger() 25 26 testdir = os.path.dirname(__file__) 27 28 29 class TestGrowth(TestDemurrageDefault): 30 31 def test_decay_by(self): 32 nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) 33 c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 34 35 v = 1000000000 36 o = c.decay_by(self.address, v, 20000, sender_address=self.accounts[0]) 37 r = self.rpc.do(o) 38 g = c.parse_decay_by(r) 39 self.assertEqual(int(g), 990690498) 40 41 o = c.decay_by(self.address, v, 43200, sender_address=self.accounts[0]) 42 r = self.rpc.do(o) 43 g = c.parse_decay_by(r) 44 self.assertEqual(int(g), 980000000) 45 46 47 def test_decay_steps(self): 48 nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) 49 c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 50 51 v = 1000000000 52 o = c.decay_by(self.address, v, 43200, sender_address=self.accounts[0]) 53 r = self.rpc.do(o) 54 gr = c.parse_decay_by(r) 55 56 v = 1000000000 57 for i in range(100): 58 o = c.decay_by(self.address, v, 432, sender_address=self.accounts[0]) 59 r = self.rpc.do(o) 60 v = c.parse_decay_by(r) 61 62 self.assert_within_lower(int(v), int(gr), 0.1) 63 64 65 if __name__ == '__main__': 66 unittest.main()