mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-11-26 01:26:45 +01:00
115 lines
4.0 KiB
Python
115 lines
4.0 KiB
Python
# standard imports
|
|
import datetime
|
|
import unittest
|
|
import logging
|
|
import os
|
|
|
|
# external imports
|
|
from chainlib.eth.nonce import RPCNonceOracle
|
|
from chainlib.eth.tx import receipt
|
|
|
|
# local imports
|
|
from erc20_demurrage_token import DemurrageToken
|
|
from erc20_demurrage_token.demurrage import DemurrageCalculator
|
|
|
|
# test imports
|
|
from erc20_demurrage_token.unittest import TestDemurrageDefault
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
logg = logging.getLogger()
|
|
|
|
|
|
class TestDemurragePeriods(TestDemurrageDefault):
|
|
|
|
# verify that tax level calculation is in ppm as expected
|
|
def test_ppm(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], self.default_supply)
|
|
r = self.rpc.do(o)
|
|
|
|
self.backend.time_travel(self.start_time + 60)
|
|
|
|
(tx_hash, o) = c.apply_demurrage(self.address, self.accounts[0])
|
|
self.rpc.do(o)
|
|
o = receipt(tx_hash)
|
|
r = self.rpc.do(o)
|
|
self.assertEqual(r['status'], 1)
|
|
|
|
o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
|
|
r = self.rpc.do(o)
|
|
bob_bal = c.parse_balance(r)
|
|
|
|
o = c.balance(self.address, self.sink_address, sender_address=self.accounts[0])
|
|
r = self.rpc.do(o)
|
|
sink_bal = c.parse_balance(r)
|
|
|
|
o = c.total_supply(self.address, sender_address=self.accounts[0])
|
|
r = self.rpc.do(o)
|
|
new_supply = c.parse_total_supply(r)
|
|
|
|
balance_delta = self.default_supply * ((2 / 1000000) / 1000)
|
|
self.assertEqual(bob_bal, self.default_supply - balance_delta)
|
|
|
|
|
|
|
|
# verify balances and supply after multiple demurrage periods
|
|
def test_over_time(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], self.default_supply)
|
|
r = self.rpc.do(o)
|
|
|
|
o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
|
|
r = self.rpc.do(o)
|
|
bob_bal = c.parse_balance(r)
|
|
prev_bob_bal = bob_bal
|
|
|
|
nonce_oracle = RPCNonceOracle(self.sink_address, self.rpc)
|
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
|
|
|
iterations = 100
|
|
|
|
for i in range(1, iterations + 1):
|
|
self.backend.time_travel(self.start_time + (self.period_seconds * i))
|
|
|
|
(tx_hash, o) = c.transfer(self.address, self.sink_address, self.accounts[1], prev_bob_bal - bob_bal)
|
|
r = self.rpc.do(o)
|
|
o = receipt(tx_hash)
|
|
r = self.rpc.do(o)
|
|
self.assertEqual(r['status'], 1)
|
|
|
|
(tx_hash, o) = c.apply_demurrage(self.address, self.sink_address)
|
|
self.rpc.do(o)
|
|
o = receipt(tx_hash)
|
|
r = self.rpc.do(o)
|
|
self.assertEqual(r['status'], 1)
|
|
|
|
o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
|
|
r = self.rpc.do(o)
|
|
bob_bal = c.parse_balance(r)
|
|
|
|
o = c.balance(self.address, self.sink_address, sender_address=self.accounts[0])
|
|
r = self.rpc.do(o)
|
|
sink_bal = c.parse_balance(r)
|
|
|
|
o = c.total_supply(self.address, sender_address=self.accounts[0])
|
|
r = self.rpc.do(o)
|
|
new_supply = c.parse_total_supply(r)
|
|
|
|
logg.info('round {} supply {} balance sink {} bob {}'.format(i, new_supply, sink_bal, bob_bal))
|
|
|
|
sum_supply = sink_bal + bob_bal
|
|
|
|
bob_delta = self.default_supply * ((2 / 1000000) / 100)
|
|
|
|
self.assert_within_lower(sum_supply, new_supply, 0.00001)
|
|
self.assert_within_greater(bob_bal, self.default_supply - bob_delta, 0.001)
|
|
self.assert_within_lower(sink_bal, bob_delta, 1000)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|