Rehabilitate tests
This commit is contained in:
parent
59f11e3df3
commit
732466de27
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
[{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_addressDeclaratorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"addWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressDeclaratorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
[{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_addressDeclaratorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"addWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressDeclaratorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"tokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenAddressHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||||
|
1
python/okota/data/RegistryAddressDeclarator.bin
Normal file
1
python/okota/data/RegistryAddressDeclarator.bin
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
[{"inputs":[{"internalType":"address","name":"_addressDeclaratorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressDeclaratorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"register","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"registry","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
[{"inputs":[{"internalType":"address","name":"_addressDeclaratorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"addWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressDeclaratorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"register","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"registry","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||||
|
@ -24,11 +24,12 @@ from chainlib.eth.constant import ZERO_ADDRESS
|
|||||||
from hexathon import (
|
from hexathon import (
|
||||||
add_0x,
|
add_0x,
|
||||||
)
|
)
|
||||||
|
from cic_contracts.registry import to_identifier
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from .interface import (
|
from .interface import (
|
||||||
TokenUniqueSymbolIndex,
|
#TokenUniqueSymbolIndex,
|
||||||
to_identifier,
|
CICTokenIndex,
|
||||||
)
|
)
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
@ -38,7 +39,8 @@ datadir = os.path.join(moddir, '..', 'data')
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TokenUniqueSymbolIndexAddressDeclarator(TokenUniqueSymbolIndex):
|
#class TokenUniqueSymbolIndexAddressDeclarator(TokenUniqueSymbolIndex):
|
||||||
|
class TokenUniqueSymbolIndexAddressDeclarator(CICTokenIndex):
|
||||||
|
|
||||||
__abi = None
|
__abi = None
|
||||||
__bytecode = None
|
__bytecode = None
|
||||||
|
@ -1,113 +1,18 @@
|
|||||||
# Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
# File-version: 1
|
|
||||||
# Description: Python interface to abi and bin files for faucet contracts
|
|
||||||
|
|
||||||
# standard imports
|
# standard imports
|
||||||
import logging
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from chainlib.eth.contract import (
|
|
||||||
ABIContractEncoder,
|
|
||||||
ABIContractType,
|
|
||||||
abi_decode_single,
|
|
||||||
)
|
|
||||||
from chainlib.eth.tx import (
|
|
||||||
TxFactory,
|
|
||||||
TxFormat,
|
|
||||||
)
|
|
||||||
from chainlib.jsonrpc import JSONRPCRequest
|
|
||||||
from chainlib.eth.constant import ZERO_ADDRESS
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
from hexathon import (
|
|
||||||
add_0x,
|
|
||||||
)
|
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
# local imports
|
||||||
|
from cic_contracts.accounts_index import CICAccountsIndex
|
||||||
moddir = os.path.dirname(__file__)
|
from cic_contracts.registry import CICRegistry
|
||||||
datadir = os.path.join(moddir, '..', 'data')
|
|
||||||
|
|
||||||
|
|
||||||
def to_identifier(s):
|
class CICTokenIndex(CICRegistry, CICAccountsIndex):
|
||||||
h = hashlib.new('sha256')
|
|
||||||
h.update(s.encode('utf-8'))
|
|
||||||
return h.digest().hex()
|
|
||||||
|
|
||||||
|
def address_of(self, contract_address, identifier_string, sender_address=ZERO_ADDRESS):
|
||||||
class TokenUniqueSymbolIndex(TxFactory):
|
h = hashlib.sha256()
|
||||||
|
h.update(identifier_string.encode('utf-8'))
|
||||||
def register(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
z = h.digest()
|
||||||
enc = ABIContractEncoder()
|
return super(CICTokenIndex, self).address_of_literal(contract_address, z.hex(), sender_address=sender_address)
|
||||||
enc.method('register')
|
|
||||||
enc.typ(ABIContractType.ADDRESS)
|
|
||||||
enc.address(address)
|
|
||||||
data = enc.get()
|
|
||||||
tx = self.template(sender_address, contract_address, use_nonce=True)
|
|
||||||
tx = self.set_code(tx, data)
|
|
||||||
tx = self.finalize(tx, tx_format)
|
|
||||||
return tx
|
|
||||||
|
|
||||||
|
|
||||||
def address_of(self, contract_address, token_symbol, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
||||||
j = JSONRPCRequest(id_generator)
|
|
||||||
o = j.template()
|
|
||||||
o['method'] = 'eth_call'
|
|
||||||
enc = ABIContractEncoder()
|
|
||||||
enc.method('addressOf')
|
|
||||||
enc.typ(ABIContractType.BYTES32)
|
|
||||||
token_symbol_digest = to_identifier(token_symbol)
|
|
||||||
enc.bytes32(token_symbol_digest)
|
|
||||||
data = add_0x(enc.get())
|
|
||||||
tx = self.template(sender_address, contract_address)
|
|
||||||
tx = self.set_code(tx, data)
|
|
||||||
o['params'].append(self.normalize(tx))
|
|
||||||
o = j.finalize(o)
|
|
||||||
return o
|
|
||||||
|
|
||||||
|
|
||||||
def entry(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
||||||
j = JSONRPCRequest(id_generator)
|
|
||||||
o = j.template()
|
|
||||||
o['method'] = 'eth_call'
|
|
||||||
enc = ABIContractEncoder()
|
|
||||||
enc.method('entry')
|
|
||||||
enc.typ(ABIContractType.UINT256)
|
|
||||||
enc.uint256(idx)
|
|
||||||
data = add_0x(enc.get())
|
|
||||||
tx = self.template(sender_address, contract_address)
|
|
||||||
tx = self.set_code(tx, data)
|
|
||||||
o['params'].append(self.normalize(tx))
|
|
||||||
o = j.finalize(o)
|
|
||||||
return o
|
|
||||||
|
|
||||||
|
|
||||||
def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
|
||||||
j = JSONRPCRequest(id_generator)
|
|
||||||
o = j.template()
|
|
||||||
o['method'] = 'eth_call'
|
|
||||||
enc = ABIContractEncoder()
|
|
||||||
enc.method('entryCount')
|
|
||||||
data = add_0x(enc.get())
|
|
||||||
tx = self.template(sender_address, contract_address)
|
|
||||||
tx = self.set_code(tx, data)
|
|
||||||
o['params'].append(self.normalize(tx))
|
|
||||||
o = j.finalize(o)
|
|
||||||
return o
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def parse_address_of(self, v):
|
|
||||||
return abi_decode_single(ABIContractType.ADDRESS, v)
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def parse_entry(self, v):
|
|
||||||
return abi_decode_single(ABIContractType.ADDRESS, v)
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def parse_entry_count(self, v):
|
|
||||||
return abi_decode_single(ABIContractType.UINT256, v)
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
confini>=0.3.6rc3,<0.5.0
|
confini~=0.5.1
|
||||||
crypto-dev-signer>=0.4.15rc2,<=0.4.15
|
funga-eth~=0.5.1
|
||||||
chainlib-eth>=0.0.9a13,<=0.1.0
|
chainlib-eth~=0.0.10
|
||||||
eth_erc20>=0.1.2a3,<=0.2.0
|
eth_erc20~=0.1.2
|
||||||
eth-address-index>=0.2.4a1,<=0.3.0
|
eth-address-index~=0.2.4
|
||||||
eth-accounts-index>=0.1.2a3,<=0.2.0
|
eth-accounts-index~=0.1.2
|
||||||
eth-token-index>=0.2.4a1,<=0.3.0
|
eth-token-index~=0.2.4
|
||||||
|
eth-contract-registry~=0.6.3
|
||||||
|
cic-contracts~=0.0.5
|
||||||
|
14
python/run_tests.sh
Normal file
14
python/run_tests.sh
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -a
|
||||||
|
set -e
|
||||||
|
set -x
|
||||||
|
default_pythonpath=$PYTHONPATH:.
|
||||||
|
export PYTHONPATH=${default_pythonpath:-.}
|
||||||
|
>&2 echo using pythonpath $PYTHONPATH
|
||||||
|
for f in `ls tests/*.py`; do
|
||||||
|
python $f
|
||||||
|
done
|
||||||
|
set +x
|
||||||
|
set +e
|
||||||
|
set +a
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = okota
|
name = okota
|
||||||
version = 0.2.4a14
|
version = 0.2.5a1
|
||||||
description = Registries for CIC using the eth-address-index backend
|
description = Registries for CIC using the eth-address-index backend
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
@ -14,6 +14,7 @@ from eth_address_declarator.unittest import TestAddressDeclaratorBase
|
|||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from okota.accounts_index import AccountsIndexAddressDeclarator
|
from okota.accounts_index import AccountsIndexAddressDeclarator
|
||||||
|
from eth_accounts_index.registry import AccountRegistry
|
||||||
|
|
||||||
# test imports
|
# test imports
|
||||||
|
|
||||||
@ -38,6 +39,14 @@ class TestAccountsIndex(TestAddressDeclaratorBase):
|
|||||||
self.accounts_index_address = r['contract_address']
|
self.accounts_index_address = r['contract_address']
|
||||||
logg.debug('accounts index deployed with address {}'.format(self.accounts_index_address))
|
logg.debug('accounts index deployed with address {}'.format(self.accounts_index_address))
|
||||||
|
|
||||||
|
c = AccountRegistry(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash_hex, o) = c.add_writer(self.accounts_index_address, self.accounts[0], self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
|
||||||
|
o = receipt(tx_hash_hex)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
|
||||||
def test_accounts_index_address_declarator(self):
|
def test_accounts_index_address_declarator(self):
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
@ -46,14 +55,18 @@ class TestAccountsIndex(TestAddressDeclaratorBase):
|
|||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
self.assertEqual(tx_hash, r)
|
self.assertEqual(tx_hash, r)
|
||||||
|
|
||||||
|
self.helper.mine_block()
|
||||||
|
|
||||||
o = receipt(tx_hash)
|
o = receipt(tx_hash)
|
||||||
rcpt = self.rpc.do(o)
|
rcpt = self.rpc.do(o)
|
||||||
|
self.assertEqual(rcpt['status'], 1)
|
||||||
|
for k in rcpt.keys():
|
||||||
|
logg.debug('>>> RCPT {} {}'.format(k, rcpt[k]))
|
||||||
|
|
||||||
self.helper.mine_block()
|
|
||||||
o = c.have(self.accounts_index_address, self.accounts[1], sender_address=self.accounts[0])
|
o = c.have(self.accounts_index_address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
|
|
||||||
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
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])
|
o = c.declaration(self.address, self.accounts[0], self.accounts[1], sender_address=self.accounts[0])
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
proofs = c.parse_declaration(r)
|
proofs = c.parse_declaration(r)
|
||||||
|
@ -89,5 +89,6 @@ class TestContractRegistry(TestAddressDeclaratorBase):
|
|||||||
self.assertEqual(z.hex(), proofs[2])
|
self.assertEqual(z.hex(), proofs[2])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -18,6 +18,7 @@ from eth_address_declarator import Declarator
|
|||||||
# local imports
|
# local imports
|
||||||
from okota.token_index.index import (
|
from okota.token_index.index import (
|
||||||
TokenUniqueSymbolIndexAddressDeclarator as TokenIndex,
|
TokenUniqueSymbolIndexAddressDeclarator as TokenIndex,
|
||||||
|
CICTokenIndex,
|
||||||
to_identifier,
|
to_identifier,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,12 +46,21 @@ class TestTokenIndex(TestAddressDeclaratorBase):
|
|||||||
|
|
||||||
self.token_index_address = r['contract_address']
|
self.token_index_address = r['contract_address']
|
||||||
|
|
||||||
|
c = CICTokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash_hex, o) = c.add_writer(self.token_index_address, self.accounts[0], self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
|
||||||
|
o = receipt(tx_hash_hex)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_register(self):
|
def test_register(self):
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||||
c = TokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
c = CICTokenIndex(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)
|
(tx_hash_hex, o) = c.add(self.token_index_address, self.accounts[0], self.foo_token_address)
|
||||||
self.rpc.do(o)
|
self.rpc.do(o)
|
||||||
e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec)
|
e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec)
|
||||||
|
|
||||||
@ -77,10 +87,12 @@ class TestTokenIndex(TestAddressDeclaratorBase):
|
|||||||
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0])
|
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0])
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
proofs = c.parse_declaration(r)
|
proofs = c.parse_declaration(r)
|
||||||
|
|
||||||
|
h = hashlib.sha256()
|
||||||
|
h.update('FOO'.encode('utf-8'))
|
||||||
|
z = h.digest()
|
||||||
|
|
||||||
token_symbol_identifier = to_identifier('FOO')
|
self.assertEqual(proofs[0], z.hex())
|
||||||
|
|
||||||
self.assertEqual(token_symbol_identifier, proofs[0])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -2,22 +2,20 @@ pragma solidity >0.6.11;
|
|||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
|
||||||
// TODO: inherit accounts index contract
|
// TODO: inherit accounts index contract
|
||||||
contract AccountsIndexAddressDeclarator {
|
contract AccountsIndexAddressDeclarator {
|
||||||
|
|
||||||
address public tokenAddress;
|
address public tokenAddress;
|
||||||
bytes32 tokenAddressHash;
|
bytes32 public tokenAddressHash;
|
||||||
address public addressDeclaratorAddress;
|
address public addressDeclaratorAddress;
|
||||||
mapping(address => uint256) entryIndex;
|
mapping(address => uint256) entryIndex;
|
||||||
//uint256 count;
|
|
||||||
mapping(address => bool) writers;
|
mapping(address => bool) writers;
|
||||||
address[] entries;
|
address[] entries;
|
||||||
|
|
||||||
address public owner;
|
address public owner;
|
||||||
address newOwner;
|
address newOwner;
|
||||||
|
|
||||||
event AddressAdded(address indexed addedAccount, uint256 indexed accountIndex); // AccountsIndex
|
event AddressAdded(address indexed addedAccount, uint256 indexed accountIndex); // AddressIndex
|
||||||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
||||||
|
|
||||||
constructor(address _tokenAddress, address _addressDeclaratorAddress) public {
|
constructor(address _tokenAddress, address _addressDeclaratorAddress) public {
|
||||||
@ -42,7 +40,7 @@ contract AccountsIndexAddressDeclarator {
|
|||||||
require(ok);
|
require(ok);
|
||||||
require(r[31] == 0x01);
|
require(r[31] == 0x01);
|
||||||
|
|
||||||
oldEntryIndex = entries.length - 1;
|
oldEntryIndex = entries.length;
|
||||||
entryIndex[_account] = oldEntryIndex;
|
entryIndex[_account] = oldEntryIndex;
|
||||||
entries.push(_account);
|
entries.push(_account);
|
||||||
|
|
||||||
@ -65,12 +63,14 @@ contract AccountsIndexAddressDeclarator {
|
|||||||
return entries.length - 1;
|
return entries.length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements Writer
|
||||||
function addWriter(address _writer) public returns (bool) {
|
function addWriter(address _writer) public returns (bool) {
|
||||||
require(owner == msg.sender);
|
require(owner == msg.sender);
|
||||||
writers[_writer] = true;
|
writers[_writer] = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements Writer
|
||||||
function deleteWriter(address _writer) public returns (bool) {
|
function deleteWriter(address _writer) public returns (bool) {
|
||||||
require(owner == msg.sender);
|
require(owner == msg.sender);
|
||||||
delete writers[_writer];
|
delete writers[_writer];
|
||||||
@ -95,4 +95,24 @@ contract AccountsIndexAddressDeclarator {
|
|||||||
emit OwnershipTransferred(oldOwner, owner);
|
emit OwnershipTransferred(oldOwner, owner);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements EIP165
|
||||||
|
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
||||||
|
if (_sum == 0xcbdb05c7) { // AccountsIndex
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (_sum == 0x01ffc9a7) { // EIP165
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (_sum == 0x9493f8b2) { // EIP173
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (_sum == 0x37a47be4) { // OwnedAccepter
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (_sum == 0x80c84bd6) { // Writer
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,13 @@ contract TokenUniqueSymbolIndexAddressDeclarator {
|
|||||||
address public owner;
|
address public owner;
|
||||||
address newOwner;
|
address newOwner;
|
||||||
address public addressDeclaratorAddress;
|
address public addressDeclaratorAddress;
|
||||||
|
mapping(address => bool) writers;
|
||||||
|
|
||||||
mapping ( bytes32 => uint256 ) public registry;
|
mapping ( bytes32 => uint256 ) public registry;
|
||||||
address[] tokens;
|
address[] tokens;
|
||||||
|
|
||||||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
||||||
event AddressAdded(address indexed addedAccount, uint256 indexed accountIndex); // AccountsIndex
|
event AddressAdded(address indexed addedAccount, uint256 indexed accountIndex); // AddressIndex
|
||||||
|
|
||||||
constructor(address _addressDeclaratorAddress) public {
|
constructor(address _addressDeclaratorAddress) public {
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
@ -35,7 +36,7 @@ contract TokenUniqueSymbolIndexAddressDeclarator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function register(address _token) public returns (bool) {
|
function register(address _token) public returns (bool) {
|
||||||
require(msg.sender == owner);
|
require(writers[msg.sender]);
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
bytes memory r;
|
bytes memory r;
|
||||||
@ -64,13 +65,13 @@ contract TokenUniqueSymbolIndexAddressDeclarator {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements AccountsIndex
|
// Implements AddressIndex
|
||||||
function add(address _token) public returns (bool) {
|
function add(address _token) public returns (bool) {
|
||||||
return register(_token);
|
return register(_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implements AccountsIndex
|
// Implements AddressIndex
|
||||||
function entryCount() public view returns ( uint256 ) {
|
function entryCount() public view returns ( uint256 ) {
|
||||||
return tokens.length - 1;
|
return tokens.length - 1;
|
||||||
}
|
}
|
||||||
@ -92,10 +93,23 @@ contract TokenUniqueSymbolIndexAddressDeclarator {
|
|||||||
emit OwnershipTransferred(oldOwner, owner);
|
emit OwnershipTransferred(oldOwner, owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements Writer
|
||||||
|
function addWriter(address _writer) public returns (bool) {
|
||||||
|
require(owner == msg.sender);
|
||||||
|
writers[_writer] = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements Writer
|
||||||
|
function deleteWriter(address _writer) public returns (bool) {
|
||||||
|
require(owner == msg.sender);
|
||||||
|
delete writers[_writer];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Implements EIP165
|
// Implements EIP165
|
||||||
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
||||||
if (_sum == 0xcbdb05c7) { // AccountsIndex
|
if (_sum == 0xcbdb05c7) { // AddressIndex
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (_sum == 0xbb34534c) { // Registry
|
if (_sum == 0xbb34534c) { // Registry
|
||||||
@ -110,6 +124,9 @@ contract TokenUniqueSymbolIndexAddressDeclarator {
|
|||||||
if (_sum == 0x37a47be4) { // OwnedAccepter
|
if (_sum == 0x37a47be4) { // OwnedAccepter
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (_sum == 0x80c84bd6) { // Writer
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user