mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-11-22 08:16:47 +01:00
Add transfers test, rehabilitate single test
This commit is contained in:
parent
34d90b3291
commit
606b8d6238
@ -68,6 +68,14 @@ class TestAmounts(TestDemurrageDefault):
|
|||||||
|
|
||||||
self.backend.time_travel(self.start_time + self.period_seconds)
|
self.backend.time_travel(self.start_time + self.period_seconds)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.apply_demurrage(self.address, self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
|
||||||
|
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
balance = c.parse_balance_of(r)
|
||||||
|
self.assertEqual(balance, 1634)
|
||||||
|
|
||||||
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)
|
||||||
(tx_hash, o) = c.transfer(self.address, self.accounts[1], self.accounts[2], 500)
|
(tx_hash, o) = c.transfer(self.address, self.accounts[1], self.accounts[2], 500)
|
||||||
@ -76,7 +84,39 @@ 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_of(r)
|
balance = c.parse_balance_of(r)
|
||||||
self.assertEqual(balance, 817)
|
self.assertEqual(balance, 1134)
|
||||||
|
|
||||||
|
o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
balance = c.parse_balance_of(r)
|
||||||
|
self.assert_within_lower(balance, 500, 2000)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dynamic_amount(self):
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 2000)
|
||||||
|
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),
|
||||||
|
]
|
||||||
|
for case in cases:
|
||||||
|
self.backend.time_travel(self.start_time + case[0])
|
||||||
|
|
||||||
|
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
balance = c.parse_balance_of(r)
|
||||||
|
self.assertEqual(balance, case[1])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -31,86 +31,86 @@ testdir = os.path.dirname(__file__)
|
|||||||
|
|
||||||
class TestRedistribution(TestDemurrageUnit):
|
class TestRedistribution(TestDemurrageUnit):
|
||||||
|
|
||||||
# # TODO: move to "pure" test file when getdistribution is implemented in all contracts
|
# TODO: move to "pure" test file when getdistribution is implemented in all contracts
|
||||||
# def test_distribution(self):
|
def test_distribution(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)
|
||||||
#
|
|
||||||
# demurrage = (1 - (self.tax_level / 1000000)) * (10**38)
|
demurrage = (1 - (self.tax_level / 1000000)) * (10**38)
|
||||||
# supply = self.default_supply
|
supply = self.default_supply
|
||||||
#
|
|
||||||
# o = c.get_distribution(self.address, supply, demurrage, sender_address=self.accounts[0])
|
o = c.get_distribution(self.address, supply, demurrage, sender_address=self.accounts[0])
|
||||||
# r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
# distribution = c.parse_get_distribution(r)
|
distribution = c.parse_get_distribution(r)
|
||||||
# expected_distribution = self.default_supply * (self.tax_level / 1000000)
|
expected_distribution = self.default_supply * (self.tax_level / 1000000)
|
||||||
# self.assertEqual(distribution, expected_distribution)
|
self.assertEqual(distribution, expected_distribution)
|
||||||
#
|
|
||||||
#
|
|
||||||
# def test_distribution_from_redistribution(self):
|
def test_distribution_from_redistribution(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)
|
||||||
#
|
|
||||||
# demurrage = (1 - (self.tax_level / 1000000)) * (10**38)
|
demurrage = (1 - (self.tax_level / 1000000)) * (10**38)
|
||||||
# supply = self.default_supply
|
supply = self.default_supply
|
||||||
#
|
|
||||||
# o = c.to_redistribution(self.address, 0, demurrage, supply, 1, sender_address=self.accounts[0])
|
o = c.to_redistribution(self.address, 0, demurrage, supply, 1, sender_address=self.accounts[0])
|
||||||
# redistribution = self.rpc.do(o)
|
redistribution = self.rpc.do(o)
|
||||||
#
|
|
||||||
# o = c.get_distribution_from_redistribution(self.address, redistribution, self.accounts[0])
|
o = c.get_distribution_from_redistribution(self.address, redistribution, self.accounts[0])
|
||||||
# r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
# distribution = c.parse_get_distribution(r)
|
distribution = c.parse_get_distribution(r)
|
||||||
# expected_distribution = self.default_supply * (self.tax_level / 1000000)
|
expected_distribution = self.default_supply * (self.tax_level / 1000000)
|
||||||
# self.assertEqual(distribution, expected_distribution)
|
self.assertEqual(distribution, expected_distribution)
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# def test_single_step(self):
|
def test_single_step(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)
|
||||||
#
|
|
||||||
# mint_amount = 100000000
|
mint_amount = 100000000
|
||||||
#
|
|
||||||
# (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], mint_amount)
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], mint_amount)
|
||||||
# self.rpc.do(o)
|
self.rpc.do(o)
|
||||||
#
|
|
||||||
# self.backend.time_travel(self.start_time + self.period_seconds)
|
self.backend.time_travel(self.start_time + self.period_seconds)
|
||||||
#
|
|
||||||
# (tx_hash, o) = c.change_period(self.address, self.accounts[0])
|
(tx_hash, o) = c.change_period(self.address, self.accounts[0])
|
||||||
# self.rpc.do(o)
|
self.rpc.do(o)
|
||||||
#
|
|
||||||
# expected_balance = int(mint_amount - ((self.tax_level / 1000000) * mint_amount))
|
expected_balance = int(mint_amount - ((self.tax_level / 1000000) * mint_amount))
|
||||||
#
|
|
||||||
# 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_of(r)
|
balance = c.parse_balance_of(r)
|
||||||
#
|
|
||||||
# self.assertEqual(balance, expected_balance)
|
self.assertEqual(balance, expected_balance)
|
||||||
#
|
|
||||||
#
|
|
||||||
# def test_single_step_multi(self):
|
def test_single_step_multi(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)
|
||||||
#
|
|
||||||
# mint_amount = 100000000
|
mint_amount = 100000000
|
||||||
#
|
|
||||||
# for i in range(3):
|
for i in range(3):
|
||||||
# (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[i+1], mint_amount)
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[i+1], mint_amount)
|
||||||
# self.rpc.do(o)
|
self.rpc.do(o)
|
||||||
#
|
|
||||||
# self.backend.time_travel(self.start_time + self.period_seconds)
|
self.backend.time_travel(self.start_time + self.period_seconds)
|
||||||
#
|
|
||||||
# (tx_hash, o) = c.change_period(self.address, self.accounts[0])
|
(tx_hash, o) = c.change_period(self.address, self.accounts[0])
|
||||||
# self.rpc.do(o)
|
self.rpc.do(o)
|
||||||
#
|
|
||||||
# expected_balance = int(mint_amount - ((self.tax_level / 1000000) * mint_amount))
|
expected_balance = int(mint_amount - ((self.tax_level / 1000000) * mint_amount))
|
||||||
#
|
|
||||||
# for i in range(3):
|
for i in range(3):
|
||||||
# o = c.balance_of(self.address, self.accounts[i+1], sender_address=self.accounts[0])
|
o = c.balance_of(self.address, self.accounts[i+1], sender_address=self.accounts[0])
|
||||||
# r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
# balance = c.parse_balance_of(r)
|
balance = c.parse_balance_of(r)
|
||||||
# self.assertEqual(balance, expected_balance)
|
self.assertEqual(balance, expected_balance)
|
||||||
#
|
|
||||||
#
|
|
||||||
def test_single_step_transfer(self):
|
def test_single_step_transfer(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)
|
||||||
|
@ -64,22 +64,23 @@ class TestRedistributionSingle(TestDemurrageSingle):
|
|||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
self.assertEqual(r['status'], 1)
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
tax_modifier = (1 - (self.tax_level / 1000000)) ** 10
|
||||||
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_of(r)
|
balance = c.parse_balance_of(r)
|
||||||
self.assertEqual(balance, mint_amount - (mint_amount * (self.tax_level / 1000000)))
|
self.assertEqual(balance, int(mint_amount * tax_modifier))
|
||||||
|
|
||||||
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)
|
||||||
balance = c.parse_balance_of(r)
|
balance = c.parse_balance_of(r)
|
||||||
base_amount = mint_amount - int(mint_amount * 0.1)
|
base_amount = mint_amount - int(mint_amount * 0.1)
|
||||||
self.assertEqual(balance, (base_amount - (base_amount * (self.tax_level / 1000000))))
|
self.assertEqual(balance, int(base_amount * tax_modifier)) #(base_amount - (base_amount * (self.tax_level / 1000000))))
|
||||||
|
|
||||||
o = c.balance_of(self.address, self.accounts[3], sender_address=self.accounts[0])
|
o = c.balance_of(self.address, self.accounts[3], sender_address=self.accounts[0])
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
balance = c.parse_balance_of(r)
|
balance = c.parse_balance_of(r)
|
||||||
base_amount = mint_amount - int(mint_amount * 0.2)
|
base_amount = mint_amount - int(mint_amount * 0.2)
|
||||||
self.assertEqual(balance, (base_amount - (base_amount * (self.tax_level / 1000000))))
|
self.assertEqual(balance, int(base_amount * tax_modifier)) #(base_amount - (base_amount * (self.tax_level / 1000000))))
|
||||||
|
|
||||||
o = c.total_supply(self.address, sender_address=self.accounts[0])
|
o = c.total_supply(self.address, sender_address=self.accounts[0])
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
@ -88,8 +89,8 @@ class TestRedistributionSingle(TestDemurrageSingle):
|
|||||||
o = c.balance_of(self.address, self.sink_address, sender_address=self.accounts[0])
|
o = c.balance_of(self.address, self.sink_address, sender_address=self.accounts[0])
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
balance = c.parse_balance_of(r)
|
balance = c.parse_balance_of(r)
|
||||||
base_amount = new_supply * (self.tax_level / 1000000)
|
expected_balance = new_supply - (new_supply * tax_modifier)
|
||||||
self.assertEqual(balance, base_amount - (base_amount * (self.tax_level / 1000000)))
|
self.assert_within_lower(balance, expected_balance, 1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user