Add writer to token index deploy in eth tests
This commit is contained in:
parent
b85390fc36
commit
69a0aea7ed
@ -4,6 +4,11 @@ from chainlib.eth.connection import RPCConnection
|
||||
|
||||
|
||||
def extension_start(network, *args, **kwargs):
|
||||
"""Called by the "export" cli tool subcommand for initialization of the eth extension.
|
||||
|
||||
:param network: Network object to read and write settings from
|
||||
:type network: cic.network.Network
|
||||
"""
|
||||
CICRegistry.address = kwargs['registry_address']
|
||||
|
||||
RPCConnection.register_location(kwargs['rpc_provider'], kwargs['chain_spec'])
|
||||
|
@ -16,7 +16,15 @@ logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Network(Data):
|
||||
"""Contains network settings for token deployments across extensions.
|
||||
|
||||
Extension targets are defined by the keys immediately following the "resources" key in the network settings file.
|
||||
|
||||
:param path: Path to settings directory
|
||||
:type path: str
|
||||
:param targets: Extension targets to execute
|
||||
:type targets: list of str
|
||||
"""
|
||||
def __init__(self, path='.', targets=[]):
|
||||
super(Network, self).__init__()
|
||||
self.resources = None
|
||||
@ -26,6 +34,8 @@ class Network(Data):
|
||||
|
||||
|
||||
def load(self):
|
||||
"""Load network settings from file.
|
||||
"""
|
||||
super(Network, self).load()
|
||||
|
||||
f = open(self.network_path, 'r')
|
||||
@ -38,6 +48,10 @@ class Network(Data):
|
||||
|
||||
|
||||
def start(self):
|
||||
"""Initialize network settings with targets chosen at object instantiation.
|
||||
|
||||
Will save to network settings file.
|
||||
"""
|
||||
super(Network, self).load()
|
||||
|
||||
network_template_file_path = os.path.join(data_dir, 'network_template_v{}.json'.format(self.version()))
|
||||
@ -54,6 +68,8 @@ class Network(Data):
|
||||
|
||||
|
||||
def save(self):
|
||||
"""Save network settings to file.
|
||||
"""
|
||||
f = open(self.network_path, 'w')
|
||||
json.dump({
|
||||
'resources': self.resources,
|
||||
@ -62,6 +78,13 @@ class Network(Data):
|
||||
|
||||
|
||||
def resource(self, k):
|
||||
"""Get settings definitions for a given extension.
|
||||
|
||||
:param k: Extension key
|
||||
:type k: str
|
||||
:rtype: dict
|
||||
:return: Extension settings
|
||||
"""
|
||||
v = self.resources.get(k)
|
||||
if v == None:
|
||||
raise AttributeError('no defined reference for {}'.format(k))
|
||||
@ -69,16 +92,44 @@ class Network(Data):
|
||||
|
||||
|
||||
def resource_set(self, resource_key, content_key, reference, key_account=None):
|
||||
"""Set the values a content part of an extension setting.
|
||||
|
||||
The content parts define network application resources. Each entry is keyed by the name of the application. Each value consists of a key_account used to write/deploy to the contract, and the reference (address) of the application resource. If no application resource yet exists on the network for the part, the reference value will be None.
|
||||
|
||||
:param resource_key: Extension key
|
||||
:type resource_key: str
|
||||
:param content_key: Resource name (e.g. smart contract name)
|
||||
:type content_key: str
|
||||
:param reference: Reference to resource on network (e.g. smart contract address)
|
||||
:type reference: str
|
||||
:param key_account: Address of account to sign transaction for the resource with
|
||||
:type key_account: str
|
||||
|
||||
"""
|
||||
self.resources[resource_key]['contents'][content_key]['reference'] = reference
|
||||
self.resources[resource_key]['contents'][content_key]['key_account'] = key_account
|
||||
|
||||
|
||||
def chain_spec(self, k):
|
||||
"""Retrieve chain spec for the given extension
|
||||
|
||||
:param k: Extension key
|
||||
:type k: str
|
||||
:rtype: chainlib.chain.ChainSpec
|
||||
:return: Chain spec object
|
||||
"""
|
||||
v = self.resource(k)
|
||||
return ChainSpec.from_dict(v['chain_spec'])
|
||||
|
||||
|
||||
def set(self, resource_key, chain_spec):
|
||||
"""Set chain spec for resource.
|
||||
|
||||
:param resource_key: Extension key
|
||||
:type resource_key: str
|
||||
:param chain_spec: Chain spec to set
|
||||
:type chain_spec: chainlib.chain.ChainSpec
|
||||
"""
|
||||
chain_spec_dict = chain_spec.asdict()
|
||||
for k in chain_spec_dict.keys():
|
||||
logg.debug('resources {}'.format(self.resources))
|
||||
|
@ -1,6 +1,7 @@
|
||||
chainlib-eth~=0.0.12
|
||||
chainlib-eth~=0.0.13
|
||||
funga-eth~=0.5.1
|
||||
eth-token-index~=0.2.4
|
||||
eth-address-index~=0.2.4
|
||||
okota~=0.2.5a1
|
||||
cic_eth_registry~=0.6.2
|
||||
cic_contracts~=0.0.5
|
||||
|
@ -1,5 +1,5 @@
|
||||
funga-eth~=0.5.1
|
||||
cic-types~=0.2.1a5
|
||||
confini~=0.5.1
|
||||
chainlib~=0.0.12
|
||||
chainlib~=0.0.13
|
||||
cbor2==5.4.1
|
||||
|
@ -20,6 +20,7 @@ from hexathon import (
|
||||
from funga.eth.keystore.dict import DictKeystore
|
||||
from eth_address_declarator.declarator import AddressDeclarator
|
||||
from okota.token_index.index import TokenUniqueSymbolIndexAddressDeclarator
|
||||
from cic_contracts.writer import CICWriter
|
||||
|
||||
# local imports
|
||||
from cic.ext.eth import CICEth
|
||||
@ -69,6 +70,14 @@ class TestCICEthBase(EthTesterCase):
|
||||
self.token_index_address = r['contract_address']
|
||||
logg.debug('token index deployed at {}'.format(self.token_index_address))
|
||||
|
||||
c = CICWriter(self.chain_spec, self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
(tx_hash_hex, o) = c.add_writer(self.token_index_address, addresses[1], addresses[1])
|
||||
r = self.rpc.do(o)
|
||||
o = receipt(r)
|
||||
r = self.rpc.do(o)
|
||||
Tx.src_normalize(r)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
self.resources = {
|
||||
'token': {
|
||||
'reference': self.token_address,
|
||||
|
@ -72,6 +72,7 @@ class TestCICEthRPC(TestCICEthTokenBase):
|
||||
self.adapter.process()
|
||||
results = self.adapter.get_outputs()
|
||||
for v in results:
|
||||
logg.debug('checking result for {}'.format(v[0]))
|
||||
o = receipt(v[1])
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
Loading…
Reference in New Issue
Block a user