cic-cli/tests/eth/test_eth_full.py
2021-10-11 12:23:08 +02:00

96 lines
3.1 KiB
Python

# standard imports
import unittest
import logging
import random
# external imports
from chainlib.eth.nonce import (
RPCNonceOracle,
nonce,
)
from chainlib.eth.gas import (
RPCGasOracle,
OverrideGasOracle,
)
from chainlib.eth.tx import (
TxFormat,
unpack,
receipt,
Tx,
)
from hexathon import (
strip_0x,
add_0x,
)
from eth_token_index import TokenUniqueSymbolIndex
from giftable_erc20_token import GiftableToken
# local imports
from cic.ext.eth import CICEth
# test imports
from tests.eth.base_eth import TestCICEthTokenBase
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
class TestCICEthRPC(TestCICEthTokenBase):
def setUp(self):
super(TestCICEthRPC, self).setUp()
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
gas_oracle = RPCGasOracle(self.rpc)
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))
o = receipt(hsh)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
def test_rpc_process_withtoken(self):
self.adapter.fee_oracle = OverrideGasOracle(limit=GiftableToken.gas(), conn=self.rpc)
self.adapter.prepare_token(self.token_name, self.token_symbol, self.token_precision, GiftableToken.bytecode())
results = self.adapter.process()
for hsh in results:
logg.debug('hsh {}'.format(hsh))
o = receipt(hsh)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
o = receipt(results[0])
r = self.rpc.do(o)
token_contract_address = r['contract_address']
c = TokenUniqueSymbolIndex(self.chain_spec)
o = c.address_of(self.token_index_address, 'FOO', sender_address=self.accounts[0])
r = self.rpc.do(o)
token_contract_address_lookup = c.parse_address_of(r)
self.assertEqual(strip_0x(token_contract_address), strip_0x(token_contract_address_lookup))
if __name__ == '__main__':
unittest.main()