Add signer test for ciceth
This commit is contained in:
parent
9bdf9db32a
commit
fe6950016c
@ -24,7 +24,9 @@ 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
|
||||||
|
|
||||||
|
|
||||||
def process_token(self):
|
def process_token(self):
|
||||||
@ -32,15 +34,17 @@ class CICEth:
|
|||||||
|
|
||||||
|
|
||||||
def process_token_index(self):
|
def process_token_index(self):
|
||||||
c = TokenUniqueSymbolIndex(self.chain_spec) # tx_format = None
|
c = TokenUniqueSymbolIndex(self.chain_spec, signer=self.signer) # tx_format = None
|
||||||
if self.signer == None:
|
|
||||||
tx_format = TxFormat.RAW_ARGS
|
|
||||||
|
|
||||||
contract_address = self.resources['token_index']['reference']
|
contract_address = self.resources['token_index']['reference']
|
||||||
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=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:
|
||||||
self.outputs['token_index'] = o
|
pass
|
||||||
|
elif self.signer != None:
|
||||||
|
self.outputs['token_index'] = o[1]
|
||||||
|
else:
|
||||||
|
self.outputs['token_index'] = o
|
||||||
|
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
|
@ -5,10 +5,12 @@ import random
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
|
from chainlib.eth.unittest.ethtester import EthTesterCase
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
)
|
)
|
||||||
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic.ext.eth import CICEth
|
from cic.ext.eth import CICEth
|
||||||
@ -16,34 +18,26 @@ from cic.ext.eth import CICEth
|
|||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TestCICEth(unittest.TestCase):
|
class TestCICEthBase(EthTesterCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(TestCICEthBase, self).setUp()
|
||||||
random.seed(42)
|
random.seed(42)
|
||||||
self.chain_spec = ChainSpec.from_chain_str('evm:foo:42')
|
|
||||||
self.token_address = add_0x(random.randbytes(20).hex())
|
self.token_address = add_0x(random.randbytes(20).hex())
|
||||||
self.token_index_address = add_0x(random.randbytes(20).hex())
|
self.token_index_address = add_0x(random.randbytes(20).hex())
|
||||||
|
addresses = self.keystore.list()
|
||||||
self.resources = {
|
self.resources = {
|
||||||
'token': {
|
'token': {
|
||||||
'reference': self.token_address,
|
'reference': self.token_address,
|
||||||
'key_address': None,
|
'key_address': addresses[0],
|
||||||
},
|
},
|
||||||
'token_index': {
|
'token_index': {
|
||||||
'reference': self.token_index_address,
|
'reference': self.token_index_address,
|
||||||
'key_address': None,
|
'key_address': addresses[1],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
self.proofs = []
|
self.proofs = []
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
self.proofs.append(random.randbytes(32).hex())
|
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()
|
|
24
tests/eth/test_eth_offline.py
Normal file
24
tests/eth/test_eth_offline.py
Normal file
@ -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()
|
34
tests/eth/test_eth_sign.py
Normal file
34
tests/eth/test_eth_sign.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user