Add mint amounts test

This commit is contained in:
nolash 2021-06-08 11:53:51 +02:00
parent 689baa5f62
commit e894dcd3cf
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 76 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = erc20-demurrage-token name = erc20-demurrage-token
version = 0.0.1b2 version = 0.0.1b3
description = ERC20 token with redistributed continual demurrage description = ERC20 token with redistributed continual demurrage
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -92,6 +92,13 @@ class TestDemurrage(EthTesterCase):
logg.debug('contract address {} start block {} start time {}'.format(self.address, self.start_block, self.start_time)) logg.debug('contract address {} start block {} start time {}'.format(self.address, self.start_block, self.start_time))
def assert_within_lower(self, v, target, tolerance_ppm):
lower_target = target - (target * (tolerance_ppm / 1000000))
self.assertGreaterEqual(v, lower_target)
self.assertLessEqual(v, target)
logg.debug('asserted within lower {} <= {} <= {}'.format(lower_target, v, target))
def tearDown(self): def tearDown(self):
pass pass

View File

@ -0,0 +1,64 @@
# standard imports
import os
import unittest
import json
import logging
# external imports
from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import receipt
# local imports
from erc20_demurrage_token import DemurrageToken
# test imports
from tests.base import TestDemurrageDefault
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
testdir = os.path.dirname(__file__)
class TestAmounts(TestDemurrageDefault):
def test_mints(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], 1000)
r = self.rpc.do(o)
self.backend.time_travel(self.start_time + self.period_seconds)
(tx_hash, o) = c.apply_demurrage(self.address, self.accounts[0])
r = self.rpc.do(o)
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o)
balance = c.parse_balance_of(r)
self.assertEqual(balance, 817)
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 1000)
r = self.rpc.do(o)
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o)
balance = c.parse_balance_of(r)
self.assert_within_lower(balance, 1817, 750)
self.backend.time_travel(self.start_time + self.period_seconds * 2)
(tx_hash, o) = c.apply_demurrage(self.address, self.accounts[0])
r = self.rpc.do(o)
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o)
balance = c.parse_balance_of(r)
expected_balance = ((1 - self.tax_level / 1000000) ** 10) * 1000
expected_balance += ((1 - self.tax_level / 1000000) ** 20) * 1000
self.assert_within_lower(balance, expected_balance, 500)
if __name__ == '__main__':
unittest.main()

View File

@ -102,5 +102,6 @@ class TestPeriod(TestDemurrageDefault):
period = int(period) * (10 ** (38 - 9)) period = int(period) * (10 ** (38 - 9))
self.assertEqual(modifier, period) self.assertEqual(modifier, period)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -206,7 +206,7 @@ contract DemurrageTokenSingleCap {
require(_amount + totalSupply <= supplyCap, 'ERR_CAP'); require(_amount + totalSupply <= supplyCap, 'ERR_CAP');
changePeriod(); changePeriod();
baseAmount = _amount; baseAmount = toBaseAmount(_amount);
totalSupply += _amount; totalSupply += _amount;
increaseBaseBalance(_beneficiary, baseAmount); increaseBaseBalance(_beneficiary, baseAmount);
emit Mint(msg.sender, _beneficiary, _amount); emit Mint(msg.sender, _beneficiary, _amount);
@ -350,6 +350,7 @@ contract DemurrageTokenSingleCap {
uint256 periodTimestamp; uint256 periodTimestamp;
uint256 nextPeriod; uint256 nextPeriod;
applyDemurrage();
currentRedistribution = checkPeriod(); currentRedistribution = checkPeriod();
if (currentRedistribution == bytes32(0x00)) { if (currentRedistribution == bytes32(0x00)) {
return false; return false;
@ -359,7 +360,6 @@ contract DemurrageTokenSingleCap {
nextPeriod = currentPeriod + 1; nextPeriod = currentPeriod + 1;
periodTimestamp = getPeriodTimeDelta(currentPeriod); periodTimestamp = getPeriodTimeDelta(currentPeriod);
applyDemurrage();
currentDemurrageAmount = demurrageAmount; currentDemurrageAmount = demurrageAmount;
demurrageCounts = demurrageCycles(periodTimestamp); demurrageCounts = demurrageCycles(periodTimestamp);