mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-11-05 10:06:45 +01:00
Use next redistribution object hack in apply default distribution
This commit is contained in:
parent
0b6d58f7af
commit
a2a141dbf4
File diff suppressed because one or more lines are too long
@ -19,10 +19,8 @@ from erc20_demurrage_token import (
|
||||
DemurrageToken,
|
||||
)
|
||||
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
#BLOCKTIME = 5 # seconds
|
||||
TAX_LEVEL = int(10000 * 2) # 2%
|
||||
# calc "1-(0.98)^(1/518400)" <- 518400 = 30 days of blocks
|
||||
|
@ -31,39 +31,39 @@ 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)
|
||||
|
||||
|
||||
|
||||
# # 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)
|
||||
@ -137,6 +137,10 @@ class TestRedistribution(TestDemurrageUnit):
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
# check that we have crossed into new period, this will throw if not
|
||||
o = c.redistributions(self.address, 1, sender_address=self.accounts[0])
|
||||
self.rpc.do(o)
|
||||
|
||||
demurrage_amount = int((self.tax_level / 1000000) * mint_amount)
|
||||
|
||||
expected_balance = mint_amount - demurrage_amount
|
||||
@ -181,8 +185,7 @@ class TestRedistribution(TestDemurrageUnit):
|
||||
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)
|
||||
self.assertGreaterEqual(balance, expected_balance - expected_balance_tolerance)
|
||||
self.assertLessEqual(balance, expected_balance)
|
||||
self.assert_within_lower(balance, expected_balance, 1000)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -14,6 +14,10 @@ contract DemurrageTokenSingleCap {
|
||||
uint8 constant shiftRedistributionDemurrage = 104;
|
||||
uint256 constant maskRedistributionDemurrage = 0x000000ffffffffffffffffffffffffffffffff00000000000000000000000000; // ((1 << 20) - 1) << 140
|
||||
|
||||
uint8 constant shiftRedistributionIsUsed = 255;
|
||||
uint256 constant maskRedistributionIsUsed = 0x4000000000000000000000000000000000000000000000000000000000000000; // 1 << 255
|
||||
|
||||
|
||||
// Account balances
|
||||
mapping (address => uint256) account;
|
||||
|
||||
@ -372,7 +376,7 @@ contract DemurrageTokenSingleCap {
|
||||
nextRedistribution = toRedistribution(0, nextRedistributionDemurrage, totalSupply, nextPeriod);
|
||||
redistributions.push(nextRedistribution);
|
||||
|
||||
applyDefaultRedistribution(currentRedistribution);
|
||||
applyDefaultRedistribution(nextRedistribution);
|
||||
emit Period(nextPeriod);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user