mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-11-15 14:06:45 +01:00
WIP test burn over time
This commit is contained in:
parent
ef294eaec2
commit
a56f1c4869
File diff suppressed because one or more lines are too long
@ -13,6 +13,7 @@ for m in ${modes[@]}; do
|
|||||||
ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_growth.py
|
ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_growth.py
|
||||||
ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_amounts.py
|
ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_amounts.py
|
||||||
ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_single.py
|
ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_single.py
|
||||||
|
ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_burn.py
|
||||||
done
|
done
|
||||||
|
|
||||||
#modes=(SingleCap) # other contracts need to be updted
|
#modes=(SingleCap) # other contracts need to be updted
|
||||||
|
@ -18,16 +18,34 @@ from chainlib.eth.block import (
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
from erc20_demurrage_token.unittest.base import TestDemurrage
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
testdir = os.path.dirname(__file__)
|
testdir = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
|
||||||
class TestBurn(TestDemurrageDefault):
|
class TestBurn(TestDemurrage):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestBurn, self).setUp()
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
|
self.mode = os.environ.get('ERC20_DEMURRAGE_TOKEN_TEST_MODE')
|
||||||
|
if self.mode == None:
|
||||||
|
self.mode = 'MultiNocap'
|
||||||
|
logg.debug('executing test setup default mode {}'.format(self.mode))
|
||||||
|
|
||||||
|
self.deployer.settings.sink_address = self.accounts[9]
|
||||||
|
self.deployer.sink_address = self.accounts[9]
|
||||||
|
self.deploy(c, self.mode)
|
||||||
|
|
||||||
|
logg.info('deployed with mode {}'.format(self.mode))
|
||||||
|
|
||||||
|
|
||||||
def test_burn_basic(self):
|
def test_burn_basic(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)
|
||||||
@ -191,5 +209,88 @@ class TestBurn(TestDemurrageDefault):
|
|||||||
self.assert_within_lower(sink_bal, bal, 0.09) # TODO is this ok variance, 1.0 is ppm?
|
self.assert_within_lower(sink_bal, bal, 0.09) # TODO is this ok variance, 1.0 is ppm?
|
||||||
|
|
||||||
|
|
||||||
|
def test_burn_accumulate(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.add_minter(self.address, self.accounts[0], self.sink_address)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.sink_address, self.default_supply)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.sink_address, self.rpc)
|
||||||
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.transfer(self.address, self.sink_address, self.accounts[1], int(self.default_supply / 2))
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
|
||||||
|
new_supply = None
|
||||||
|
burn_rate = 1000
|
||||||
|
sink_bal = None
|
||||||
|
bob_bal = None
|
||||||
|
bob_refund = None
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
for i in range(1, 101):
|
||||||
|
nonce_oracle = RPCNonceOracle(self.sink_address, self.rpc)
|
||||||
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
|
if bob_refund != None:
|
||||||
|
(tx_hash, o) = c.transfer(self.address, self.sink_address, self.accounts[1], bob_refund)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.burn(self.address, self.sink_address, burn_rate)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
o = c.total_supply(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
new_supply = c.parse_total_supply(r)
|
||||||
|
|
||||||
|
self.backend.time_travel(self.start_time + (self.period_seconds * i))
|
||||||
|
|
||||||
|
(tx_hash, o) = c.change_period(self.address, self.accounts[0])
|
||||||
|
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)
|
||||||
|
|
||||||
|
bob_refund = prev_bob_bal - bob_bal
|
||||||
|
|
||||||
|
o = c.balance(self.address, self.sink_address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
burner_bal = c.parse_balance(r)
|
||||||
|
|
||||||
|
o = c.total_burned(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
total_burned = c.parse_balance(r)
|
||||||
|
|
||||||
|
o = c.to_base_amount(self.address, total_burned, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
total_burned_base = c.parse_balance(r)
|
||||||
|
|
||||||
|
expected_supply = self.default_supply - (burn_rate * i)
|
||||||
|
logg.info('checking burn round {} balance burner {} bob {} supply {} expected {} burned {} base {}'.format(i, burner_bal, bob_bal, new_supply, expected_supply, total_burned, total_burned_base))
|
||||||
|
self.assertEqual(new_supply, expected_supply)
|
||||||
|
|
||||||
|
sum_supply = burner_bal + bob_bal
|
||||||
|
logg.debug('balances sink {} bob {} total {} supply real {} original {}'.format(sink_bal, bob_bal, sum_supply, new_supply, self.default_supply))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -24,7 +24,7 @@ from erc20_demurrage_token import DemurrageToken
|
|||||||
# test imports
|
# test imports
|
||||||
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
testdir = os.path.dirname(__file__)
|
testdir = os.path.dirname(__file__)
|
||||||
@ -88,18 +88,31 @@ class TestRedistribution(TestDemurrageDefault):
|
|||||||
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], supply)
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], supply)
|
||||||
self.rpc.do(o)
|
self.rpc.do(o)
|
||||||
|
|
||||||
self.backend.time_travel(self.start_time + (self.period_seconds * 10))
|
self.backend.time_travel(self.start_time + (self.period_seconds * 100))
|
||||||
|
|
||||||
for i in range(1, 11):
|
balance_minter = None
|
||||||
logg.debug('checking period {}'.format(i))
|
balance_sink = None
|
||||||
|
real_supply = None
|
||||||
|
|
||||||
|
for i in range(1, 101):
|
||||||
(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)
|
||||||
o = receipt(tx_hash)
|
o = receipt(tx_hash)
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
self.assertEqual(r['status'], 1)
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
i = 10
|
o = c.balance_of(self.address, self.sink_address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
balance_sink = c.parse_balance(r)
|
||||||
|
|
||||||
|
o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
balance_minter = c.parse_balance(r)
|
||||||
|
|
||||||
|
real_supply = balance_sink + balance_minter
|
||||||
|
logg.info('period {} testing sink {} mint {} adds up to supply {} of original {} (delta {})'.format(i, balance_sink, balance_minter, real_supply, supply, supply - real_supply))
|
||||||
|
|
||||||
|
i = 100
|
||||||
o = c.redistributions(self.address, i, sender_address=self.accounts[0])
|
o = c.redistributions(self.address, i, sender_address=self.accounts[0])
|
||||||
redistribution = self.rpc.do(o)
|
redistribution = self.rpc.do(o)
|
||||||
|
|
||||||
@ -122,7 +135,7 @@ class TestRedistribution(TestDemurrageDefault):
|
|||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
balance_minter = c.parse_balance(r)
|
balance_minter = c.parse_balance(r)
|
||||||
|
|
||||||
logg.debug('testing sink {} mint {} adds up to supply {} with demurrage between {} and {}'.format(balance_sink, balance_minter, supply, demurrage_previous, demurrage))
|
logg.debug('testing sink {} mint {} adds up to supply {} with demurrage between {} and {}'.format(balance_sink, balance_minter, real_supply, demurrage_previous, demurrage))
|
||||||
|
|
||||||
self.assert_within_lower(balance_minter + balance_sink, supply, 0.001)
|
self.assert_within_lower(balance_minter + balance_sink, supply, 0.001)
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ contract DemurrageTokenSingleCap {
|
|||||||
uint8 constant shiftRedistributionValue = 32;
|
uint8 constant shiftRedistributionValue = 32;
|
||||||
uint256 constant maskRedistributionValue = 0x00000000000000000000000000000000000000ffffffffffffffffff00000000; // ((1 << 72) - 1) << 32
|
uint256 constant maskRedistributionValue = 0x00000000000000000000000000000000000000ffffffffffffffffff00000000; // ((1 << 72) - 1) << 32
|
||||||
uint8 constant shiftRedistributionDemurrage = 104;
|
uint8 constant shiftRedistributionDemurrage = 104;
|
||||||
uint256 constant maskRedistributionDemurrage = 0x0000000000ffffffffffffffffffffffffffff00000000000000000000000000; // ((1 << 20) - 1) << 140
|
uint256 constant maskRedistributionDemurrage = 0x0000000000ffffffffffffffffffffffffffff00000000000000000000000000; // ((1 << 36) - 1) << 140
|
||||||
|
|
||||||
// Account balances
|
// Account balances
|
||||||
mapping (address => uint256) account;
|
mapping (address => uint256) account;
|
||||||
|
Loading…
Reference in New Issue
Block a user