mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-11-26 01:26:45 +01:00
Refactor mint, minter tests
This commit is contained in:
parent
9f27f9e26a
commit
d1a0a7e882
@ -94,6 +94,18 @@ class DemurrageToken(ERC20):
|
|||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
|
||||||
|
def remove_minter(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
|
enc = ABIContractEncoder()
|
||||||
|
enc.method('removeMinter')
|
||||||
|
enc.typ(ABIContractType.ADDRESS)
|
||||||
|
enc.address(address)
|
||||||
|
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 mint_to(self, contract_address, sender_address, address, value, tx_format=TxFormat.JSONRPC):
|
def mint_to(self, contract_address, sender_address, address, value, tx_format=TxFormat.JSONRPC):
|
||||||
enc = ABIContractEncoder()
|
enc = ABIContractEncoder()
|
||||||
enc.method('mintTo')
|
enc.method('mintTo')
|
||||||
|
@ -8,7 +8,8 @@ import datetime
|
|||||||
# external imports
|
# external imports
|
||||||
from chainlib.eth.constant import ZERO_ADDRESS
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
from chainlib.eth.nonce import RPCNonceOracle
|
from chainlib.eth.nonce import RPCNonceOracle
|
||||||
|
from chainlib.eth.tx import receipt
|
||||||
|
import eth_tester
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
@ -37,6 +38,7 @@ class TestBasic(TestDemurrageDefault):
|
|||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skip('foo')
|
||||||
def test_apply_demurrage(self):
|
def test_apply_demurrage(self):
|
||||||
modifier = 10 * (10 ** 37)
|
modifier = 10 * (10 ** 37)
|
||||||
|
|
||||||
@ -64,45 +66,94 @@ class TestBasic(TestDemurrageDefault):
|
|||||||
self.assertEqual(modifier, demurrage_amount)
|
self.assertEqual(modifier, demurrage_amount)
|
||||||
|
|
||||||
|
|
||||||
# def test_mint(self):
|
@unittest.skip('foo')
|
||||||
# tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1024).transact()
|
def test_mint(self):
|
||||||
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
# self.assertEqual(r.status, 1)
|
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], 1024)
|
||||||
# balance = self.contract.functions.balanceOf(self.w3.eth.accounts[1]).call()
|
r = self.rpc.do(o)
|
||||||
# self.assertEqual(balance, 1024)
|
o = receipt(tx_hash)
|
||||||
#
|
r = self.rpc.do(o)
|
||||||
# tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 976).transact()
|
self.assertEqual(r['status'], 1)
|
||||||
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
|
||||||
# self.assertEqual(r.status, 1)
|
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
#
|
r = self.rpc.do(o)
|
||||||
# balance = self.contract.functions.balanceOf(self.w3.eth.accounts[1]).call()
|
balance = c.parse_balance_of(r)
|
||||||
# self.assertEqual(balance, 2000)
|
self.assertEqual(balance, 1024)
|
||||||
#
|
|
||||||
# self.eth_tester.time_travel(self.start_time + 61)
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 976)
|
||||||
# balance = self.contract.functions.balanceOf(self.w3.eth.accounts[1]).call()
|
r = self.rpc.do(o)
|
||||||
# self.assertEqual(balance, int(2000 * 0.98))
|
o = receipt(tx_hash)
|
||||||
#
|
r = self.rpc.do(o)
|
||||||
#
|
self.assertEqual(r['status'], 1)
|
||||||
# def test_minter_control(self):
|
|
||||||
# with self.assertRaises(eth_tester.exceptions.TransactionFailed):
|
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
# tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[2], 1024).transact({'from': self.w3.eth.accounts[1]})
|
r = self.rpc.do(o)
|
||||||
#
|
balance = c.parse_balance_of(r)
|
||||||
# with self.assertRaises(eth_tester.exceptions.TransactionFailed):
|
self.assertEqual(balance, 2000)
|
||||||
# tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[1]})
|
|
||||||
#
|
|
||||||
# tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[0]})
|
self.backend.time_travel(self.start_time + 61)
|
||||||
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
(tx_hash, o) = c.apply_demurrage(self.address, sender_address=self.accounts[0])
|
||||||
# self.assertEqual(r.status, 1)
|
r = self.rpc.do(o)
|
||||||
#
|
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
# with self.assertRaises(eth_tester.exceptions.TransactionFailed):
|
r = self.rpc.do(o)
|
||||||
# tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[2]).transact({'from': self.w3.eth.accounts[1]})
|
balance = c.parse_balance_of(r)
|
||||||
#
|
self.assertEqual(balance, int(2000 * 0.98))
|
||||||
# tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[2], 1024).transact({'from': self.w3.eth.accounts[1]})
|
|
||||||
#
|
|
||||||
# with self.assertRaises(eth_tester.exceptions.TransactionFailed):
|
def test_minter_control(self):
|
||||||
# tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[2]})
|
|
||||||
#
|
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
|
||||||
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[1], self.accounts[2], 1024)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.add_minter(self.address, self.accounts[1], self.accounts[1])
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.add_minter(self.address, self.accounts[0], self.accounts[1])
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
|
||||||
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[1], self.accounts[2], 1024)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.add_minter(self.address, self.accounts[1], self.accounts[2])
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.remove_minter(self.address, self.accounts[1], self.accounts[1])
|
||||||
|
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[1], self.accounts[2], 1024)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
|
||||||
# tx_hash = self.contract.functions.removeMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[1]})
|
# tx_hash = self.contract.functions.removeMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[1]})
|
||||||
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||||
# self.assertEqual(r.status, 1)
|
# self.assertEqual(r.status, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user