mirror of
git://holbrook.no/eth-address-index
synced 2024-12-02 12:36:49 +01:00
Factor out eth-token-index
This commit is contained in:
parent
c3c948e9e3
commit
bf2e204eea
@ -26,9 +26,7 @@ python_requires = >= 3.6
|
|||||||
packages =
|
packages =
|
||||||
eth_address_declarator
|
eth_address_declarator
|
||||||
eth_address_declarator.runnable
|
eth_address_declarator.runnable
|
||||||
eth_token_index
|
eth_address_declarator.unittest
|
||||||
eth_token_index.runnable
|
|
||||||
eth_token_index.unittest
|
|
||||||
|
|
||||||
[options.extras_require]
|
[options.extras_require]
|
||||||
testing =
|
testing =
|
||||||
@ -39,16 +37,9 @@ testing =
|
|||||||
* =
|
* =
|
||||||
data/AddressDeclarator.json
|
data/AddressDeclarator.json
|
||||||
data/AddressDeclarator.bin
|
data/AddressDeclarator.bin
|
||||||
data/GiftableToken.bin
|
|
||||||
data/GifttableToken.json
|
|
||||||
data/TokenUniqueSymbolIndex.bin
|
|
||||||
data/TokenUniqueSymbolIndex.json
|
|
||||||
data/ERC20.json
|
data/ERC20.json
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
eth-address-declarator-deploy = eth_address_declarator.runnable.deploy:main
|
eth-address-declarator-deploy = eth_address_declarator.runnable.deploy:main
|
||||||
eth-address-declarator-add = eth_address_declarator.runnable.add:main
|
eth-address-declarator-add = eth_address_declarator.runnable.add:main
|
||||||
eth-token-index-deploy = eth_token_index.runnable.deploy:main
|
|
||||||
eth-token-index-add = eth_token_index.runnable.add:main
|
|
||||||
eth-token-index-list = eth_token_index.runnable.list:main
|
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
# standard imports
|
|
||||||
import unittest
|
|
||||||
import logging
|
|
||||||
import hashlib
|
|
||||||
|
|
||||||
# external imports
|
|
||||||
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
|
|
||||||
|
|
||||||
# test imports
|
|
||||||
from tests.test_addressdeclarator_base import TestBase
|
|
||||||
|
|
||||||
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()
|
|
@ -1,87 +0,0 @@
|
|||||||
# standard imports
|
|
||||||
import os
|
|
||||||
import unittest
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
import hashlib
|
|
||||||
|
|
||||||
# external imports
|
|
||||||
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
|
|
||||||
from chainlib.eth.tx import unpack
|
|
||||||
from hexathon import strip_0x
|
|
||||||
from chainlib.eth.contract import ABIContractEncoder
|
|
||||||
|
|
||||||
# local imports
|
|
||||||
from eth_address_declarator.token_index.index import (
|
|
||||||
TokenUniqueSymbolIndexAddressDeclarator as TokenIndex,
|
|
||||||
to_identifier,
|
|
||||||
)
|
|
||||||
from eth_address_declarator import Declarator
|
|
||||||
|
|
||||||
# test imports
|
|
||||||
from tests.test_addressdeclarator_base import TestBase
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
logg = logging.getLogger()
|
|
||||||
|
|
||||||
testdir = os.path.dirname(__file__)
|
|
||||||
|
|
||||||
|
|
||||||
class TestTokenIndex(TestBase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(TestTokenIndex, self).setUp()
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
|
||||||
c = TokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
|
||||||
(tx_hash_hex, o) = c.constructor(self.accounts[0], self.address)
|
|
||||||
self.rpc.do(o)
|
|
||||||
|
|
||||||
o = receipt(tx_hash_hex)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 1)
|
|
||||||
|
|
||||||
self.token_index_address = r['contract_address']
|
|
||||||
|
|
||||||
|
|
||||||
def test_register(self):
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
|
||||||
c = TokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
|
||||||
|
|
||||||
(tx_hash_hex, o) = c.register(self.token_index_address, self.accounts[0], self.foo_token_address)
|
|
||||||
self.rpc.do(o)
|
|
||||||
e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec)
|
|
||||||
|
|
||||||
o = receipt(tx_hash_hex)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 1)
|
|
||||||
|
|
||||||
o = c.address_of(self.token_index_address, 'FOO', sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
address = c.parse_address_of(r)
|
|
||||||
self.assertEqual(address, self.foo_token_address)
|
|
||||||
|
|
||||||
o = c.entry(self.token_index_address, 0, sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
address = c.parse_entry(r)
|
|
||||||
self.assertEqual(address, self.foo_token_address)
|
|
||||||
|
|
||||||
o = c.entry_count(self.token_index_address, sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
count = c.parse_entry_count(r)
|
|
||||||
self.assertEqual(count, 1)
|
|
||||||
|
|
||||||
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
|
||||||
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
proofs = c.parse_declaration(r)
|
|
||||||
|
|
||||||
token_symbol_identifier = to_identifier('FOO')
|
|
||||||
|
|
||||||
self.assertEqual(token_symbol_identifier, proofs[0])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
Loading…
Reference in New Issue
Block a user