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

67 lines
2.0 KiB
Python
Raw Permalink Normal View History

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
from chainlib.eth.block import block_latest
from chainlib.eth.address import to_checksum_address
from hexathon import (
strip_0x,
add_0x,
)
# local imports
from erc20_demurrage_token import DemurrageToken
# test imports
2023-02-10 16:58:31 +01:00
from erc20_demurrage_token.unittest import TestDemurrageDefault
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
testdir = os.path.dirname(__file__)
2023-02-10 16:58:31 +01:00
class TestCap(TestDemurrageDefault):
2023-02-10 16:58:31 +01:00
def test_cap(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
2023-02-10 16:58:31 +01:00
o = c.total_supply(self.address, sender_address=self.accounts[0])
r = self.rpc.do(o)
logg.debug('r {}'.format(r))
(tx_hash, o) = c.set_max_supply(self.address, self.accounts[0], self.default_supply_cap)
r = self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
o = c.max_supply(self.address, sender_address=self.accounts[0])
r = self.rpc.do(o)
cap = c.parse_supply_cap(r)
self.assertEqual(cap, self.default_supply_cap)
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], self.default_supply_cap)
r = 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.accounts[2], 1)
r = self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
self.assertEqual(r['status'], 0)
if __name__ == '__main__':
unittest.main()