erc20-limiter

ERC20 balance limit registry
Log | Files | Refs | README

commit 97174b4eb8e23cbd37dd26e7dc34e6f28ca5aaac
parent e6591adc9cfc17dc0286f8e2224a8b4fdc93b45c
Author: lash <dev@holbrook.no>
Date:   Thu,  3 Aug 2023 13:53:48 +0100

Rename limiter registry contract

Diffstat:
Apython/erc20_limiter/data/LimiterIndex.bin | 2++
Rpython/erc20_limiter/data/LimiterTokenRegistry.json -> python/erc20_limiter/data/LimiterIndex.json | 0
Apython/erc20_limiter/data/LimiterIndex.metadata.json | 1+
Dpython/erc20_limiter/data/LimiterTokenRegistry.bin | 2--
Dpython/erc20_limiter/data/LimiterTokenRegistry.metadata.json | 1-
Apython/erc20_limiter/index.py | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dpython/erc20_limiter/token.py | 96-------------------------------------------------------------------------------
Mpython/erc20_limiter/unittest/base.py | 6+++---
Apython/tests/test_index.py | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Dpython/tests/test_token_registry.py | 51---------------------------------------------------
Rsolidity/LimiterTokenRegistry.sol -> solidity/LimiterIndex.sol | 0
Msolidity/Makefile | 8++++----
12 files changed, 157 insertions(+), 157 deletions(-)

