Add test for arbitrary account demurrage honoring burn amount
This commit is contained in:
parent
140dde7bc3
commit
2f4f8bb7b9
@ -124,41 +124,72 @@ class TestBurn(TestDemurrageDefault):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# def test_burned_other_redistribution(self):
|
def test_burned_other_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)
|
||||||
#
|
|
||||||
# (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], 1024)
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], 1000000000)
|
||||||
# r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
#
|
|
||||||
# (tx_hash, o) = c.burn(self.address, self.accounts[0], 500)
|
(tx_hash, o) = c.burn(self.address, self.accounts[0], 500000000)
|
||||||
# r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
#
|
|
||||||
# (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.accounts[1], 524)
|
(tx_hash, o) = c.transfer(self.address, self.accounts[0], self.accounts[1], 500000000)
|
||||||
# r = self.rpc.do(o)
|
r = 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])
|
o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
# r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
# o = receipt(tx_hash)
|
bal = c.parse_balance(r)
|
||||||
# r = self.rpc.do(o)
|
self.assertEqual(bal, 416873881) # 9 periods demurrage
|
||||||
# self.assertEqual(r['status'], 1)
|
|
||||||
#
|
(tx_hash, o) = c.change_period(self.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)
|
o = receipt(tx_hash)
|
||||||
# new_supply = c.parse_total_supply(r)
|
r = self.rpc.do(o)
|
||||||
# self.assertEqual(new_supply, 524)
|
self.assertEqual(r['status'], 1)
|
||||||
#
|
|
||||||
# o = c.balance(self.address, self.accounts[1], 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)
|
||||||
# bal = c.parse_balance(r)
|
new_supply = c.parse_total_supply(r)
|
||||||
# self.assertEqual(bal, 524)
|
self.assertEqual(new_supply, 500000000)
|
||||||
#
|
|
||||||
# o = c.balance(self.address, self.sink_address, sender_address=self.accounts[0])
|
o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
# r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
# bal = c.parse_balance(r)
|
bal = c.parse_balance(r)
|
||||||
# self.assertEqual(bal, 524)
|
self.assertEqual(bal, 408536403) # 9 periods demurrage
|
||||||
|
|
||||||
|
o = c.balance(self.address, self.sink_address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
sink_bal = c.parse_balance(r)
|
||||||
|
self.assert_within_lower(sink_bal, 500000000 - 408536403, 0.09) # TODO is this ok variance, 1.0 is ppm?
|
||||||
|
|
||||||
|
self.backend.time_travel(self.start_time + (self.period_seconds * 2))
|
||||||
|
|
||||||
|
(tx_hash, o) = c.change_period(self.address, self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.total_supply(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
new_supply = c.parse_total_supply(r)
|
||||||
|
self.assertEqual(new_supply, 500000000)
|
||||||
|
|
||||||
|
o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
next_bal = c.parse_balance(r)
|
||||||
|
self.assertEqual(next_bal, 333803985) # 9 periods demurrage
|
||||||
|
|
||||||
|
o = c.balance(self.address, self.sink_address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
prev_sink_bal = sink_bal
|
||||||
|
bal = prev_sink_bal + (bal - next_bal)
|
||||||
|
sink_bal = c.parse_balance(r)
|
||||||
|
self.assert_within_lower(sink_bal, bal, 0.09) # TODO is this ok variance, 1.0 is ppm?
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user