mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-11-05 02:06:45 +01:00
Rehabilitate test growth and amounts
This commit is contained in:
parent
e74a9cb594
commit
3333d50f98
@ -13,7 +13,7 @@ from chainlib.eth.tx import receipt
|
||||
from erc20_demurrage_token import DemurrageToken
|
||||
|
||||
# test imports
|
||||
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
||||
from erc20_demurrage_token.unittest import TestDemurrageDefault
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@ -36,7 +36,7 @@ class TestAmounts(TestDemurrageDefault):
|
||||
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
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)
|
||||
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])
|
||||
r = self.rpc.do(o)
|
||||
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)
|
||||
|
||||
@ -57,8 +57,8 @@ class TestAmounts(TestDemurrageDefault):
|
||||
|
||||
expected_balance = ((1 - self.tax_level / 1000000) ** 10) * 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):
|
||||
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])
|
||||
r = self.rpc.do(o)
|
||||
balance = c.parse_balance(r)
|
||||
self.assertEqual(balance, 1634)
|
||||
self.assertEqual(balance, 1960)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
|
||||
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])
|
||||
r = self.rpc.do(o)
|
||||
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])
|
||||
r = self.rpc.do(o)
|
||||
@ -99,24 +99,24 @@ class TestAmounts(TestDemurrageDefault):
|
||||
r = self.rpc.do(o)
|
||||
|
||||
cases = [
|
||||
(61, 1960),
|
||||
(121, 1920),
|
||||
(181, 1882),
|
||||
(241, 1844),
|
||||
(301, 1807),
|
||||
(361, 1771),
|
||||
(421, 1736),
|
||||
(481, 1701),
|
||||
(541, 1667),
|
||||
(601, 1634),
|
||||
(60, 1960),
|
||||
(120, 1920),
|
||||
(180, 1882),
|
||||
(240, 1844),
|
||||
(300, 1807),
|
||||
(360, 1771),
|
||||
(420, 1736),
|
||||
(480, 1701),
|
||||
(540, 1667),
|
||||
(600, 1634),
|
||||
]
|
||||
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])
|
||||
r = self.rpc.do(o)
|
||||
balance = c.parse_balance(r)
|
||||
self.assertEqual(balance, case[1])
|
||||
self.assert_within_lower(balance, case[1], 10000)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -18,7 +18,7 @@ from chainlib.eth.block import (
|
||||
from erc20_demurrage_token import DemurrageToken
|
||||
|
||||
# test imports
|
||||
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
||||
from erc20_demurrage_token.unittest import TestDemurrageDefault
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@ -28,42 +28,20 @@ testdir = os.path.dirname(__file__)
|
||||
|
||||
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):
|
||||
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.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)
|
||||
g = c.parse_decay_by(r)
|
||||
self.assertEqual(int(v * growth_factor), g)
|
||||
|
||||
period = 10
|
||||
growth_factor = (1 - (self.tax_level) / 1000000) ** period
|
||||
o = c.decay_by(self.address, v, period, sender_address=self.accounts[0])
|
||||
self.assertEqual(int(g), 990690498)
|
||||
|
||||
o = c.decay_by(self.address, v, 43200, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
g = c.parse_decay_by(r)
|
||||
self.assertEqual(int(v * growth_factor), g)
|
||||
self.assertEqual(int(g), 980000000)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user