diff --git a/python/erc20_limiter/data/LimiterIndex.bin b/python/erc20_limiter/data/LimiterIndex.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b506040516109b93803806109b98339818101604052810190610032919061015b565b81600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505061019b565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100ea826100bf565b9050919050565b6100fa816100df565b811461010557600080fd5b50565b600081519050610117816100f1565b92915050565b6000610128826100df565b9050919050565b6101388161011d565b811461014357600080fd5b50565b6000815190506101558161012f565b92915050565b60008060408385031215610172576101716100ba565b5b600061018085828601610108565b925050602061019185828601610146565b9150509250929050565b61080f806101aa6000396000f3fe608060405234801561001057600080fd5b5060043610610074576000357c01000000000000000000000000000000000000000000000000000000009004806301ffc9a71461007957806323778613146100a957806336db43b5146100d95780633ef25013146100f5578063bdd5544014610125575b600080fd5b610093600480360381019061008e9190610507565b610141565b6040516100a0919061054f565b60405180910390f35b6100c360048036038101906100be91906105c8565b610243565b6040516100d09190610621565b60405180910390f35b6100f360048036038101906100ee9190610668565b610306565b005b61010f600480360381019061010a91906106a8565b610315565b60405161011c919061054f565b60405180910390f35b61013f600480360381019061013a91906106d5565b6103fa565b005b60006301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191603610195576001905061023e565b63b7bca6257c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916036101e7576001905061023e565b63237786137c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191603610239576001905061023e565b600090505b919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632377861384846040518363ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016102bd929190610737565b602060405180830381865afa1580156102da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102fe9190610775565b905092915050565b6103118233836103fa565b5050565b60008060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632377861384600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518363ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016103b1929190610737565b602060405180830381865afa1580156103ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103f29190610775565b119050919050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663bdd554408484846040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401610473939291906107a2565b600060405180830381600087803b15801561048d57600080fd5b505af11580156104a1573d6000803e3d6000fd5b50505050505050565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6104e4816104af565b81146104ef57600080fd5b50565b600081359050610501816104db565b92915050565b60006020828403121561051d5761051c6104aa565b5b600061052b848285016104f2565b91505092915050565b60008115159050919050565b61054981610534565b82525050565b60006020820190506105646000830184610540565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105958261056a565b9050919050565b6105a58161058a565b81146105b057600080fd5b50565b6000813590506105c28161059c565b92915050565b600080604083850312156105df576105de6104aa565b5b60006105ed858286016105b3565b92505060206105fe858286016105b3565b9150509250929050565b6000819050919050565b61061b81610608565b82525050565b60006020820190506106366000830184610612565b92915050565b61064581610608565b811461065057600080fd5b50565b6000813590506106628161063c565b92915050565b6000806040838503121561067f5761067e6104aa565b5b600061068d858286016105b3565b925050602061069e85828601610653565b9150509250929050565b6000602082840312156106be576106bd6104aa565b5b60006106cc848285016105b3565b91505092915050565b6000806000606084860312156106ee576106ed6104aa565b5b60006106fc868287016105b3565b935050602061070d868287016105b3565b925050604061071e86828701610653565b9150509250925092565b6107318161058a565b82525050565b600060408201905061074c6000830185610728565b6107596020830184610728565b9392505050565b60008151905061076f8161063c565b92915050565b60006020828403121561078b5761078a6104aa565b5b600061079984828501610760565b91505092915050565b60006060820190506107b76000830186610728565b6107c46020830185610728565b6107d16040830184610612565b94935050505056fea26469706673582212207ee27d09ef3d423a98e3dbc9563133658799e67ea2ceabcfe9327dda839ee8b464736f6c63430008130033 +\ No newline at end of file diff --git a/python/erc20_limiter/data/LimiterTokenRegistry.json b/python/erc20_limiter/data/LimiterIndex.json diff --git a/python/erc20_limiter/data/LimiterIndex.metadata.json b/python/erc20_limiter/data/LimiterIndex.metadata.json @@ -0,0 +1 @@ +{"compiler":{"version":"0.8.19+commit.7dd6d404"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"_holder","type":"address"},{"internalType":"contract Limiter","name":"_limiter","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_holder","type":"address"}],"name":"limitOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"setLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_holder","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"setLimitFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"LimiterIndex.sol":"LimiterTokenRegistry"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"LimiterIndex.sol":{"keccak256":"0x8bc7716c5a8b9d698a4f8571a89b4da77c790d5d17f6f5e0f83f31fe6faef649","license":"AGPL-3.0-or-later","urls":["bzz-raw://4135e14e8203ca39fc809c7505222686b61dee82362fd3eb0f295b61bb44182a","dweb:/ipfs/Qmf5bCwu61UAK9atMghHbZJC88tfq2X43UDwq2nxeExDZR"]}},"version":1} diff --git a/python/erc20_limiter/data/LimiterTokenRegistry.bin b/python/erc20_limiter/data/LimiterTokenRegistry.bin @@ -1 +0,0 @@ -608060405234801561001057600080fd5b506040516109b93803806109b98339818101604052810190610032919061015b565b81600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505061019b565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100ea826100bf565b9050919050565b6100fa816100df565b811461010557600080fd5b50565b600081519050610117816100f1565b92915050565b6000610128826100df565b9050919050565b6101388161011d565b811461014357600080fd5b50565b6000815190506101558161012f565b92915050565b60008060408385031215610172576101716100ba565b5b600061018085828601610108565b925050602061019185828601610146565b9150509250929050565b61080f806101aa6000396000f3fe608060405234801561001057600080fd5b5060043610610074576000357c01000000000000000000000000000000000000000000000000000000009004806301ffc9a71461007957806323778613146100a957806336db43b5146100d95780633ef25013146100f5578063bdd5544014610125575b600080fd5b610093600480360381019061008e9190610507565b610141565b6040516100a0919061054f565b60405180910390f35b6100c360048036038101906100be91906105c8565b610243565b6040516100d09190610621565b60405180910390f35b6100f360048036038101906100ee9190610668565b610306565b005b61010f600480360381019061010a91906106a8565b610315565b60405161011c919061054f565b60405180910390f35b61013f600480360381019061013a91906106d5565b6103fa565b005b60006301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191603610195576001905061023e565b63b7bca6257c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916036101e7576001905061023e565b63237786137c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191603610239576001905061023e565b600090505b919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632377861384846040518363ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016102bd929190610737565b602060405180830381865afa1580156102da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102fe9190610775565b905092915050565b6103118233836103fa565b5050565b60008060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632377861384600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518363ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016103b1929190610737565b602060405180830381865afa1580156103ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103f29190610775565b119050919050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663bdd554408484846040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401610473939291906107a2565b600060405180830381600087803b15801561048d57600080fd5b505af11580156104a1573d6000803e3d6000fd5b50505050505050565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6104e4816104af565b81146104ef57600080fd5b50565b600081359050610501816104db565b92915050565b60006020828403121561051d5761051c6104aa565b5b600061052b848285016104f2565b91505092915050565b60008115159050919050565b61054981610534565b82525050565b60006020820190506105646000830184610540565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105958261056a565b9050919050565b6105a58161058a565b81146105b057600080fd5b50565b6000813590506105c28161059c565b92915050565b600080604083850312156105df576105de6104aa565b5b60006105ed858286016105b3565b92505060206105fe858286016105b3565b9150509250929050565b6000819050919050565b61061b81610608565b82525050565b60006020820190506106366000830184610612565b92915050565b61064581610608565b811461065057600080fd5b50565b6000813590506106628161063c565b92915050565b6000806040838503121561067f5761067e6104aa565b5b600061068d858286016105b3565b925050602061069e85828601610653565b9150509250929050565b6000602082840312156106be576106bd6104aa565b5b60006106cc848285016105b3565b91505092915050565b6000806000606084860312156106ee576106ed6104aa565b5b60006106fc868287016105b3565b935050602061070d868287016105b3565b925050604061071e86828701610653565b9150509250925092565b6107318161058a565b82525050565b600060408201905061074c6000830185610728565b6107596020830184610728565b9392505050565b60008151905061076f8161063c565b92915050565b60006020828403121561078b5761078a6104aa565b5b600061079984828501610760565b91505092915050565b60006060820190506107b76000830186610728565b6107c46020830185610728565b6107d16040830184610612565b94935050505056fea2646970667358221220d14a5fb84c2c0c33d98c777eb16ce25087d08196d9f62f70806dcc9b49a0052464736f6c63430008130033 -\ No newline at end of file diff --git a/python/erc20_limiter/data/LimiterTokenRegistry.metadata.json b/python/erc20_limiter/data/LimiterTokenRegistry.metadata.json @@ -1 +0,0 @@ -{"compiler":{"version":"0.8.19+commit.7dd6d404"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"_holder","type":"address"},{"internalType":"contract Limiter","name":"_limiter","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_holder","type":"address"}],"name":"limitOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"setLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_holder","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"setLimitFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"LimiterTokenRegistry.sol":"LimiterTokenRegistry"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"LimiterTokenRegistry.sol":{"keccak256":"0x8bc7716c5a8b9d698a4f8571a89b4da77c790d5d17f6f5e0f83f31fe6faef649","license":"AGPL-3.0-or-later","urls":["bzz-raw://4135e14e8203ca39fc809c7505222686b61dee82362fd3eb0f295b61bb44182a","dweb:/ipfs/Qmf5bCwu61UAK9atMghHbZJC88tfq2X43UDwq2nxeExDZR"]}},"version":1} diff --git a/python/erc20_limiter/index.py b/python/erc20_limiter/index.py @@ -0,0 +1,96 @@ +# standard imports +import logging +import os +import enum + +# external imports +from chainlib.eth.constant import ZERO_ADDRESS +from chainlib.eth.constant import ZERO_CONTENT +from chainlib.eth.contract import ( + ABIContractEncoder, + ABIContractDecoder, + ABIContractType, + abi_decode_single, +) +from chainlib.eth.jsonrpc import to_blockheight_param +from chainlib.eth.error import RequestMismatchException +from chainlib.eth.tx import ( + TxFactory, + TxFormat, +) +from chainlib.jsonrpc import JSONRPCRequest +from chainlib.block import BlockSpec +from hexathon import ( + add_0x, + strip_0x, +) +from chainlib.eth.cli.encode import CLIEncoder + +# local imports +from erc20_limiter.data import data_dir + +logg = logging.getLogger() + + +class LimiterIndex(TxFactory): + + __abi = None + __bytecode = None + + def constructor(self, sender_address, holder_address, limiter_address, tx_format=TxFormat.JSONRPC, version=None): + code = self.cargs(holder_address, limiter_address, version=version) + tx = self.template(sender_address, None, use_nonce=True) + tx = self.set_code(tx, code) + return self.finalize(tx, tx_format) + + + @staticmethod + def cargs(holder_address, limiter_address, version=None): + code = LimiterIndex.bytecode(version=version) + enc = ABIContractEncoder() + enc.address(holder_address) + enc.address(limiter_address) + args = enc.get() + code += args + logg.debug('constructor code: ' + args) + return code + + + @staticmethod + def gas(code=None): + return 4000000 + + + @staticmethod + def abi(): + if LimiterIndex.__abi == None: + f = open(os.path.join(data_dir, 'LimiterIndex.json'), 'r') + LimiterIndex.__abi = json.load(f) + f.close() + return LimiterIndex.__abi + + + @staticmethod + def bytecode(version=None): + if LimiterIndex.__bytecode == None: + f = open(os.path.join(data_dir, 'LimiterIndex.bin')) + LimiterIndex.__bytecode = f.read() + f.close() + return LimiterIndex.__bytecode + + + def have(self, contract_address, token_address, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('have') + enc.typ(ABIContractType.ADDRESS) + enc.address(token_address) + 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['params'].append('latest') + o = j.finalize(o) + return o diff --git a/python/erc20_limiter/token.py b/python/erc20_limiter/token.py @@ -1,96 +0,0 @@ -# standard imports -import logging -import os -import enum - -# external imports -from chainlib.eth.constant import ZERO_ADDRESS -from chainlib.eth.constant import ZERO_CONTENT -from chainlib.eth.contract import ( - ABIContractEncoder, - ABIContractDecoder, - ABIContractType, - abi_decode_single, -) -from chainlib.eth.jsonrpc import to_blockheight_param -from chainlib.eth.error import RequestMismatchException -from chainlib.eth.tx import ( - TxFactory, - TxFormat, -) -from chainlib.jsonrpc import JSONRPCRequest -from chainlib.block import BlockSpec -from hexathon import ( - add_0x, - strip_0x, -) -from chainlib.eth.cli.encode import CLIEncoder - -# local imports -from erc20_limiter.data import data_dir - -logg = logging.getLogger() - - -class LimiterTokenRegistry(TxFactory): - - __abi = None - __bytecode = None - - def constructor(self, sender_address, holder_address, limiter_address, tx_format=TxFormat.JSONRPC, version=None): - code = self.cargs(holder_address, limiter_address, version=version) - tx = self.template(sender_address, None, use_nonce=True) - tx = self.set_code(tx, code) - return self.finalize(tx, tx_format) - - - @staticmethod - def cargs(holder_address, limiter_address, version=None): - code = LimiterTokenRegistry.bytecode(version=version) - enc = ABIContractEncoder() - enc.address(holder_address) - enc.address(limiter_address) - args = enc.get() - code += args - logg.debug('constructor code: ' + args) - return code - - - @staticmethod - def gas(code=None): - return 4000000 - - - @staticmethod - def abi(): - if LimiterTokenRegistry.__abi == None: - f = open(os.path.join(data_dir, 'LimiterTokenRegistry.json'), 'r') - LimiterTokenRegistry.__abi = json.load(f) - f.close() - return LimiterTokenRegistry.__abi - - - @staticmethod - def bytecode(version=None): - if LimiterTokenRegistry.__bytecode == None: - f = open(os.path.join(data_dir, 'LimiterTokenRegistry.bin')) - LimiterTokenRegistry.__bytecode = f.read() - f.close() - return LimiterTokenRegistry.__bytecode - - - def have(self, contract_address, token_address, sender_address=ZERO_ADDRESS, id_generator=None): - j = JSONRPCRequest(id_generator) - o = j.template() - o['method'] = 'eth_call' - enc = ABIContractEncoder() - enc.method('have') - enc.typ(ABIContractType.ADDRESS) - enc.address(token_address) - 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['params'].append('latest') - o = j.finalize(o) - return o diff --git a/python/erc20_limiter/unittest/base.py b/python/erc20_limiter/unittest/base.py @@ -12,7 +12,7 @@ from chainlib.eth.block import block_latest # local imports from erc20_limiter import Limiter -from erc20_limiter.token import LimiterTokenRegistry +from erc20_limiter.index import LimiterIndex logg = logging.getLogger(__name__) @@ -37,11 +37,11 @@ class TestLimiter(EthTesterCase): return address -class TestLimiterTokenRegistry(TestLimiter): +class TestLimiterIndex(TestLimiter): def publish_token_registry(self, holder_address, limiter_address): nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) - c = LimiterTokenRegistry(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + c = LimiterIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) (tx_hash, o) = c.constructor(self.accounts[0], holder_address, limiter_address) self.rpc.do(o) o = receipt(tx_hash) diff --git a/python/tests/test_index.py b/python/tests/test_index.py @@ -0,0 +1,51 @@ +# standard imports +import unittest +import logging + +# external imports +from chainlib.eth.nonce import RPCNonceOracle +from chainlib.eth.tx import receipt + +# local imports +from erc20_limiter import Limiter +from erc20_limiter.index import LimiterIndex +from erc20_limiter.unittest import TestLimiterIndex + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + + +class TestLimiterBase(TestLimiterIndex): + + def setUp(self): + super(TestLimiterBase, self).setUp() + self.publish_limiter() + self.token_registry = self.publish_token_registry(self.accounts[0], self.address) + logg.debug('tokenreg {}'.format(self.token_registry)) + + + def test_limit(self): + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + + foo_token = '2c26b46b68ffc68ff99b453c1d30413413422d70' + c = LimiterIndex(self.chain_spec) + o = c.have(self.token_registry, foo_token, sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertEqual(int(r, 16), 0) + + c = Limiter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.set_limit(self.address, self.accounts[0], foo_token, 42) + self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + c = LimiterIndex(self.chain_spec) + o = c.have(self.token_registry, foo_token, sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertEqual(int(r, 16), 1) + + +if __name__ == '__main__': + unittest.main() + diff --git a/python/tests/test_token_registry.py b/python/tests/test_token_registry.py @@ -1,51 +0,0 @@ -# standard imports -import unittest -import logging - -# external imports -from chainlib.eth.nonce import RPCNonceOracle -from chainlib.eth.tx import receipt - -# local imports -from erc20_limiter import Limiter -from erc20_limiter.token import LimiterTokenRegistry -from erc20_limiter.unittest import TestLimiterTokenRegistry - -logging.basicConfig(level=logging.DEBUG) -logg = logging.getLogger() - - -class TestLimiterBase(TestLimiterTokenRegistry): - - def setUp(self): - super(TestLimiterBase, self).setUp() - self.publish_limiter() - self.token_registry = self.publish_token_registry(self.accounts[0], self.address) - logg.debug('tokenreg {}'.format(self.token_registry)) - - - def test_limit(self): - nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) - - foo_token = '2c26b46b68ffc68ff99b453c1d30413413422d70' - c = LimiterTokenRegistry(self.chain_spec) - o = c.have(self.token_registry, foo_token, sender_address=self.accounts[0]) - r = self.rpc.do(o) - self.assertEqual(int(r, 16), 0) - - c = Limiter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) - (tx_hash, o) = c.set_limit(self.address, self.accounts[0], foo_token, 42) - self.rpc.do(o) - o = receipt(tx_hash) - r = self.rpc.do(o) - self.assertEqual(r['status'], 1) - - c = LimiterTokenRegistry(self.chain_spec) - o = c.have(self.token_registry, foo_token, sender_address=self.accounts[0]) - r = self.rpc.do(o) - self.assertEqual(int(r, 16), 1) - - -if __name__ == '__main__': - unittest.main() - diff --git a/solidity/LimiterTokenRegistry.sol b/solidity/LimiterIndex.sol diff --git a/solidity/Makefile b/solidity/Makefile @@ -4,12 +4,12 @@ all: $(SOLC) --bin Limiter.sol --evm-version byzantium | awk 'NR>3' > Limiter.bin $(SOLC) --abi Limiter.sol --evm-version byzantium | awk 'NR>3' > Limiter.json $(SOLC) --metadata Limiter.sol --evm-version byzantium | awk 'NR>3' > Limiter.metadata.json - $(SOLC) --bin LimiterTokenRegistry.sol --evm-version byzantium | awk 'NR>7' > LimiterTokenRegistry.bin - $(SOLC) --abi LimiterTokenRegistry.sol --evm-version byzantium | awk 'NR>7' > LimiterTokenRegistry.json - $(SOLC) --metadata LimiterTokenRegistry.sol --evm-version byzantium | awk 'NR>7' > LimiterTokenRegistry.metadata.json + $(SOLC) --bin LimiterIndex.sol --evm-version byzantium | awk 'NR>7' > LimiterIndex.bin + $(SOLC) --abi LimiterIndex.sol --evm-version byzantium | awk 'NR>7' > LimiterIndex.json + $(SOLC) --metadata LimiterIndex.sol --evm-version byzantium | awk 'NR>7' > LimiterIndex.metadata.json truncate -s -1 Limiter.bin - truncate -s -1 LimiterTokenRegistry.bin + truncate -s -1 LimiterIndex.bin install: all cp -v *.json ../python/erc20_limiter/data/