Move test base to externally importable path
This commit is contained in:
parent
abe82949ea
commit
c6b5d9a8e0
1
python/erc20_demurrage_token/unittest/__init__.py
Normal file
1
python/erc20_demurrage_token/unittest/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .base import *
|
@ -12,6 +12,7 @@ from chainlib.eth.block import (
|
|||||||
block_by_number,
|
block_by_number,
|
||||||
)
|
)
|
||||||
from chainlib.eth.nonce import RPCNonceOracle
|
from chainlib.eth.nonce import RPCNonceOracle
|
||||||
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from erc20_demurrage_token import (
|
from erc20_demurrage_token import (
|
||||||
@ -29,64 +30,93 @@ TAX_LEVEL = int(10000 * 2) # 2%
|
|||||||
PERIOD = 10
|
PERIOD = 10
|
||||||
|
|
||||||
|
|
||||||
class TestDemurrage(EthTesterCase):
|
class TestTokenDeploy:
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(TestDemurrage, self).setUp()
|
|
||||||
|
|
||||||
|
def __init__(self, rpc, token_symbol='FOO', token_name='Foo Token', sink_address=ZERO_ADDRESS, supply=10**12):
|
||||||
self.tax_level = TAX_LEVEL
|
self.tax_level = TAX_LEVEL
|
||||||
self.period_seconds = PERIOD * 60
|
self.period_seconds = PERIOD * 60
|
||||||
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
|
||||||
self.settings = DemurrageTokenSettings()
|
self.settings = DemurrageTokenSettings()
|
||||||
self.settings.name = 'Foo Token'
|
self.settings.name = token_name
|
||||||
self.settings.symbol = 'FOO'
|
self.settings.symbol = token_symbol
|
||||||
self.settings.decimals = 6
|
self.settings.decimals = 6
|
||||||
self.settings.demurrage_level = TAX_LEVEL * (10 ** 32)
|
self.settings.demurrage_level = TAX_LEVEL * (10 ** 32)
|
||||||
self.settings.period_minutes = PERIOD
|
self.settings.period_minutes = PERIOD
|
||||||
self.settings.sink_address = self.accounts[9]
|
self.settings.sink_address = sink_address
|
||||||
self.sink_address = self.settings.sink_address
|
self.sink_address = self.settings.sink_address
|
||||||
|
|
||||||
o = block_latest()
|
o = block_latest()
|
||||||
self.start_block = self.rpc.do(o)
|
self.start_block = rpc.do(o)
|
||||||
|
|
||||||
o = block_by_number(self.start_block, include_tx=False)
|
o = block_by_number(self.start_block, include_tx=False)
|
||||||
r = self.rpc.do(o)
|
r = rpc.do(o)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.start_time = int(r['timestamp'], 16)
|
self.start_time = int(r['timestamp'], 16)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.start_time = int(r['timestamp'])
|
self.start_time = int(r['timestamp'])
|
||||||
|
|
||||||
self.default_supply = 10 ** 12
|
self.default_supply = supply
|
||||||
self.default_supply_cap = int(self.default_supply * 10)
|
self.default_supply_cap = int(self.default_supply * 10)
|
||||||
|
|
||||||
|
|
||||||
def deploy(self, interface, mode):
|
def deploy(self, rpc, deployer_address, interface, mode, supply_cap=10**12):
|
||||||
tx_hash = None
|
tx_hash = None
|
||||||
o = None
|
o = None
|
||||||
|
logg.debug('mode {} {}'.format(mode, self.settings))
|
||||||
|
self.mode = mode
|
||||||
if mode == 'MultiNocap':
|
if mode == 'MultiNocap':
|
||||||
(tx_hash, o) = interface.constructor(self.accounts[0], self.settings, redistribute=True, cap=0)
|
(tx_hash, o) = interface.constructor(deployer_address, self.settings, redistribute=True, cap=0)
|
||||||
elif mode == 'SingleNocap':
|
elif mode == 'SingleNocap':
|
||||||
(tx_hash, o) = interface.constructor(self.accounts[0], self.settings, redistribute=False, cap=0)
|
(tx_hash, o) = interface.constructor(deployer_address, self.settings, redistribute=False, cap=0)
|
||||||
elif mode == 'MultiCap':
|
elif mode == 'MultiCap':
|
||||||
(tx_hash, o) = interface.constructor(self.accounts[0], self.settings, redistribute=True, cap=self.default_supply_cap)
|
(tx_hash, o) = interface.constructor(deployer_address, self.settings, redistribute=True, cap=supply_cap)
|
||||||
elif mode == 'SingleCap':
|
elif mode == 'SingleCap':
|
||||||
(tx_hash, o) = interface.constructor(self.accounts[0], self.settings, redistribute=False, cap=self.default_supply_cap)
|
(tx_hash, o) = interface.constructor(deployer_address, self.settings, redistribute=False, cap=supply_cap)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Invalid mode "{}", valid are {}'.format(self.mode, DemurrageToken.valid_modes))
|
raise ValueError('Invalid mode "{}", valid are {}'.format(mode, DemurrageToken.valid_modes))
|
||||||
|
|
||||||
r = self.rpc.do(o)
|
r = rpc.do(o)
|
||||||
o = receipt(tx_hash)
|
o = receipt(tx_hash)
|
||||||
r = self.rpc.do(o)
|
r = rpc.do(o)
|
||||||
self.assertEqual(r['status'], 1)
|
assert r['status'] == 1
|
||||||
self.start_block = r['block_number']
|
self.start_block = r['block_number']
|
||||||
self.address = r['contract_address']
|
self.address = r['contract_address']
|
||||||
|
|
||||||
o = block_by_number(r['block_number'])
|
o = block_by_number(r['block_number'])
|
||||||
r = self.rpc.do(o)
|
r = rpc.do(o)
|
||||||
self.start_time = r['timestamp']
|
self.start_time = r['timestamp']
|
||||||
|
|
||||||
|
return self.address
|
||||||
|
|
||||||
|
|
||||||
|
class TestDemurrage(EthTesterCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestDemurrage, self).setUp()
|
||||||
|
# token_deploy = TestTokenDeploy()
|
||||||
|
# self.settings = token_deploy.settings
|
||||||
|
# self.sink_address = token_deploy.sink_address
|
||||||
|
# self.start_block = token_deploy.start_block
|
||||||
|
# self.start_time = token_deploy.start_time
|
||||||
|
# self.default_supply = self.default_supply
|
||||||
|
# self.default_supply_cap = self.default_supply_cap
|
||||||
|
self.deployer = TestTokenDeploy(self.rpc)
|
||||||
|
self.default_supply = self.deployer.default_supply
|
||||||
|
self.default_supply_cap = self.deployer.default_supply_cap
|
||||||
|
self.start_block = None
|
||||||
|
self.address = None
|
||||||
|
self.start_time = None
|
||||||
|
|
||||||
|
|
||||||
|
def deploy(self, interface, mode):
|
||||||
|
self.address = self.deployer.deploy(self.rpc, self.accounts[0], interface, mode, supply_cap=self.default_supply_cap)
|
||||||
|
self.start_block = self.deployer.start_block
|
||||||
|
self.start_time = self.deployer.start_time
|
||||||
|
self.tax_level = self.deployer.tax_level
|
||||||
|
self.period_seconds = self.deployer.period_seconds
|
||||||
|
self.sink_address = self.deployer.sink_address
|
||||||
|
|
||||||
logg.debug('contract address {} start block {} start time {}'.format(self.address, self.start_block, self.start_time))
|
logg.debug('contract address {} start block {} start time {}'.format(self.address, self.start_block, self.start_time))
|
||||||
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -x
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export PYTHONPATH=.
|
export PYTHONPATH=.
|
||||||
@ -31,3 +32,4 @@ done
|
|||||||
#done
|
#done
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
set +x
|
||||||
|
@ -13,7 +13,7 @@ from chainlib.eth.tx import receipt
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrageDefault
|
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -18,7 +18,7 @@ from chainlib.eth.block import (
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrageDefault
|
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -18,7 +18,7 @@ from hexathon import (
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrageCap
|
from erc20_demurrage_token.unittest.base import TestDemurrageCap
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -10,7 +10,7 @@ from erc20_demurrage_token import DemurrageToken
|
|||||||
from erc20_demurrage_token.demurrage import DemurrageCalculator
|
from erc20_demurrage_token.demurrage import DemurrageCalculator
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrage
|
from erc20_demurrage_token.unittest.base import TestDemurrage
|
||||||
|
|
||||||
|
|
||||||
class TestEmulate(TestDemurrage):
|
class TestEmulate(TestDemurrage):
|
||||||
|
@ -18,7 +18,7 @@ from chainlib.eth.block import (
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrageDefault
|
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -13,7 +13,7 @@ from chainlib.eth.tx import receipt
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrageDefault
|
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -22,7 +22,7 @@ from hexathon import (
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrageDefault
|
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -21,7 +21,7 @@ from hexathon import (
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrageUnit
|
from erc20_demurrage_token.unittest.base import TestDemurrageUnit
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -16,7 +16,7 @@ import eth_tester
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrageDefault
|
from erc20_demurrage_token.unittest.base import TestDemurrageDefault
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -18,7 +18,7 @@ from hexathon import (
|
|||||||
from erc20_demurrage_token import DemurrageToken
|
from erc20_demurrage_token import DemurrageToken
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
from tests.base import TestDemurrageSingle
|
from erc20_demurrage_token.unittest.base import TestDemurrageSingle
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
Reference in New Issue
Block a user