mirror of
git://holbrook.no/eth-address-index
synced 2026-04-27 03:07:14 +02:00
Add test for address index for declarator implementation
This commit is contained in:
70
python/tests/test_accounts_index.py
Normal file
70
python/tests/test_accounts_index.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import logging
|
||||
import hashlib
|
||||
|
||||
# external imports
|
||||
from tests.test_addressdeclarator_base import TestBase
|
||||
from eth_accounts_index import AccountsIndex
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from giftable_erc20_token import GiftableToken
|
||||
from chainlib.eth.tx import receipt
|
||||
from chainlib.eth.contract import ABIContractEncoder
|
||||
|
||||
# local imports
|
||||
from eth_address_declarator.accounts_index import AccountsIndexAddressDeclarator
|
||||
from eth_address_declarator import Declarator
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class TestAccountsIndex(TestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAccountsIndex, self).setUp()
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
|
||||
c = AccountsIndexAddressDeclarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0], self.foo_token_address, self.address)
|
||||
r = self.rpc.do(o)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
self.accounts_index_address = r['contract_address']
|
||||
logg.debug('accounts index deployed with address {}'.format(self.accounts_index_address))
|
||||
|
||||
|
||||
def test_accounts_index_address_declarator(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash, o) = c.add(self.accounts_index_address, self.accounts[0], self.accounts[1])
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(tx_hash, r)
|
||||
|
||||
o = receipt(tx_hash)
|
||||
rcpt = self.rpc.do(o)
|
||||
|
||||
self.helper.mine_block()
|
||||
o = c.have(self.accounts_index_address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
|
||||
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
o = c.declaration(self.address, self.accounts[0], self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
proofs = c.parse_declaration(r)
|
||||
|
||||
enc = ABIContractEncoder()
|
||||
enc.address(self.foo_token_address)
|
||||
token_address_padded = enc.get()
|
||||
logg.debug('proof {} {}'.format(proofs, token_address_padded))
|
||||
h = hashlib.sha256()
|
||||
h.update(bytes.fromhex(token_address_padded))
|
||||
r = h.digest()
|
||||
self.assertEqual(r.hex(), proofs[0])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -14,51 +14,31 @@ from chainlib.eth.contract import (
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from chainlib.eth.tx import receipt
|
||||
from giftable_erc20_token import GiftableToken
|
||||
from hexathon import add_0x
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from eth_address_declarator.declarator import AddressDeclarator
|
||||
from eth_address_declarator import Declarator
|
||||
from tests.test_addressdeclarator_base import TestBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
logging.getLogger('web3').setLevel(logging.WARNING)
|
||||
logging.getLogger('eth.vm').setLevel(logging.WARNING)
|
||||
|
||||
testdir = os.path.dirname(__file__)
|
||||
|
||||
description = '0x{:<064s}'.format(b'foo'.hex())
|
||||
|
||||
class Test(EthTesterCase):
|
||||
|
||||
class TestAddressDeclarator(TestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(Test, self).setUp()
|
||||
self.description = add_0x(os.urandom(32).hex())
|
||||
super(TestAddressDeclarator, self).setUp()
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
#c = AddressDeclarator(signer=self.signer, nonce_oracle=nonce_oracle, chain_id=self.chain_spec.chain_id())
|
||||
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']
|
||||
|
||||
#c = GiftableToken(signer=self.signer, nonce_oracle=nonce_oracle, chain_id=self.chain_spec.chain_id())
|
||||
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']
|
||||
|
||||
#c = GiftableToken(signer=self.signer, nonce_oracle=nonce_oracle, chain_id=self.chain_spec.chain_id())
|
||||
#c = GiftableToken(signer=self.signer, nonce_oracle=nonce_oracle, chain_id=self.chain_spec.chain_id())
|
||||
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0], 'BarToken', 'BAR', 6)
|
||||
self.rpc.do(o)
|
||||
@@ -98,6 +78,23 @@ class Test(EthTesterCase):
|
||||
self.assertEqual(c.parse_declarator_count(r), 1)
|
||||
|
||||
|
||||
def test_get_single_declaration(self):
|
||||
d = add_0x(os.urandom(32).hex())
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
|
||||
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[1], self.foo_token_address, d)
|
||||
self.rpc.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
o = c.declaration(self.address, self.accounts[1], self.foo_token_address, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
proofs = c.parse_declaration(r)
|
||||
self.assertEqual(proofs[0], strip_0x(d))
|
||||
|
||||
|
||||
def test_declaration(self):
|
||||
|
||||
d = add_0x(os.urandom(32).hex())
|
||||
@@ -124,11 +121,10 @@ class Test(EthTesterCase):
|
||||
o = c.declaration(self.address, self.accounts[1], self.foo_token_address, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
proofs = c.parse_declaration(r)
|
||||
self.assertEqual(proofs[0], d[2:])
|
||||
self.assertEqual(proofs[1], d_two[2:])
|
||||
self.assertEqual(proofs[0], strip_0x(d))
|
||||
self.assertEqual(proofs[1], strip_0x(d_two))
|
||||
|
||||
|
||||
|
||||
def test_declarator_to_subject(self):
|
||||
d = add_0x(os.urandom(32).hex())
|
||||
|
||||
|
||||
46
python/tests/test_addressdeclarator_base.py
Normal file
46
python/tests/test_addressdeclarator_base.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# 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
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class TestBase(EthTesterCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBase, 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']
|
||||
logg.debug('address declarator deployed 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']
|
||||
logg.debug('foo token deployed with address {}'.format(self.foo_token_address))
|
||||
Reference in New Issue
Block a user