erc20-demurrage-token/python/tests/test_demurrage_ext.py

42 lines
1.4 KiB
Python
Raw Permalink Normal View History

2021-07-02 15:29:56 +02:00
# standard imports
import datetime
import unittest
2021-07-04 12:10:01 +02:00
# external imports
from chainlib.eth.nonce import RPCNonceOracle
2021-07-02 15:29:56 +02:00
# local imports
2021-07-04 12:10:01 +02:00
from erc20_demurrage_token import DemurrageToken
2021-07-02 15:29:56 +02:00
from erc20_demurrage_token.demurrage import DemurrageCalculator
# test imports
from erc20_demurrage_token.unittest.base import TestDemurrage
2021-07-02 15:29:56 +02:00
class TestEmulate(TestDemurrage):
def test_amount_since(self):
d = datetime.datetime.utcnow() - datetime.timedelta(seconds=29, hours=5, minutes=3, days=4)
c = DemurrageCalculator(0.00000050105908373373)
a = c.amount_since(100, d.timestamp())
self.assert_within_lower(a, 99.69667, 0.1)
2021-07-04 14:52:12 +02:00
def test_amount_since_slow(self):
d = datetime.datetime.utcnow() - datetime.timedelta(seconds=29, hours=5, minutes=3, days=4)
c = DemurrageCalculator(0.00000050105908373373)
a = c.amount_since_slow(100, d.timestamp())
self.assert_within_lower(a, 99.69667, 0.1)
2021-07-04 12:10:01 +02:00
def test_from_contract(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
self.deploy(c, 'SingleNocap')
dc = DemurrageCalculator.from_contract(self.rpc, self.chain_spec, self.address, sender_address=self.accounts[0])
self.assertEqual(dc.r_min, 0.02)
2021-07-02 15:29:56 +02:00
if __name__ == '__main__':
unittest.main()