eth-address-index/python/eth_address_declarator/unittest/addressdeclarator.py

48 lines
1.6 KiB
Python
Raw Normal View History

# standard imports
import unittest
import logging
import os
# external imports
from hexathon import add_0x
from chainlib.eth.unittest.ethtester import EthTesterCase
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import receipt
from giftable_erc20_token import GiftableToken
# local imports
from eth_address_declarator.declarator import AddressDeclarator
2023-03-24 09:55:59 +01:00
from eth_address_declarator.kv import AddressDeclaratorKV
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
class TestAddressDeclaratorBase(EthTesterCase):
def setUp(self):
super(TestAddressDeclaratorBase, self).setUp()
self.description = add_0x(os.urandom(32).hex())
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = AddressDeclarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash_hex, o) = c.constructor(self.accounts[0], self.description)
self.rpc.do(o)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
self.address = r['contract_address']
2023-03-24 09:55:59 +01:00
logg.debug('address declarator published with address {}'.format(self.address))
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash_hex, o) = c.constructor(self.accounts[0], 'FooToken', 'FOO', 6)
self.rpc.do(o)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
self.foo_token_address = r['contract_address']
2023-03-24 09:55:59 +01:00
logg.debug('foo token published with address {}'.format(self.foo_token_address))