diff --git a/cic/ext/eth/__init__.py b/cic/ext/eth/__init__.py index 9c21b72..ddca1e6 100644 --- a/cic/ext/eth/__init__.py +++ b/cic/ext/eth/__init__.py @@ -24,7 +24,9 @@ class CICEth: self.outputs = {} for k in resources.keys(): self.outputs[k] = None - + self.tx_format = TxFormat.RLP_SIGNED + if self.signer == None: + self.tx_format = TxFormat.RAW_ARGS def process_token(self): @@ -32,15 +34,17 @@ class CICEth: def process_token_index(self): - c = TokenUniqueSymbolIndex(self.chain_spec) # tx_format = None - if self.signer == None: - tx_format = TxFormat.RAW_ARGS + c = TokenUniqueSymbolIndex(self.chain_spec, signer=self.signer) # tx_format = None contract_address = self.resources['token_index']['reference'] signer_address = self.resources['token_index']['key_address'] - o = c.register(contract_address, signer_address, self.token_address, tx_format=tx_format) - if self.rpc == None: - self.outputs['token_index'] = o + o = c.register(contract_address, signer_address, self.token_address, tx_format=self.tx_format) + if self.rpc != None: + pass + elif self.signer != None: + self.outputs['token_index'] = o[1] + else: + self.outputs['token_index'] = o def process(self): diff --git a/tests/eth/test_token_index.py b/tests/eth/base_eth.py similarity index 60% rename from tests/eth/test_token_index.py rename to tests/eth/base_eth.py index ca74780..0603e41 100644 --- a/tests/eth/test_token_index.py +++ b/tests/eth/base_eth.py @@ -5,10 +5,12 @@ import random # external imports from chainlib.chain import ChainSpec +from chainlib.eth.unittest.ethtester import EthTesterCase from hexathon import ( add_0x, strip_0x, ) +from funga.eth.keystore.dict import DictKeystore # local imports from cic.ext.eth import CICEth @@ -16,34 +18,26 @@ from cic.ext.eth import CICEth logg = logging.getLogger(__name__) -class TestCICEth(unittest.TestCase): +class TestCICEthBase(EthTesterCase): def setUp(self): + super(TestCICEthBase, self).setUp() random.seed(42) - self.chain_spec = ChainSpec.from_chain_str('evm:foo:42') self.token_address = add_0x(random.randbytes(20).hex()) self.token_index_address = add_0x(random.randbytes(20).hex()) + addresses = self.keystore.list() self.resources = { 'token': { 'reference': self.token_address, - 'key_address': None, + 'key_address': addresses[0], }, 'token_index': { 'reference': self.token_index_address, - 'key_address': None, + 'key_address': addresses[1], }, } self.proofs = [] for i in range(3): self.proofs.append(random.randbytes(32).hex()) - self.adapter = CICEth(self.chain_spec, self.resources, self.proofs) - def test_offline_token_index(self): - self.adapter.token_address = self.token_address - v = self.adapter.process_token_index() - self.assertEqual(self.adapter.outputs['token_index'][:8], '4420e486') - - -if __name__ == '__main__': - unittest.main() diff --git a/tests/eth/test_eth_offline.py b/tests/eth/test_eth_offline.py new file mode 100644 index 0000000..29e0402 --- /dev/null +++ b/tests/eth/test_eth_offline.py @@ -0,0 +1,24 @@ +# standard imports +import unittest + +# local imports +from cic.ext.eth import CICEth + +# tests imports +from tests.eth.base_eth import TestCICEthBase + +class TestCICEthOffline(TestCICEthBase): + + def setUp(self): + super(TestCICEthOffline, self).setUp() + self.adapter = CICEth(self.chain_spec, self.resources, self.proofs) + + + def test_offline_token_index(self): + self.adapter.token_address = self.token_address + v = self.adapter.process_token_index() + self.assertEqual(self.adapter.outputs['token_index'][:8], '4420e486') + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/eth/test_eth_sign.py b/tests/eth/test_eth_sign.py new file mode 100644 index 0000000..af99f85 --- /dev/null +++ b/tests/eth/test_eth_sign.py @@ -0,0 +1,34 @@ +# standard imports +import unittest + +# external imports +from chainlib.eth.tx import unpack +from hexathon import ( + strip_0x, + add_0x, + ) + +# local imports +from cic.ext.eth import CICEth + +# tests imports +from tests.eth.base_eth import TestCICEthBase + +class TestCICEthSign(TestCICEthBase): + + def setUp(self): + 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) + + + def test_sign_token_index(self): + self.adapter.token_address = self.token_address + v = self.adapter.process_token_index() + tx_raw = bytes.fromhex(strip_0x(self.adapter.outputs['token_index'])) + tx = unpack(tx_raw, self.chain_spec) + self.assertEqual(strip_0x(tx['data'])[:8], '4420e486') + + +if __name__ == '__main__': + unittest.main()