Add render token index test

This commit is contained in:
nolash 2021-10-10 12:50:18 +02:00
parent 16308f736e
commit 9bdf9db32a
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 88 additions and 5 deletions

View File

@ -2,22 +2,55 @@
import logging
# external imports
from chainlib.chain import ChainSpec
from chainlib.eth.tx import TxFormat
from chainlib.eth.connection import RPCConnection
from eth_token_index import TokenUniqueSymbolIndex
logg = logging.getLogger(__name__)
class CICEth:
def __init__(self, resources, proofs, signer_hint=None):
def __init__(self, chain_spec, resources, proofs, signer=None, rpc=None, nonce_oracle=None, fee_oracle=None):
self.resources = resources
self.proofs = proofs
self.signer_hint = signer_hint
self.chain_spec = chain_spec
self.signer = signer
self.rpc = rpc
self.nonce_oracle = nonce_oracle
self.fee_oracle = fee_oracle
self.token_address = None
self.outputs = {}
for k in resources.keys():
self.outputs[k] = None
def token_index(self):
pass
def process_token(self):
raise NotImplementedError
def process_token_index(self):
c = TokenUniqueSymbolIndex(self.chain_spec) # tx_format = None
if self.signer == None:
tx_format = TxFormat.RAW_ARGS
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
def process(self):
self.token_address = self.resources['token']['reference']
if self.token_address == None:
tasks.append('token')
tasks.append('token_index')
for task in tasks:
getattr(self, 'process_̈́ ' + task)()
def new(resources, proofs, signer_hint=None):
return CICEth(resources, proofs, signer_hint=None)
return CICEth(resources, proofs, signer=None)

View File

@ -12,6 +12,7 @@ from funga.keystore import Keystore
logg = logging.getLogger(__name__)
class KeystoreDirectory(Keystore):
def process_dir(self, path, password_retriever=None, default_password=''):

View File

@ -0,0 +1,49 @@
# standard imports
import unittest
import logging
import random
# external imports
from chainlib.chain import ChainSpec
from hexathon import (
add_0x,
strip_0x,
)
# local imports
from cic.ext.eth import CICEth
logg = logging.getLogger(__name__)
class TestCICEth(unittest.TestCase):
def setUp(self):
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())
self.resources = {
'token': {
'reference': self.token_address,
'key_address': None,
},
'token_index': {
'reference': self.token_index_address,
'key_address': None,
},
}
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()