Add ciceth rpc tests

This commit is contained in:
nolash 2021-10-10 13:48:32 +02:00
parent fe6950016c
commit 33f173f0c9
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 82 additions and 6 deletions

View File

@ -1,5 +1,6 @@
# standard imports # standard imports
import logging import logging
import copy
# external imports # external imports
from chainlib.chain import ChainSpec from chainlib.chain import ChainSpec
@ -13,6 +14,8 @@ logg = logging.getLogger(__name__)
class CICEth: class CICEth:
def __init__(self, chain_spec, resources, proofs, signer=None, rpc=None, nonce_oracle=None, fee_oracle=None): def __init__(self, chain_spec, resources, proofs, signer=None, rpc=None, nonce_oracle=None, fee_oracle=None):
"""resources will be modified
"""
self.resources = resources self.resources = resources
self.proofs = proofs self.proofs = proofs
self.chain_spec = chain_spec self.chain_spec = chain_spec
@ -24,9 +27,11 @@ class CICEth:
self.outputs = {} self.outputs = {}
for k in resources.keys(): for k in resources.keys():
self.outputs[k] = None self.outputs[k] = None
self.tx_format = TxFormat.RLP_SIGNED
if self.signer == None:
self.tx_format = TxFormat.RAW_ARGS self.tx_format = TxFormat.RAW_ARGS
if self.rpc != None:
self.tx_format = TxFormat.JSONRPC
elif self.signer != None:
self.tx_format = TxFormat.RLP_SIGNED
def process_token(self): def process_token(self):
@ -40,12 +45,15 @@ class CICEth:
signer_address = self.resources['token_index']['key_address'] signer_address = self.resources['token_index']['key_address']
o = c.register(contract_address, signer_address, self.token_address, tx_format=self.tx_format) o = c.register(contract_address, signer_address, self.token_address, tx_format=self.tx_format)
if self.rpc != None: if self.rpc != None:
pass r = self.rpc.do(o[1])
self.outputs['token_index'] = r
elif self.signer != None: elif self.signer != None:
self.outputs['token_index'] = o[1] self.outputs['token_index'] = o[1]
else: else:
self.outputs['token_index'] = o self.outputs['token_index'] = o
return self.outputs['token_index']
def process(self): def process(self):
self.token_address = self.resources['token']['reference'] self.token_address = self.resources['token']['reference']

17
run_tests.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
set -a
set -e
set -x
default_pythonpath=$PYTHONPATH:.
export PYTHONPATH=${default_pythonpath:-.}
>&2 echo using pythonpath $PYTHONPATH
for f in `ls tests/*.py`; do
python $f
done
for f in `ls tests/eth/*.py`; do
python $f
done
set +x
set +e
set +a

47
tests/eth/test_eth_rpc.py Normal file
View File

@ -0,0 +1,47 @@
# standard imports
import unittest
import logging
# external imports
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.gas import RPCGasOracle
from chainlib.eth.tx import (
TxFormat,
unpack,
)
from hexathon import strip_0x
# local imports
from cic.ext.eth import CICEth
# test imports
from tests.eth.base_eth import TestCICEthBase
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
class TestCICEthRPC(TestCICEthBase):
def setUp(self):
super(TestCICEthRPC, self).setUp()
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
gas_oracle = RPCGasOracle(self.rpc)
self.adapter = CICEth(self.chain_spec, self.resources, self.proofs, signer=self.signer, rpc=self.rpc, nonce_oracle=nonce_oracle, fee_oracle=gas_oracle)
def test_rpc_token_index(self):
self.adapter.token_address = self.token_address
v = self.adapter.process_token_index()
adapter_norpc = CICEth(self.chain_spec, self.resources, self.proofs, signer=self.signer)
adapter_norpc.token_address = self.token_address
vv = adapter_norpc.process_token_index()
tx_raw = bytes.fromhex(strip_0x(adapter_norpc.outputs['token_index']))
tx = unpack(tx_raw, self.chain_spec)
self.assertEqual(strip_0x(tx['hash']), strip_0x(v))
if __name__ == '__main__':
unittest.main()

View File

@ -1,5 +1,6 @@
# standard imports # standard imports
import unittest import unittest
import logging
# external imports # external imports
from chainlib.eth.tx import unpack from chainlib.eth.tx import unpack
@ -14,11 +15,14 @@ from cic.ext.eth import CICEth
# tests imports # tests imports
from tests.eth.base_eth import TestCICEthBase from tests.eth.base_eth import TestCICEthBase
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
class TestCICEthSign(TestCICEthBase): class TestCICEthSign(TestCICEthBase):
def setUp(self): def setUp(self):
super(TestCICEthSign, self).setUp() super(TestCICEthSign, self).setUp()
#self.adapter = CICEth(self.chain_spec, self.resources, self.proofs, signer=self.signer, rpc=self.rpc)
self.adapter = CICEth(self.chain_spec, self.resources, self.proofs, signer=self.signer) self.adapter = CICEth(self.chain_spec, self.resources, self.proofs, signer=self.signer)