Cleanup, docs, benchmarks
This commit is contained in:
@@ -47,6 +47,14 @@ class Test(unittest.TestCase):
|
||||
pass
|
||||
|
||||
|
||||
def test_construct(self):
|
||||
period = 10
|
||||
c = self.w3.eth.contract(abi=self.abi, bytecode=self.bytecode)
|
||||
tx_hash = c.constructor('Foo Token', 'FOO', 6, TAX_LEVEL * (10 ** 32), period, self.sink_address).transact({'from': self.w3.eth.accounts[0]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
print('construct: {}'.format(r['gasUsed']))
|
||||
|
||||
|
||||
def test_gas_changeperiod(self):
|
||||
period = 43200
|
||||
for i in range(5):
|
||||
@@ -64,7 +72,155 @@ class Test(unittest.TestCase):
|
||||
tx_hash = contract.functions.changePeriod().transact()
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
|
||||
print('{} ({}): {}'.format(i, 60 * (10 ** i), r['gasUsed']))
|
||||
print('changePeriod {} ({}): {}'.format(i, 60 * (10 ** i), r['gasUsed']))
|
||||
|
||||
|
||||
def test_mint(self):
|
||||
period = 10
|
||||
c = self.w3.eth.contract(abi=self.abi, bytecode=self.bytecode)
|
||||
tx_hash = c.constructor('Foo Token', 'FOO', 6, TAX_LEVEL * (10 ** 32), period, self.sink_address).transact({'from': self.w3.eth.accounts[0]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
contract = self.w3.eth.contract(abi=self.abi, address=r.contractAddress)
|
||||
|
||||
start_block = self.w3.eth.blockNumber
|
||||
b = self.w3.eth.getBlock(start_block)
|
||||
start_time = b['timestamp']
|
||||
|
||||
tx_hash = contract.functions.mintTo(self.w3.eth.accounts[1], 1000000).transact({'from': self.w3.eth.accounts[0]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
print ('mintTo: {}'.format(r['gasUsed']))
|
||||
|
||||
|
||||
def test_transfer(self):
|
||||
period = 10
|
||||
c = self.w3.eth.contract(abi=self.abi, bytecode=self.bytecode)
|
||||
tx_hash = c.constructor('Foo Token', 'FOO', 6, TAX_LEVEL * (10 ** 32), period, self.sink_address).transact({'from': self.w3.eth.accounts[0]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
contract = self.w3.eth.contract(abi=self.abi, address=r.contractAddress)
|
||||
|
||||
start_block = self.w3.eth.blockNumber
|
||||
b = self.w3.eth.getBlock(start_block)
|
||||
start_time = b['timestamp']
|
||||
|
||||
contract.functions.mintTo(self.w3.eth.accounts[1], 1000000).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
tx_hash = contract.functions.transfer(self.w3.eth.accounts[2], 1000000).transact({'from': self.w3.eth.accounts[1]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
print ('transfer: {}'.format(r['gasUsed']))
|
||||
|
||||
|
||||
def test_approve(self):
|
||||
period = 10
|
||||
c = self.w3.eth.contract(abi=self.abi, bytecode=self.bytecode)
|
||||
tx_hash = c.constructor('Foo Token', 'FOO', 6, TAX_LEVEL * (10 ** 32), period, self.sink_address).transact({'from': self.w3.eth.accounts[0]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
contract = self.w3.eth.contract(abi=self.abi, address=r.contractAddress)
|
||||
|
||||
start_block = self.w3.eth.blockNumber
|
||||
b = self.w3.eth.getBlock(start_block)
|
||||
start_time = b['timestamp']
|
||||
|
||||
contract.functions.mintTo(self.w3.eth.accounts[1], 1000000).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
tx_hash = contract.functions.approve(self.w3.eth.accounts[2], 1000000).transact({'from': self.w3.eth.accounts[1]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
print ('approve: {}'.format(r['gasUsed']))
|
||||
|
||||
|
||||
def test_transferfrom(self):
|
||||
period = 10
|
||||
c = self.w3.eth.contract(abi=self.abi, bytecode=self.bytecode)
|
||||
tx_hash = c.constructor('Foo Token', 'FOO', 6, TAX_LEVEL * (10 ** 32), period, self.sink_address).transact({'from': self.w3.eth.accounts[0]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
contract = self.w3.eth.contract(abi=self.abi, address=r.contractAddress)
|
||||
|
||||
start_block = self.w3.eth.blockNumber
|
||||
b = self.w3.eth.getBlock(start_block)
|
||||
start_time = b['timestamp']
|
||||
|
||||
contract.functions.mintTo(self.w3.eth.accounts[1], 1000000).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
contract.functions.approve(self.w3.eth.accounts[2], 1000000).transact({'from': self.w3.eth.accounts[1]})
|
||||
|
||||
tx_hash = contract.functions.transferFrom(self.w3.eth.accounts[1], self.w3.eth.accounts[3], 1000000).transact({'from': self.w3.eth.accounts[2]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
print ('transferFrom: {}'.format(r['gasUsed']))
|
||||
|
||||
|
||||
def test_redistribute_default(self):
|
||||
period = 10
|
||||
c = self.w3.eth.contract(abi=self.abi, bytecode=self.bytecode)
|
||||
tx_hash = c.constructor('Foo Token', 'FOO', 6, TAX_LEVEL * (10 ** 32), period, self.sink_address).transact({'from': self.w3.eth.accounts[0]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
contract = self.w3.eth.contract(abi=self.abi, address=r.contractAddress)
|
||||
|
||||
start_block = self.w3.eth.blockNumber
|
||||
b = self.w3.eth.getBlock(start_block)
|
||||
start_time = b['timestamp']
|
||||
|
||||
for i in range(100):
|
||||
addr = web3.Web3.toChecksumAddress('0x' + os.urandom(20).hex())
|
||||
contract.functions.mintTo(addr, 1000000 * (i+1)).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
self.eth_tester.time_travel(start_time + period * 60 + 1)
|
||||
redistribution = contract.functions.redistributions(0).call()
|
||||
tx_hash = contract.functions.changePeriod().transact({'from': self.w3.eth.accounts[2]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
print ('chainPeriod -> defaultRedistribution: {}'.format(r['gasUsed']))
|
||||
|
||||
|
||||
def test_redistribution_account(self):
|
||||
period = 10
|
||||
c = self.w3.eth.contract(abi=self.abi, bytecode=self.bytecode)
|
||||
tx_hash = c.constructor('Foo Token', 'FOO', 6, TAX_LEVEL * (10 ** 32), period, self.sink_address).transact({'from': self.w3.eth.accounts[0]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
contract = self.w3.eth.contract(abi=self.abi, address=r.contractAddress)
|
||||
|
||||
start_block = self.w3.eth.blockNumber
|
||||
b = self.w3.eth.getBlock(start_block)
|
||||
start_time = b['timestamp']
|
||||
|
||||
contract.functions.mintTo(self.w3.eth.accounts[1], 1000000).transact({'from': self.w3.eth.accounts[0]})
|
||||
contract.functions.transfer(self.w3.eth.accounts[2], 1000000).transact({'from': self.w3.eth.accounts[1]})
|
||||
|
||||
for i in range(100):
|
||||
addr = web3.Web3.toChecksumAddress('0x' + os.urandom(20).hex())
|
||||
contract.functions.mintTo(addr, 1000000 * (i+1)).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
self.eth_tester.time_travel(start_time + period * 60 + 1)
|
||||
redistribution = contract.functions.redistributions(0).call()
|
||||
tx_hash = contract.functions.applyRedistributionOnAccount(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[2]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
self.assertEqual(r.logs[0].topics[0].hex(), '0x9a2a887706623ad3ff7fc85652deeceabe9fe1e00466c597972079ee91ea40d3')
|
||||
print ('redistribute account: {}'.format(r['gasUsed']))
|
||||
|
||||
|
||||
def test_redistribution_account_transfer(self):
|
||||
period = 10
|
||||
c = self.w3.eth.contract(abi=self.abi, bytecode=self.bytecode)
|
||||
tx_hash = c.constructor('Foo Token', 'FOO', 6, TAX_LEVEL * (10 ** 32), period, self.sink_address).transact({'from': self.w3.eth.accounts[0]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
contract = self.w3.eth.contract(abi=self.abi, address=r.contractAddress)
|
||||
|
||||
start_block = self.w3.eth.blockNumber
|
||||
b = self.w3.eth.getBlock(start_block)
|
||||
start_time = b['timestamp']
|
||||
|
||||
contract.functions.mintTo(self.w3.eth.accounts[1], 2000000).transact({'from': self.w3.eth.accounts[0]})
|
||||
contract.functions.transfer(self.w3.eth.accounts[2], 1000000).transact({'from': self.w3.eth.accounts[1]})
|
||||
|
||||
for i in range(10):
|
||||
addr = web3.Web3.toChecksumAddress('0x' + os.urandom(20).hex())
|
||||
contract.functions.mintTo(addr, 1000000 * (i+1)).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
self.eth_tester.time_travel(start_time + period * 60 + 1)
|
||||
redistribution = contract.functions.redistributions(0).call()
|
||||
contract.functions.changePeriod().transact({'from': self.w3.eth.accounts[0]})
|
||||
tx_hash = contract.functions.transfer(self.w3.eth.accounts[3], 100000).transact({'from': self.w3.eth.accounts[1]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
self.assertEqual(r.logs[0].topics[0].hex(), '0x9a2a887706623ad3ff7fc85652deeceabe9fe1e00466c597972079ee91ea40d3')
|
||||
print ('redistribute account: {}'.format(r['gasUsed']))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -71,25 +71,30 @@ class Test(unittest.TestCase):
|
||||
self.assertEqual(self.contract.functions.actualPeriod().call(), 2)
|
||||
|
||||
|
||||
|
||||
def test_apply_demurrage(self):
|
||||
modifier = 10 * (10 ** 37)
|
||||
demurrage_modifier = self.contract.functions.demurrageModifier().call()
|
||||
demurrage_modifier &= (1 << 128) - 1
|
||||
self.assertEqual(modifier, demurrage_modifier)
|
||||
#demurrage_modifier = self.contract.functions.demurrageModifier().call()
|
||||
#demurrage_modifier &= (1 << 128) - 1
|
||||
demurrage_amount = self.contract.functions.demurrageAmount().call()
|
||||
#self.assertEqual(modifier, demurrage_modifier)
|
||||
self.assertEqual(modifier, demurrage_amount)
|
||||
|
||||
self.eth_tester.time_travel(self.start_time + 59)
|
||||
demurrage_modifier = self.contract.functions.demurrageModifier().call()
|
||||
demurrage_modifier &= (1 << 128) - 1
|
||||
self.assertEqual(modifier, demurrage_modifier)
|
||||
#demurrage_modifier = self.contract.functions.demurrageModifier().call()
|
||||
demurrage_amount = self.contract.functions.demurrageAmount().call()
|
||||
#demurrage_modifier &= (1 << 128) - 1
|
||||
#self.assertEqual(modifier, demurrage_modifier)
|
||||
self.assertEqual(modifier, demurrage_amount)
|
||||
|
||||
self.eth_tester.time_travel(self.start_time + 61)
|
||||
tx_hash = self.contract.functions.applyDemurrage().transact()
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
|
||||
demurrage_modifier = self.contract.functions.demurrageModifier().call()
|
||||
demurrage_modifier &= (1 << 128) - 1
|
||||
self.assertEqual(int(98 * (10 ** 36)), demurrage_modifier)
|
||||
#demurrage_modifier = self.contract.functions.demurrageModifier().call()
|
||||
demurrage_amount = self.contract.functions.demurrageAmount().call()
|
||||
#demurrage_modifier &= (1 << 128) - 1
|
||||
#self.assertEqual(int(98 * (10 ** 36)), demurrage_modifier)
|
||||
self.assertEqual(int(98 * (10 ** 36)), demurrage_amount)
|
||||
|
||||
|
||||
def test_mint(self):
|
||||
@@ -111,7 +116,34 @@ class Test(unittest.TestCase):
|
||||
balance = self.contract.functions.balanceOf(self.w3.eth.accounts[1]).call()
|
||||
self.assertEqual(balance, int(2000 * 0.98))
|
||||
|
||||
|
||||
|
||||
def test_minter_control(self):
|
||||
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]})
|
||||
|
||||
with self.assertRaises(eth_tester.exceptions.TransactionFailed):
|
||||
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]})
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
self.assertEqual(r.status, 1)
|
||||
|
||||
with self.assertRaises(eth_tester.exceptions.TransactionFailed):
|
||||
tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[2]).transact({'from': self.w3.eth.accounts[1]})
|
||||
|
||||
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):
|
||||
tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[2]})
|
||||
|
||||
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)
|
||||
@@ -120,9 +152,9 @@ class Test(unittest.TestCase):
|
||||
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()
|
||||
logg.debug('d {} {}'.format(demurrage_modifier.to_bytes(32, 'big').hex(), demurrage_amount))
|
||||
#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)
|
||||
|
||||
@@ -60,20 +60,21 @@ class Test(unittest.TestCase):
|
||||
pass
|
||||
|
||||
|
||||
@unittest.skip('this function has been removed from contract')
|
||||
def test_tax_period(self):
|
||||
t = self.contract.functions.taxLevel().call()
|
||||
logg.debug('taxlevel {}'.format(t))
|
||||
|
||||
a = self.contract.functions.toTaxPeriodAmount(1000000, 0).call()
|
||||
a = self.contract.functions.toDemurrageAmount(1000000, 0).call()
|
||||
self.assertEqual(a, 1000000)
|
||||
|
||||
a = self.contract.functions.toTaxPeriodAmount(1000000, 1).call()
|
||||
a = self.contract.functions.toDemurrageAmount(1000000, 1).call()
|
||||
self.assertEqual(a, 980000)
|
||||
|
||||
a = self.contract.functions.toTaxPeriodAmount(1000000, 2).call()
|
||||
a = self.contract.functions.toDemurrageAmount(1000000, 2).call()
|
||||
self.assertEqual(a, 960400)
|
||||
|
||||
a = self.contract.functions.toTaxPeriodAmount(980000, 1).call()
|
||||
a = self.contract.functions.toDemurrageAmount(980000, 1).call()
|
||||
self.assertEqual(a, 960400)
|
||||
|
||||
|
||||
|
||||
@@ -71,6 +71,9 @@ class Test(unittest.TestCase):
|
||||
|
||||
# TODO: check receipt log outputs
|
||||
def test_redistribution_storage(self):
|
||||
redistribution = self.contract.functions.redistributions(0).call();
|
||||
self.assertEqual(redistribution.hex(), '000000000000000000000000f424000000000000000000000000000000000001')
|
||||
|
||||
self.contract.functions.mintTo(self.w3.eth.accounts[1], 1000000).transact()
|
||||
self.contract.functions.mintTo(self.w3.eth.accounts[2], 1000000).transact()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user