Add agnostic processing unit, outputter
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import random
|
||||
import os
|
||||
import logging
|
||||
import tempfile
|
||||
|
||||
# external imports
|
||||
from chainlib.chain import ChainSpec
|
||||
@@ -24,6 +25,9 @@ from okota.token_index.index import TokenUniqueSymbolIndexAddressDeclarator
|
||||
from cic.ext.eth import CICEth
|
||||
from cic import Proof
|
||||
from cic.attachment import Attachment
|
||||
from cic.output import KVWriter
|
||||
from cic.processor import Processor
|
||||
|
||||
|
||||
# test imports
|
||||
from tests.base_cic import test_data_dir
|
||||
@@ -38,6 +42,9 @@ class TestCICEthBase(EthTesterCase):
|
||||
random.seed(42)
|
||||
self.initial_description = add_0x(random.randbytes(32).hex())
|
||||
self.token_address = add_0x(random.randbytes(20).hex())
|
||||
d = tempfile.mkdtemp()
|
||||
self.outputs_writer = KVWriter(d)
|
||||
self.core_processor = Processor(self.token_address, outputs_writer=self.outputs_writer)
|
||||
|
||||
addresses = self.keystore.list()
|
||||
|
||||
@@ -91,7 +98,7 @@ class TestCICEthTokenBase(TestCICEthBase):
|
||||
def setUp(self):
|
||||
super(TestCICEthTokenBase, self).setUp()
|
||||
self.resources['token']['reference'] = None
|
||||
self.adapter = CICEth(self.chain_spec, self.resources, self.proofs)
|
||||
self.adapter = CICEth(self.core_processor, self.chain_spec, self.resources, self.proofs)
|
||||
self.token_name = 'FOotoken'
|
||||
self.token_symbol = 'FOO'
|
||||
self.token_precision = 8
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import logging
|
||||
import random
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.nonce import (
|
||||
@@ -15,10 +16,14 @@ from chainlib.eth.tx import (
|
||||
TxFormat,
|
||||
unpack,
|
||||
receipt,
|
||||
Tx,
|
||||
)
|
||||
from hexathon import (
|
||||
strip_0x,
|
||||
add_0x,
|
||||
)
|
||||
from hexathon import strip_0x
|
||||
from giftable_erc20_token import GiftableToken
|
||||
from eth_token_index import TokenUniqueSymbolIndex
|
||||
from giftable_erc20_token import GiftableToken
|
||||
|
||||
# local imports
|
||||
from cic.ext.eth import CICEth
|
||||
@@ -37,10 +42,26 @@ class TestCICEthRPC(TestCICEthTokenBase):
|
||||
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, fee_oracle=gas_oracle)
|
||||
self.adapter = CICEth(self.core_processor, self.chain_spec, self.resources, self.proofs, signer=self.signer, rpc=self.rpc, fee_oracle=gas_oracle)
|
||||
|
||||
|
||||
def test_rpc_process_notoken(self):
|
||||
addresses = self.keystore.list()
|
||||
nonce_oracle = RPCNonceOracle(addresses[0], self.rpc)
|
||||
gas_oracle = OverrideGasOracle(limit=GiftableToken.gas(), conn=self.rpc)
|
||||
c = GiftableToken(self.chain_spec, self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(addresses[0], self.token_name, self.token_symbol, self.token_precision)
|
||||
r = self.rpc.do(o)
|
||||
o = receipt(r)
|
||||
r = self.rpc.do(o)
|
||||
Tx.src_normalize(r)
|
||||
self.assertEqual(r['status'], 1)
|
||||
token_address = r['contract_address']
|
||||
self.adapter.resources['token']['reference'] = token_address
|
||||
|
||||
self.token_index_address = r['contract_address']
|
||||
logg.debug('token index deployed at {}'.format(self.token_index_address))
|
||||
|
||||
results = self.adapter.process()
|
||||
for hsh in results:
|
||||
logg.debug('hsh {}'.format(hsh))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
# local imports
|
||||
from cic.ext.eth import CICEth
|
||||
@@ -7,11 +8,15 @@ from cic.ext.eth import CICEth
|
||||
# tests imports
|
||||
from tests.eth.base_eth import TestCICEthBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class TestCICEthOffline(TestCICEthBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCICEthOffline, self).setUp()
|
||||
self.adapter = CICEth(self.chain_spec, self.resources, self.proofs)
|
||||
self.adapter = CICEth(self.core_processor, self.chain_spec, self.resources, self.proofs)
|
||||
|
||||
|
||||
def test_offline_token_index(self):
|
||||
|
||||
@@ -27,14 +27,15 @@ class TestCICEthRPC(TestCICEthBase):
|
||||
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)
|
||||
self.adapter = CICEth(self.core_processor, self.chain_spec, self.resources, self.proofs, signer=self.signer, rpc=self.rpc, fee_oracle=gas_oracle)
|
||||
|
||||
|
||||
@unittest.skip('test does not make sense anymore because nonces will be different')
|
||||
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 = CICEth(self.core_processor, self.chain_spec, self.resources, self.proofs, signer=self.signer)
|
||||
adapter_norpc.token_address = self.token_address
|
||||
vv = adapter_norpc.process_token_index()
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class TestCICEthSign(TestCICEthBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCICEthSign, self).setUp()
|
||||
self.adapter = CICEth(self.chain_spec, self.resources, self.proofs, signer=self.signer)
|
||||
self.adapter = CICEth(self.core_processor, self.chain_spec, self.resources, self.proofs, signer=self.signer)
|
||||
|
||||
|
||||
def test_sign_token_index(self):
|
||||
|
||||
@@ -22,7 +22,7 @@ from eth_erc20 import ERC20
|
||||
from cic.ext.eth import CICEth
|
||||
|
||||
# tests imports
|
||||
from tests.eth.base_eth import TestCICEthBase
|
||||
from tests.eth.base_eth import TestCICEthTokenBase
|
||||
from tests.base_cic import test_data_dir
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
@@ -31,7 +31,6 @@ logg = logging.getLogger()
|
||||
|
||||
class TestCICEthToken(TestCICEthTokenBase):
|
||||
|
||||
|
||||
def test_token_nobackend(self):
|
||||
self.adapter.prepare_token(self.token_name, self.token_symbol, self.token_precision, GiftableToken.bytecode())
|
||||
v = self.adapter.process_token()
|
||||
|
||||
Reference in New Issue
Block a user