2021-02-02 11:26:44 +01:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
import json
|
|
|
|
import logging
|
2021-02-06 15:18:30 +01:00
|
|
|
import datetime
|
2021-02-02 11:26:44 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
# external imports
|
|
|
|
from chainlib.eth.constant import ZERO_ADDRESS
|
|
|
|
from chainlib.eth.nonce import RPCNonceOracle
|
2021-06-04 09:24:05 +02:00
|
|
|
from chainlib.eth.tx import receipt
|
|
|
|
import eth_tester
|
2021-02-05 09:44:15 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
# local imports
|
|
|
|
from erc20_demurrage_token import DemurrageToken
|
2021-02-05 09:44:15 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
# test imports
|
|
|
|
from tests.base import TestDemurrageDefault
|
2021-02-02 11:26:44 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
logg = logging.getLogger()
|
2021-02-06 15:18:30 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
testdir = os.path.dirname(__file__)
|
2021-02-02 11:26:44 +01:00
|
|
|
|
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
class TestBasic(TestDemurrageDefault):
|
2021-02-02 11:26:44 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
@unittest.skip('foo')
|
2021-02-02 19:09:13 +01:00
|
|
|
def test_hello(self):
|
2021-06-04 09:05:08 +02:00
|
|
|
|
|
|
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
|
|
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
|
|
|
o = c.actual_period(self.address, sender_address=self.accounts[0])
|
|
|
|
r = self.rpc.do(o)
|
|
|
|
|
|
|
|
self.backend.time_travel(self.start_time + 61)
|
|
|
|
o = c.actual_period(self.address, sender_address=self.accounts[0])
|
|
|
|
r = self.rpc.do(o)
|
2021-02-02 11:26:44 +01:00
|
|
|
|
2021-02-02 16:10:21 +01:00
|
|
|
|
2021-06-04 09:24:05 +02:00
|
|
|
@unittest.skip('foo')
|
2021-02-06 15:18:30 +01:00
|
|
|
def test_apply_demurrage(self):
|
|
|
|
modifier = 10 * (10 ** 37)
|
2021-02-02 16:10:21 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
|
|
|
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
2021-02-02 16:10:21 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
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)
|
2021-02-05 09:22:36 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
self.backend.time_travel(self.start_time + 59)
|
|
|
|
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)
|
2021-02-05 09:22:36 +01:00
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
self.backend.time_travel(self.start_time + 61)
|
|
|
|
(tx_hash, o) = c.apply_demurrage(self.address, sender_address=self.accounts[0])
|
|
|
|
r = self.rpc.do(o)
|
|
|
|
o = c.demurrage_amount(self.address, sender_address=self.accounts[0])
|
|
|
|
r = self.rpc.do(o)
|
|
|
|
demurrage_amount = c.parse_demurrage_amount(r)
|
|
|
|
modifier = int(98 * (10 ** 36))
|
|
|
|
self.assertEqual(modifier, demurrage_amount)
|
2021-02-05 09:22:36 +01:00
|
|
|
|
|
|
|
|
2021-06-04 09:24:05 +02:00
|
|
|
@unittest.skip('foo')
|
|
|
|
def test_mint(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], 1024)
|
|
|
|
r = self.rpc.do(o)
|
|
|
|
o = receipt(tx_hash)
|
|
|
|
r = self.rpc.do(o)
|
|
|
|
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 = c.parse_balance_of(r)
|
|
|
|
self.assertEqual(balance, 1024)
|
|
|
|
|
|
|
|
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 976)
|
|
|
|
r = self.rpc.do(o)
|
|
|
|
o = receipt(tx_hash)
|
|
|
|
r = self.rpc.do(o)
|
|
|
|
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 = c.parse_balance_of(r)
|
|
|
|
self.assertEqual(balance, 2000)
|
|
|
|
|
|
|
|
|
|
|
|
self.backend.time_travel(self.start_time + 61)
|
|
|
|
(tx_hash, o) = c.apply_demurrage(self.address, sender_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, int(2000 * 0.98))
|
|
|
|
|
|
|
|
|
|
|
|
def test_minter_control(self):
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2021-06-04 09:05:08 +02:00
|
|
|
# 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)
|
|
|
|
# self.assertEqual(r.status, 1)
|
|
|
|
#
|
|
|
|
# with self.assertRaises(eth_tester.exceptions.TransactionFailed):
|
|
|
|
# tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[2], 1024).transact({'from': self.w3.eth.accounts[1]})
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# def test_base_amount(self):
|
|
|
|
# tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1000).transact()
|
|
|
|
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
|
|
|
# self.assertEqual(r.status, 1)
|
|
|
|
#
|
|
|
|
# self.eth_tester.time_travel(self.start_time + 61)
|
|
|
|
#
|
|
|
|
# self.contract.functions.applyDemurrage().transact()
|
|
|
|
# #demurrage_modifier = self.contract.functions.demurrageModifier().call()
|
|
|
|
# #demurrage_amount = self.contract.functions.toDemurrageAmount(demurrage_modifier).call()
|
|
|
|
# demurrage_amount = self.contract.functions.demurrageAmount().call()
|
|
|
|
#
|
|
|
|
# a = self.contract.functions.toBaseAmount(1000).call();
|
|
|
|
# self.assertEqual(a, 1020)
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# def test_transfer(self):
|
|
|
|
# tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1024).transact()
|
|
|
|
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
|
|
|
# self.assertEqual(r.status, 1)
|
|
|
|
#
|
|
|
|
# tx_hash = self.contract.functions.transfer(self.w3.eth.accounts[2], 500).transact({'from': self.w3.eth.accounts[1]})
|
|
|
|
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
|
|
|
# self.assertEqual(r.status, 1)
|
|
|
|
# logg.debug('tx {}'.format(r))
|
|
|
|
#
|
|
|
|
# balance_alice = self.contract.functions.balanceOf(self.w3.eth.accounts[1]).call()
|
|
|
|
# self.assertEqual(balance_alice, 524)
|
|
|
|
#
|
|
|
|
# balance_bob = self.contract.functions.balanceOf(self.w3.eth.accounts[2]).call()
|
|
|
|
# self.assertEqual(balance_bob, 500)
|
|
|
|
#
|
|
|
|
# tx_hash = self.contract.functions.transfer(self.w3.eth.accounts[2], 500).transact({'from': self.w3.eth.accounts[1]})
|
|
|
|
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
|
|
|
# self.assertEqual(r.status, 1)
|
|
|
|
# logg.debug('tx {}'.format(r))
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# def test_transfer_from(self):
|
|
|
|
# tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1024).transact()
|
|
|
|
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
|
|
|
# self.assertEqual(r.status, 1)
|
|
|
|
#
|
|
|
|
# tx_hash = self.contract.functions.approve(self.w3.eth.accounts[2], 500).transact({'from': self.w3.eth.accounts[1]})
|
|
|
|
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
|
|
|
# self.assertEqual(r.status, 1)
|
|
|
|
# logg.debug('tx {}'.format(r))
|
|
|
|
#
|
|
|
|
# balance_alice = self.contract.functions.balanceOf(self.w3.eth.accounts[1]).call()
|
|
|
|
# self.assertEqual(balance_alice, 1024)
|
|
|
|
#
|
|
|
|
# tx_hash = self.contract.functions.transferFrom(self.w3.eth.accounts[1], self.w3.eth.accounts[3], 500).transact({'from': self.w3.eth.accounts[2]})
|
|
|
|
# r = self.w3.eth.getTransactionReceipt(tx_hash)
|
|
|
|
# self.assertEqual(r.status, 1)
|
|
|
|
# logg.debug('tx {}'.format(r))
|
|
|
|
#
|
|
|
|
# balance_alice = self.contract.functions.balanceOf(self.w3.eth.accounts[1]).call()
|
|
|
|
# self.assertEqual(balance_alice, 524)
|
|
|
|
#
|
|
|
|
# balance_alice = self.contract.functions.balanceOf(self.w3.eth.accounts[3]).call()
|
|
|
|
# self.assertEqual(balance_alice, 500)
|
2021-02-05 09:22:36 +01:00
|
|
|
|
|
|
|
|
2021-02-02 11:26:44 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|