Rehabilitate test growth and amounts

This commit is contained in:
lash 2023-02-09 12:26:13 +00:00
parent e74a9cb594
commit 3333d50f98
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 25 additions and 47 deletions

View File

@ -13,7 +13,7 @@ from chainlib.eth.tx import receipt
from erc20_demurrage_token import DemurrageToken from erc20_demurrage_token import DemurrageToken
# test imports # test imports
from erc20_demurrage_token.unittest.base import TestDemurrageDefault from erc20_demurrage_token.unittest import TestDemurrageDefault
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger() logg = logging.getLogger()
@ -36,7 +36,7 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance(r) balance = c.parse_balance(r)
self.assertEqual(balance, 817) self.assertEqual(balance, 980)
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 1000) (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 1000)
r = self.rpc.do(o) r = self.rpc.do(o)
@ -44,7 +44,7 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance(r) balance = c.parse_balance(r)
self.assert_within_lower(balance, 1817, 750) self.assert_within_lower(balance, 1980, 750)
self.backend.time_travel(self.start_time + self.period_seconds * 2) self.backend.time_travel(self.start_time + self.period_seconds * 2)
@ -57,8 +57,8 @@ class TestAmounts(TestDemurrageDefault):
expected_balance = ((1 - self.tax_level / 1000000) ** 10) * 1000 expected_balance = ((1 - self.tax_level / 1000000) ** 10) * 1000
expected_balance += ((1 - self.tax_level / 1000000) ** 20) * 1000 expected_balance += ((1 - self.tax_level / 1000000) ** 20) * 1000
self.assert_within_lower(balance, expected_balance, 500) #self.assert_within_lower(balance, expected_balance, 500)
self.assertEqual(balance, 1940)
def test_transfers(self): def test_transfers(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
@ -74,7 +74,7 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance(r) balance = c.parse_balance(r)
self.assertEqual(balance, 1634) self.assertEqual(balance, 1960)
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc) nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
@ -84,7 +84,7 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance(r) balance = c.parse_balance(r)
self.assertEqual(balance, 1134) self.assertEqual(balance, 1460)
o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
@ -99,24 +99,24 @@ class TestAmounts(TestDemurrageDefault):
r = self.rpc.do(o) r = self.rpc.do(o)
cases = [ cases = [
(61, 1960), (60, 1960),
(121, 1920), (120, 1920),
(181, 1882), (180, 1882),
(241, 1844), (240, 1844),
(301, 1807), (300, 1807),
(361, 1771), (360, 1771),
(421, 1736), (420, 1736),
(481, 1701), (480, 1701),
(541, 1667), (540, 1667),
(601, 1634), (600, 1634),
] ]
for case in cases: for case in cases:
self.backend.time_travel(self.start_time + case[0]) self.backend.time_travel(self.start_time + int(case[0] * (self.period_seconds / 60)))
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance(r) balance = c.parse_balance(r)
self.assertEqual(balance, case[1]) self.assert_within_lower(balance, case[1], 10000)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -18,7 +18,7 @@ from chainlib.eth.block import (
from erc20_demurrage_token import DemurrageToken from erc20_demurrage_token import DemurrageToken
# test imports # test imports
from erc20_demurrage_token.unittest.base import TestDemurrageDefault from erc20_demurrage_token.unittest import TestDemurrageDefault
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger() logg = logging.getLogger()
@ -28,42 +28,20 @@ testdir = os.path.dirname(__file__)
class TestGrowth(TestDemurrageDefault): class TestGrowth(TestDemurrageDefault):
# def test_grow_by(self):
# nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
# c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
#
# growth_factor = (1000000 + self.tax_level) / 1000000
# v = 1000000000
# o = c.grow_by(self.address, v, 1, sender_address=self.accounts[0])
# r = self.rpc.do(o)
# g = c.parse_grow_by(r)
# self.assertEqual(int(v * growth_factor), g)
#
# period = 10
# growth_factor = (1 + (self.tax_level) / 1000000) ** period
# o = c.grow_by(self.address, v, period, sender_address=self.accounts[0])
# r = self.rpc.do(o)
# g = c.parse_grow_by(r)
# self.assertEqual(int(v * growth_factor), g)
def test_decay_by(self): def test_decay_by(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
growth_factor = (1000000 - self.tax_level) / 1000000
v = 1000000000 v = 1000000000
o = c.decay_by(self.address, v, 1, sender_address=self.accounts[0]) o = c.decay_by(self.address, v, 20000, sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
g = c.parse_decay_by(r) g = c.parse_decay_by(r)
self.assertEqual(int(v * growth_factor), g) self.assertEqual(int(g), 990690498)
period = 10 o = c.decay_by(self.address, v, 43200, sender_address=self.accounts[0])
growth_factor = (1 - (self.tax_level) / 1000000) ** period
o = c.decay_by(self.address, v, period, sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
g = c.parse_decay_by(r) g = c.parse_decay_by(r)
self.assertEqual(int(v * growth_factor), g) self.assertEqual(int(g), 980000000)
if __name__ == '__main__': if __name__ == '__main__':