commit 64621ca9b3411753e8015ffec4f2e315b46a849f
parent 996c0224cff70b271472738769ef1bec5b19f196
Author: nolash <dev@holbrook.no>
Date: Sat, 5 Jun 2021 17:59:34 +0200
Add initial sim setup, test
Diffstat:
6 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/python/MANIFEST.in b/python/MANIFEST.in
@@ -1 +1 @@
-include sarafu_token/data/*
+include erc20_demurrage_token/data/*
diff --git a/python/erc20_demurrage_token/runnable/deploy.py b/python/erc20_demurrage_token/runnable/deploy.py
@@ -91,6 +91,12 @@ if config.get('TOKEN_NAME') == None:
logg.info('token name not set, using symbol {} as name'.format(config.get('TOKEN_SYMBOL')))
config.add(config.get('TOKEN_SYMBOL'), 'TOKEN_NAME', True)
config.dict_override(args_override, 'cli args')
+
+if config.get('TOKEN_SUPPLY_LIMIT') == None:
+ config.add(0, 'TOKEN_SUPPLY_LIMIT', True)
+
+if config.get('TOKEN_REDISTRIBUTION_PERIOD') == None:
+ config.add(10800, 'TOKEN_REDISTRIBUTION_PERIOD', True)
logg.debug('config loaded:\n{}'.format(config))
passphrase_env = 'ETH_PASSPHRASE'
diff --git a/python/erc20_demurrage_token/sim/__init__.py b/python/erc20_demurrage_token/sim/__init__.py
@@ -0,0 +1 @@
+from .sim import DemurrageTokenSimulation
diff --git a/python/erc20_demurrage_token/sim/sim.py b/python/erc20_demurrage_token/sim/sim.py
@@ -0,0 +1,38 @@
+# external imports
+from chainlib.eth.unittest.ethtester import create_tester_signer
+from chainlib.eth.unittest.base import TestRPCConnection
+from chainlib.eth.tx import receipt
+from chainlib.eth.nonce import RPCNonceOracle
+from chainlib.eth.address import to_checksum_address
+from crypto_dev_signer.keystore.dict import DictKeystore
+from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
+from hexathon import (
+ strip_0x,
+ add_0x,
+ )
+
+# local imports
+from erc20_demurrage_token import DemurrageToken
+
+class DemurrageTokenSimulation:
+
+ def __init__(self, chain_spec, settings, redistribute=True, cap=0):
+ self.accounts = []
+ self.keystore = DictKeystore()
+ self.signer = EIP155Signer(self.keystore)
+ self.eth_helper = create_tester_signer(self.keystore)
+ self.eth_backend = self.eth_helper.backend
+ self.rpc = TestRPCConnection(None, self.eth_helper, self.signer)
+ for a in self.keystore.list():
+ self.accounts.append(add_0x(to_checksum_address(a)))
+ settings.sink_address = self.accounts[0]
+
+ nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.rpc)
+ c = DemurrageToken(chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.constructor(self.accounts[0], settings, redistribute=redistribute, cap=cap)
+ self.rpc.do(o)
+ o = receipt(tx_hash)
+ r = self.rpc.do(o)
+ if (r['status'] != 1):
+ raise RuntimeError('contract deployment failed')
+ self.address = r['contract_address']
diff --git a/python/setup.cfg b/python/setup.cfg
@@ -29,6 +29,7 @@ python_requires = >= 3.6
packages =
erc20_demurrage_token
erc20_demurrage_token.runnable
+ erc20_demurrage_token.data
[options.package_data]
* =
diff --git a/python/tests/sim/tests_sim.py b/python/tests/sim/tests_sim.py
@@ -0,0 +1,33 @@
+# standard imports
+import unittest
+import logging
+
+# external imports
+from chainlib.chain import ChainSpec
+
+# local imports
+from erc20_demurrage_token import DemurrageTokenSettings
+from erc20_demurrage_token.sim import DemurrageTokenSimulation
+
+logg = logging.getLogger()
+
+
+class TestSim(unittest.TestCase):
+
+ def setUp(self):
+ self.chain_spec = ChainSpec('evm', 'foochain', 42)
+ self.cap = 1000000000
+ settings = DemurrageTokenSettings()
+ settings.name = 'Simulated Demurrage Token'
+ settings.symbol = 'SIM'
+ settings.decimals = 6
+ settings.demurrage_level = 50
+ settings.period_minutes = 10800
+ self.sim = DemurrageTokenSimulation(self.chain_spec, settings, redistribute=True, cap=self.cap)
+
+
+ def test_hello(self):
+ pass
+
+if __name__ == '__main__':
+ unittest.main()