From 27a0ac92b00754a4167bc86808159395a91f599e Mon Sep 17 00:00:00 2001 From: lash Date: Sat, 6 May 2023 23:01:45 +0100 Subject: [PATCH] Add unittest module, factor out common test code --- python/CHANGELOG | 11 ++++++ .../eth_accounts_index/unittest/__init__.py | 1 + python/eth_accounts_index/unittest/base.py | 38 +++++++++++++++++++ python/setup.cfg | 2 +- python/tests/test_app.py | 32 +--------------- 5 files changed, 53 insertions(+), 31 deletions(-) create mode 100644 python/eth_accounts_index/unittest/__init__.py create mode 100644 python/eth_accounts_index/unittest/base.py diff --git a/python/CHANGELOG b/python/CHANGELOG index c638d9c..ad98d7b 100644 --- a/python/CHANGELOG +++ b/python/CHANGELOG @@ -1,3 +1,14 @@ +* 0.5.2 + - Move test fixture to unittest module +* 0.5.1 + - Simplify contract events + - Split interfaces for mutable and immutable registries +* 0.4.x, 0.5.0 + - Update packaging to beta + - Change licence to AGPL +* 0.3.6 + - Correctly implement writer interface in contract + - Add contract json metadata in python package data * 0.3.5 - Remove contract compile warnings * 0.3.4 diff --git a/python/eth_accounts_index/unittest/__init__.py b/python/eth_accounts_index/unittest/__init__.py new file mode 100644 index 0000000..ae9e843 --- /dev/null +++ b/python/eth_accounts_index/unittest/__init__.py @@ -0,0 +1 @@ +from .base import TestAccountsIndex diff --git a/python/eth_accounts_index/unittest/base.py b/python/eth_accounts_index/unittest/base.py new file mode 100644 index 0000000..f19200e --- /dev/null +++ b/python/eth_accounts_index/unittest/base.py @@ -0,0 +1,38 @@ +# standard imports +import logging + +# external imports +from chainlib.eth.unittest.ethtester import EthTesterCase +from chainlib.connection import RPCConnection +from chainlib.eth.nonce import RPCNonceOracle +from chainlib.eth.address import to_checksum_address +from chainlib.eth.tx import receipt + +# local imports +from eth_accounts_index.registry import AccountRegistry + +logg = logging.getLogger(__name__) + + +class TestAccountsIndex(EthTesterCase): + + def setUp(self): + super(TestAccountsIndex, self).setUp() + self.conn = RPCConnection.connect(self.chain_spec, 'default') + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + + c = AccountRegistry(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.constructor(self.accounts[0]) + r = self.conn.do(o) + logg.debug(f'published with hash {r}') + + o = receipt(r) + r = self.conn.do(o) + self.address = to_checksum_address(r['contract_address']) + + (tx_hash, o) = c.add_writer(self.address, self.accounts[0], self.accounts[0]) + r = self.conn.do(o) + + o = receipt(r) + r = self.conn.do(o) + self.assertEqual(r['status'], 1) diff --git a/python/setup.cfg b/python/setup.cfg index a516cca..8220ea7 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-accounts-index -version = 0.5.1 +version = 0.5.2 description = Accounts index evm contract tooling with permissioned writes author = Louis Holbrook author_email = dev@holbrook.no diff --git a/python/tests/test_app.py b/python/tests/test_app.py index a2eabd3..182c2fc 100644 --- a/python/tests/test_app.py +++ b/python/tests/test_app.py @@ -26,6 +26,7 @@ from chainlib.eth.block import ( # local imports from eth_accounts_index.registry import AccountRegistry from eth_accounts_index import AccountsIndex +from eth_accounts_index.unittest import TestAccountsIndex logging.basicConfig(level=logging.DEBUG) logg = logging.getLogger() @@ -33,39 +34,10 @@ logg = logging.getLogger() testdir = os.path.dirname(__file__) -class TestNonceOracle: - - def __init__(self, address, default_value=0): - self.nonce = default_value - - - def next_nonce(self): - nonce = self.nonce - self.nonce += 1 - return nonce - - -class Test(EthTesterCase): +class Test(TestAccountsIndex): def setUp(self): super(Test, self).setUp() - nonce_oracle = TestNonceOracle(self.accounts[0]) - c = AccountRegistry(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) - (tx_hash, o) = c.constructor(self.accounts[0]) - self.conn = RPCConnection.connect(self.chain_spec, 'default') - r = self.conn.do(o) - logg.debug(f'published with hash {r}') - - o = receipt(r) - r = self.conn.do(o) - self.address = to_checksum_address(r['contract_address']) - - (tx_hash, o) = c.add_writer(self.address, self.accounts[0], self.accounts[0]) - r = self.conn.do(o) - - o = receipt(r) - r = self.conn.do(o) - self.assertEqual(r['status'], 1) def test_1_count(self):