mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-12-22 11:57:32 +01:00
Add limited demurrage apply test
This commit is contained in:
parent
6dc843fb5d
commit
276b346e52
@ -325,8 +325,19 @@ class DemurrageToken(ERC20):
|
|||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
def apply_demurrage(self, contract_address, sender_address):
|
def apply_demurrage(self, contract_address, sender_address, limit=0, tx_format=TxFormat.JSONRPC):
|
||||||
return self.transact_noarg('applyDemurrage', contract_address, sender_address)
|
if limit == 0:
|
||||||
|
return self.transact_noarg('applyDemurrage', contract_address, sender_address)
|
||||||
|
|
||||||
|
enc = ABIContractEncoder()
|
||||||
|
enc.method('applyDemurrageLimited')
|
||||||
|
enc.typ(ABIContractType.UINT256)
|
||||||
|
enc.uint256(limit)
|
||||||
|
data = enc.get()
|
||||||
|
tx = self.template(sender_address, contract_address, use_nonce=True)
|
||||||
|
tx = self.set_code(tx, data)
|
||||||
|
tx = self.finalize(tx, tx_format)
|
||||||
|
return tx
|
||||||
|
|
||||||
|
|
||||||
def change_period(self, contract_address, sender_address):
|
def change_period(self, contract_address, sender_address):
|
||||||
|
@ -54,6 +54,33 @@ class TestBasic(TestDemurrageDefault):
|
|||||||
self.assertEqual(balance, 1024)
|
self.assertEqual(balance, 1024)
|
||||||
|
|
||||||
|
|
||||||
|
def test_apply_demurrage_limited(self):
|
||||||
|
modifier = (10 ** 28)
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
|
o = c.demurrage_amount(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
demurrage_amount = c.parse_demurrage_amount(r)
|
||||||
|
self.assertEqual(modifier, demurrage_amount)
|
||||||
|
|
||||||
|
self.backend.time_travel(self.start_time + 120)
|
||||||
|
(tx_hash, o) = c.apply_demurrage(self.address, sender_address=self.accounts[0], limit=1)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.demurrage_amount(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
demurrage_amount = c.parse_demurrage_amount(r)
|
||||||
|
modifier_base = 1000000 - self.tax_level
|
||||||
|
modifier = int(modifier_base * (10 ** 22)) # 38 decimal places minus 6 (1000000)
|
||||||
|
self.assertEqual(modifier, demurrage_amount)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_apply_demurrage(self):
|
def test_apply_demurrage(self):
|
||||||
modifier = (10 ** 28)
|
modifier = (10 ** 28)
|
||||||
|
|
||||||
@ -93,7 +120,6 @@ class TestBasic(TestDemurrageDefault):
|
|||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
demurrage_amount = c.parse_demurrage_amount(r)
|
demurrage_amount = c.parse_demurrage_amount(r)
|
||||||
modifier_base = 1000000 - self.tax_level
|
modifier_base = 1000000 - self.tax_level
|
||||||
logg.debug('modifier base {}'.format(modifier_base))
|
|
||||||
modifier = int(modifier_base * (10 ** 22)) # 38 decimal places minus 6 (1000000)
|
modifier = int(modifier_base * (10 ** 22)) # 38 decimal places minus 6 (1000000)
|
||||||
self.assertEqual(modifier, demurrage_amount)
|
self.assertEqual(modifier, demurrage_amount)
|
||||||
|
|
||||||
@ -111,7 +137,7 @@ class TestBasic(TestDemurrageDefault):
|
|||||||
modifier = int(modifier_base * (10 ** 12))
|
modifier = int(modifier_base * (10 ** 12))
|
||||||
|
|
||||||
rounding_tolerance_nano = 4000000 # 0.000004% precision
|
rounding_tolerance_nano = 4000000 # 0.000004% precision
|
||||||
demurrage_amount_truncate = int(demurrage_amount / (10 ** 16)) # equals 38 decimal places - 14 for the modifier magniture - 2 for percent int calc + 6 for token decimals (originally equalled 12 decimal places)
|
demurrage_amount_truncate = int(demurrage_amount / (10 ** 16)) # equals 38 decimal places - 14 for the modifier magniture - 2 for percent int calc + 6 for token decimals <- TODO verify this calc
|
||||||
self.assertGreaterEqual(modifier, demurrage_amount_truncate - rounding_tolerance_nano)
|
self.assertGreaterEqual(modifier, demurrage_amount_truncate - rounding_tolerance_nano)
|
||||||
self.assertLessEqual(modifier, demurrage_amount_truncate)
|
self.assertLessEqual(modifier, demurrage_amount_truncate)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user