commit 606b8d62389613bac026ed6ecf7161ea53340034
parent 34d90b32910afe5e287231947dbffd4fd1979115
Author: nolash <dev@holbrook.no>
Date: Tue, 8 Jun 2021 14:58:58 +0200
Add transfers test, rehabilitate single test
Diffstat:
3 files changed, 127 insertions(+), 86 deletions(-)
diff --git a/python/tests/test_amounts.py b/python/tests/test_amounts.py
@@ -68,6 +68,14 @@ class TestAmounts(TestDemurrageDefault):
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)
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)
@@ -76,7 +84,39 @@ 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_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__':
diff --git a/python/tests/test_redistribution_unit.py b/python/tests/test_redistribution_unit.py
@@ -31,86 +31,86 @@ testdir = os.path.dirname(__file__)
class TestRedistribution(TestDemurrageUnit):
-# # TODO: move to "pure" test file when getdistribution is implemented in all contracts
-# def test_distribution(self):
-# nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
-# c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
-#
-# demurrage = (1 - (self.tax_level / 1000000)) * (10**38)
-# supply = self.default_supply
-#
-# o = c.get_distribution(self.address, supply, demurrage, sender_address=self.accounts[0])
-# r = self.rpc.do(o)
-# distribution = c.parse_get_distribution(r)
-# expected_distribution = self.default_supply * (self.tax_level / 1000000)
-# self.assertEqual(distribution, expected_distribution)
-#
-#
-# def test_distribution_from_redistribution(self):
-# nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
-# c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
-#
-# demurrage = (1 - (self.tax_level / 1000000)) * (10**38)
-# supply = self.default_supply
-#
-# o = c.to_redistribution(self.address, 0, demurrage, supply, 1, sender_address=self.accounts[0])
-# redistribution = self.rpc.do(o)
-#
-# o = c.get_distribution_from_redistribution(self.address, redistribution, self.accounts[0])
-# r = self.rpc.do(o)
-# distribution = c.parse_get_distribution(r)
-# expected_distribution = self.default_supply * (self.tax_level / 1000000)
-# self.assertEqual(distribution, expected_distribution)
-#
-#
-#
-# def test_single_step(self):
-# nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
-# c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
-#
-# mint_amount = 100000000
-#
-# (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], mint_amount)
-# self.rpc.do(o)
-#
-# self.backend.time_travel(self.start_time + self.period_seconds)
-#
-# (tx_hash, o) = c.change_period(self.address, self.accounts[0])
-# self.rpc.do(o)
-#
-# 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])
-# r = self.rpc.do(o)
-# balance = c.parse_balance_of(r)
-#
-# self.assertEqual(balance, expected_balance)
-#
-#
-# def test_single_step_multi(self):
-# nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
-# c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
-#
-# mint_amount = 100000000
-#
-# for i in range(3):
-# (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[i+1], mint_amount)
-# self.rpc.do(o)
-#
-# self.backend.time_travel(self.start_time + self.period_seconds)
-#
-# (tx_hash, o) = c.change_period(self.address, self.accounts[0])
-# self.rpc.do(o)
-#
-# expected_balance = int(mint_amount - ((self.tax_level / 1000000) * mint_amount))
-#
-# for i in range(3):
-# o = c.balance_of(self.address, self.accounts[i+1], sender_address=self.accounts[0])
-# r = self.rpc.do(o)
-# balance = c.parse_balance_of(r)
-# self.assertEqual(balance, expected_balance)
-#
-#
+ # TODO: move to "pure" test file when getdistribution is implemented in all contracts
+ def test_distribution(self):
+ nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
+ c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+
+ demurrage = (1 - (self.tax_level / 1000000)) * (10**38)
+ supply = self.default_supply
+
+ o = c.get_distribution(self.address, supply, demurrage, sender_address=self.accounts[0])
+ r = self.rpc.do(o)
+ distribution = c.parse_get_distribution(r)
+ expected_distribution = self.default_supply * (self.tax_level / 1000000)
+ self.assertEqual(distribution, expected_distribution)
+
+
+ def test_distribution_from_redistribution(self):
+ nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
+ c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+
+ demurrage = (1 - (self.tax_level / 1000000)) * (10**38)
+ supply = self.default_supply
+
+ o = c.to_redistribution(self.address, 0, demurrage, supply, 1, sender_address=self.accounts[0])
+ redistribution = self.rpc.do(o)
+
+ o = c.get_distribution_from_redistribution(self.address, redistribution, self.accounts[0])
+ r = self.rpc.do(o)
+ distribution = c.parse_get_distribution(r)
+ expected_distribution = self.default_supply * (self.tax_level / 1000000)
+ self.assertEqual(distribution, expected_distribution)
+
+
+
+ def test_single_step(self):
+ nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
+ c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+
+ mint_amount = 100000000
+
+ (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], mint_amount)
+ self.rpc.do(o)
+
+ self.backend.time_travel(self.start_time + self.period_seconds)
+
+ (tx_hash, o) = c.change_period(self.address, self.accounts[0])
+ self.rpc.do(o)
+
+ 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])
+ r = self.rpc.do(o)
+ balance = c.parse_balance_of(r)
+
+ self.assertEqual(balance, expected_balance)
+
+
+ def test_single_step_multi(self):
+ nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
+ c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+
+ mint_amount = 100000000
+
+ for i in range(3):
+ (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[i+1], mint_amount)
+ self.rpc.do(o)
+
+ self.backend.time_travel(self.start_time + self.period_seconds)
+
+ (tx_hash, o) = c.change_period(self.address, self.accounts[0])
+ self.rpc.do(o)
+
+ expected_balance = int(mint_amount - ((self.tax_level / 1000000) * mint_amount))
+
+ for i in range(3):
+ o = c.balance_of(self.address, self.accounts[i+1], sender_address=self.accounts[0])
+ r = self.rpc.do(o)
+ balance = c.parse_balance_of(r)
+ self.assertEqual(balance, expected_balance)
+
+
def test_single_step_transfer(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
diff --git a/python/tests/test_single.py b/python/tests/test_single.py
@@ -64,22 +64,23 @@ class TestRedistributionSingle(TestDemurrageSingle):
r = self.rpc.do(o)
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])
r = self.rpc.do(o)
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])
r = self.rpc.do(o)
balance = c.parse_balance_of(r)
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])
r = self.rpc.do(o)
balance = c.parse_balance_of(r)
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])
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])
r = self.rpc.do(o)
balance = c.parse_balance_of(r)
- base_amount = new_supply * (self.tax_level / 1000000)
- self.assertEqual(balance, base_amount - (base_amount * (self.tax_level / 1000000)))
+ expected_balance = new_supply - (new_supply * tax_modifier)
+ self.assert_within_lower(balance, expected_balance, 1)
if __name__ == '__main__':