Add unittest module, factor out common test code

This commit is contained in:
lash 2023-05-06 23:01:45 +01:00
parent e6a8140d2d
commit 27a0ac92b0
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 53 additions and 31 deletions

View File

@ -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 * 0.3.5
- Remove contract compile warnings - Remove contract compile warnings
* 0.3.4 * 0.3.4

View File

@ -0,0 +1 @@
from .base import TestAccountsIndex

View File

@ -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)

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = eth-accounts-index name = eth-accounts-index
version = 0.5.1 version = 0.5.2
description = Accounts index evm contract tooling with permissioned writes description = Accounts index evm contract tooling with permissioned writes
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -26,6 +26,7 @@ from chainlib.eth.block import (
# local imports # local imports
from eth_accounts_index.registry import AccountRegistry from eth_accounts_index.registry import AccountRegistry
from eth_accounts_index import AccountsIndex from eth_accounts_index import AccountsIndex
from eth_accounts_index.unittest import TestAccountsIndex
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger() logg = logging.getLogger()
@ -33,39 +34,10 @@ logg = logging.getLogger()
testdir = os.path.dirname(__file__) testdir = os.path.dirname(__file__)
class TestNonceOracle: class Test(TestAccountsIndex):
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):
def setUp(self): def setUp(self):
super(Test, self).setUp() 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): def test_1_count(self):