cic-contracts/python-contract-interfaces/eth_writer/unittest/base.py

59 lines
1.9 KiB
Python
Raw Permalink Normal View History

2023-06-06 19:12:06 +02:00
# standard imports
import os
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.tx import receipt
2023-06-06 19:12:06 +02:00
from chainlib.eth.tx import TxFactory
from chainlib.eth.tx import TxFormat
from chainlib.eth.contract import ABIContractEncoder
from chainlib.eth.contract import ABIContractType
from cic_contracts.unittest import bytecode
2023-06-09 10:44:03 +02:00
from cic_contracts import Name
# local imports
from eth_writer import EthWriter
2023-06-06 19:12:06 +02:00
script_dir = os.path.dirname(os.path.realpath(__file__))
contract_dir = os.path.join(script_dir, '..', '..', 'solidity')
2023-06-06 19:12:06 +02:00
logg = logging.getLogger(__name__)
2023-06-06 19:12:06 +02:00
class TestEthWriter(EthTesterCase):
2023-06-06 19:12:06 +02:00
def setUp(self):
super(TestEthWriter, self).setUp()
2023-06-06 19:12:06 +02:00
self.set_method = None
2023-06-06 19:12:06 +02:00
self.conn = RPCConnection.connect(self.chain_spec, 'default')
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
2023-06-09 10:44:03 +02:00
code = bytecode(Name.WRITER)
2023-06-06 19:12:06 +02:00
txf = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
tx = txf.template(self.accounts[0], None, use_nonce=True)
tx = txf.set_code(tx, code)
(tx_hash_hex, o) = txf.build(tx)
self.conn.do(o)
o = receipt(tx_hash_hex)
r = self.conn.do(o)
self.assertEqual(r['status'], 1)
self.address = r['contract_address']
self.contracts['writer'] = self.address
self.roles['publisher'] = self.accounts[0]
self.roles['writer'] = self.accounts[1]
logg.debug('published writer test contract with hash {}'.format(r))
2023-06-06 19:12:06 +02:00
c = EthWriter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash, o) = c.add_writer(self.address, self.accounts[0], self.accounts[0])
self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)