eth-erc20

ERC20 interface and example giftable token contract
Log | Files | Refs | LICENSE

commit 2d79c863ce100b4e0666ce5f5497377a4fd46582
parent 4310c043c594c6ad3363e8d5a4523b467e69276e
Author: nolash <dev@holbrook.no>
Date:   Sat, 26 Jun 2021 10:30:17 +0200

Improve test coverage

Diffstat:
Mpython/CHANGELOG | 4++++
Mpython/eth_erc20/erc20.py | 45++++++++++++++++++++++++++++++---------------
Mpython/eth_erc20/runnable/balance.py | 10++++------
Mpython/eth_erc20/runnable/transfer.py | 53+++++++++++++++++++++++++++++++++++++----------------
Mpython/giftable_erc20_token/data/GiftableToken.bin | 4++--
Mpython/giftable_erc20_token/data/GiftableToken.json | 2+-
Mpython/giftable_erc20_token/factory.py | 1+
Mpython/requirements.txt | 4++--
Mpython/setup.cfg | 2+-
Dpython/tests/conftest.py | 25-------------------------
Dpython/tests/test_erc20.py | 74--------------------------------------------------------------------------
Apython/tests/test_erc20_interface.py | 189+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msolidity/GiftableToken.bin | 4++--
Msolidity/GiftableToken.json | 2+-
Msolidity/GiftableToken.sol | 7+++++--
15 files changed, 279 insertions(+), 147 deletions(-)

diff --git a/python/CHANGELOG b/python/CHANGELOG @@ -1,3 +1,7 @@ +* 0.0.10-pending + - Upgrade chainlib dependency, providing customizable jsonrpc id +* 0.0.9-unreleased +* 0.0.8-unreleased * 0.0.7-unreleased - Implement keystore signing. - Change makefile to compile contract for Byzantium. diff --git a/python/eth_erc20/erc20.py b/python/eth_erc20/erc20.py @@ -19,13 +19,13 @@ from chainlib.eth.tx import ( TxFactory, TxFormat, ) +from chainlib.jsonrpc import JSONRPCRequest from chainlib.eth.contract import ( ABIContractEncoder, ABIContractDecoder, ABIContractType, abi_decode_single, ) -from chainlib.jsonrpc import jsonrpc_template from chainlib.eth.error import RequestMismatchException logg = logging.getLogger() @@ -34,8 +34,9 @@ logg = logging.getLogger() class ERC20(TxFactory): - def balance_of(self, contract_address, address, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def balance_of(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('balanceOf') @@ -46,15 +47,17 @@ class ERC20(TxFactory): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def balance(self, contract_address, address, sender_address=ZERO_ADDRESS): - return self.balance_of(contract_address, address, sender_address=ZERO_ADDRESS) + def balance(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None): + return self.balance_of(contract_address, address, sender_address=ZERO_ADDRESS, id_generator=id_generator) - def symbol(self, contract_address, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def symbol(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('symbol') @@ -63,11 +66,13 @@ class ERC20(TxFactory): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def name(self, contract_address, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def name(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('name') @@ -76,11 +81,13 @@ class ERC20(TxFactory): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def decimals(self, contract_address, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def decimals(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('decimals') @@ -89,11 +96,13 @@ class ERC20(TxFactory): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def total_supply(self, contract_address, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def total_supply(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('totalSupply') @@ -102,10 +111,11 @@ class ERC20(TxFactory): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def transfer(self, contract_address, sender_address, recipient_address, value, tx_format=TxFormat.JSONRPC): + def transfer(self, contract_address, sender_address, recipient_address, value, tx_format=TxFormat.JSONRPC, id_generator=None): enc = ABIContractEncoder() enc.method('transfer') enc.typ(ABIContractType.ADDRESS) @@ -115,7 +125,7 @@ class ERC20(TxFactory): data = add_0x(enc.get()) tx = self.template(sender_address, contract_address, use_nonce=True) tx = self.set_code(tx, data) - tx = self.finalize(tx, tx_format) + tx = self.finalize(tx, tx_format, id_generator=id_generator) return tx @@ -170,6 +180,11 @@ class ERC20(TxFactory): @classmethod + def parse_total_supply(self, v): + return abi_decode_single(ABIContractType.UINT256, v) + + + @classmethod def parse_transfer_request(self, v): v = strip_0x(v) cursor = 0 diff --git a/python/eth_erc20/runnable/balance.py b/python/eth_erc20/runnable/balance.py @@ -27,10 +27,6 @@ from eth_abi import encode_single # external imports from chainlib.eth.address import to_checksum -from chainlib.jsonrpc import ( - jsonrpc_template, - jsonrpc_result, - ) from chainlib.eth.connection import EthHTTPConnection from chainlib.eth.gas import ( OverrideGasOracle, @@ -44,8 +40,9 @@ from eth_erc20 import ERC20 logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() -default_abi_dir = os.environ.get('ETH_ABI_DIR', '/usr/share/local/cic/solidity/abi') -default_eth_provider = os.environ.get('ETH_PROVIDER', 'http://localhost:8545') +default_eth_provider = os.environ.get('RPC_PROVIDER') +if default_eth_provider == None: + default_eth_provider = os.environ.get('ETH_PROVIDER', 'http://localhost:8545') argparser = argparse.ArgumentParser() argparser.add_argument('-p', '--provider', dest='p', default=default_eth_provider, type=str, help='Web3 provider url (http only)') @@ -53,6 +50,7 @@ argparser.add_argument('-a', '--token-address', dest='a', required=True, type=st argparser.add_argument('-f', '--format', dest='f', type=str, default='terminal', help='Output format [terminal (default), raw, brief]') argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string') argparser.add_argument('-u', '--unsafe', dest='u', action='store_true', help='Auto-convert address to checksum adddress') +argparser.add_argument('--seq', action='store_true', help='Use sequential rpc ids') argparser.add_argument('-v', action='store_true', help='Be verbose') argparser.add_argument('-vv', action='store_true', help='Be more verbose') argparser.add_argument('address', type=str, help='Account address') diff --git a/python/eth_erc20/runnable/transfer.py b/python/eth_erc20/runnable/transfer.py @@ -24,7 +24,9 @@ from hexathon import ( strip_0x, ) from chainlib.eth.connection import EthHTTPConnection -from chainlib.jsonrpc import jsonrpc_template +from chainlib.jsonrpc import ( + IntSequenceGenerator, + ) from chainlib.eth.nonce import ( RPCNonceOracle, OverrideNonceOracle, @@ -45,9 +47,12 @@ logg = logging.getLogger() logging.getLogger('web3').setLevel(logging.WARNING) logging.getLogger('urllib3').setLevel(logging.WARNING) -default_abi_dir = '/usr/local/share/cic/solidity/abi' +default_eth_provider = os.environ.get('RPC_PROVIDER') +if default_eth_provider == None: + default_eth_provider = os.environ.get('ETH_PROVIDER', 'http://localhost:8545') + argparser = argparse.ArgumentParser() -argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)') +argparser.add_argument('-p', '--provider', dest='p', default=default_eth_provider, type=str, help='Web3 provider url (http only)') argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed') argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed') argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string') @@ -59,6 +64,7 @@ argparser.add_argument('-s', '--send', dest='s', action='store_true', help='Send argparser.add_argument('--nonce', type=int, help='Override nonce') argparser.add_argument('--gas-price', dest='gas_price', type=int, help='Override gas price') argparser.add_argument('--gas-limit', dest='gas_limit', type=int, help='Override gas limit') +argparser.add_argument('--seq', action='store_true', help='Use sequential rpc ids') argparser.add_argument('-v', action='store_true', help='Be verbose') argparser.add_argument('-vv', action='store_true', help='Be more verbose') argparser.add_argument('recipient', type=str, help='Recipient account address') @@ -91,22 +97,33 @@ if args.y != None: logg.debug('now have key for signer address {}'.format(signer_address)) signer = EIP155Signer(keystore) +rpc_id_generator = None +if args.seq: + rpc_id_generator = IntSequenceGenerator() + +auth = None +#if os.environ.get('RPC_AUTHENTICATION') == 'custom_token': + +if os.environ.get('RPC_AUTHENTICATION') == 'basic': + from chainlib.auth import BasicAuth + #auth = CustomHeaderTokenAuth('x-api-key', os.environ['RPC_AUTHENTICATION_STRING']) + auth = BasicAuth(os.environ['RPC_USERNAME'], os.environ['RPC_PASSWORD']) conn = EthHTTPConnection(args.p) nonce_oracle = None if args.nonce != None: - nonce_oracle = OverrideNonceOracle(signer_address, args.nonce) + nonce_oracle = OverrideNonceOracle(signer_address, args.nonce, id_generator=rpc_id_generator) else: - nonce_oracle = RPCNonceOracle(signer_address, conn) + nonce_oracle = RPCNonceOracle(signer_address, conn, id_generator=rpc_id_generator) -def _max_gas(code=None): - return 8000000 +#def _max_gas(code=None): +# return 8000000 gas_oracle = None if args.gas_price != None or args.gas_limit != None: - gas_oracle = OverrideGasOracle(price=args.gas_price, limit=args.gas_limit) + gas_oracle = OverrideGasOracle(price=args.gas_price, limit=args.gas_limit, id_generator=rpc_id_generator, conn=conn) else: - gas_oracle = RPCGasOracle(conn, code_callback=_max_gas) + gas_oracle = RPCGasOracle(conn, code_callback=ERC20.gas, id_generator=rpc_id_generator) chain_spec = ChainSpec.from_chain_str(args.i) chain_id = chain_spec.network_id() @@ -118,8 +135,8 @@ send = args.s g = ERC20(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) -def balance(token_address, address): - o = g.balance(token_address, address) +def balance(token_address, address, id_generator=None): + o = g.balance(token_address, address, id_generator=id_generator) r = conn.do(o) hx = strip_0x(r) return int(hx, 16) @@ -131,18 +148,22 @@ def main(): raise ValueError('invalid checksum address') if logg.isEnabledFor(logging.DEBUG): - logg.debug('sender {} balance after: {}'.format(signer_address, balance(args.a, signer_address))) - logg.debug('recipient {} balance after: {}'.format(recipient, balance(args.a, recipient))) + sender_balance = balance(args.a, signer_address, id_generator=rpc_id_generator) + recipient_balance = balance(args.a, recipient, id_generator=rpc_id_generator) + logg.debug('sender {} balance after: {}'.format(signer_address, sender_balance)) + logg.debug('recipient {} balance after: {}'.format(recipient, recipient_balance)) - (tx_hash_hex, o) = g.transfer(args.a, signer_address, recipient, value) + (tx_hash_hex, o) = g.transfer(args.a, signer_address, recipient, value, id_generator=rpc_id_generator) if send: conn.do(o) if block_last: r = conn.wait(tx_hash_hex) if logg.isEnabledFor(logging.DEBUG): - logg.debug('sender {} balance after: {}'.format(signer_address, balance(args.a, signer_address))) - logg.debug('recipient {} balance after: {}'.format(recipient, balance(args.a, recipient))) + sender_balance = balance(args.a, signer_address, id_generator=rpc_id_generator) + recipient_balance = balance(args.a, recipient, id_generator=rpc_id_generator) + logg.debug('sender {} balance after: {}'.format(signer_address, sender_balance)) + logg.debug('recipient {} balance after: {}'.format(recipient, recipient_balance)) if r['status'] == 0: logg.critical('VM revert. Wish I could tell you more') sys.exit(1) diff --git a/python/giftable_erc20_token/data/GiftableToken.bin b/python/giftable_erc20_token/data/GiftableToken.bin @@ -1 +1 @@ -60806040523480156200001157600080fd5b50604051620014ef380380620014ef83398181016040528101906200003791906200025d565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600290805190602001906200008f92919062000124565b508160039080519060200190620000a892919062000124565b5080600460006101000a81548160ff021916908360ff16021790555060018060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050506200047c565b828054620001329062000387565b90600052602060002090601f016020900481019282620001565760008555620001a2565b82601f106200017157805160ff1916838001178555620001a2565b82800160010185558215620001a2579182015b82811115620001a157825182559160200191906001019062000184565b5b509050620001b19190620001b5565b5090565b5b80821115620001d0576000816000905550600101620001b6565b5090565b6000620001eb620001e5846200030e565b620002e5565b9050828152602081018484840111156200020457600080fd5b6200021184828562000351565b509392505050565b600082601f8301126200022b57600080fd5b81516200023d848260208601620001d4565b91505092915050565b600081519050620002578162000462565b92915050565b6000806000606084860312156200027357600080fd5b600084015167ffffffffffffffff8111156200028e57600080fd5b6200029c8682870162000219565b935050602084015167ffffffffffffffff811115620002ba57600080fd5b620002c88682870162000219565b9250506040620002db8682870162000246565b9150509250925092565b6000620002f162000304565b9050620002ff8282620003bd565b919050565b6000604051905090565b600067ffffffffffffffff8211156200032c576200032b62000422565b5b620003378262000451565b9050602081019050919050565b600060ff82169050919050565b60005b838110156200037157808201518184015260208101905062000354565b8381111562000381576000848401525b50505050565b60006002820490506001821680620003a057607f821691505b60208210811415620003b757620003b6620003f3565b5b50919050565b620003c88262000451565b810181811067ffffffffffffffff82111715620003ea57620003e962000422565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b6200046d8162000344565b81146200047957600080fd5b50565b611063806200048c6000396000f3fe608060405234801561001057600080fd5b50600436106100d1576000357c010000000000000000000000000000000000000000000000000000000090048063449a52f81161008e578063449a52f8146101c057806370a08231146101f057806395d89b4114610220578063983b2d561461023e578063a9059cbb1461026e578063dd62ed3e1461029e576100d1565b806306fdde03146100d6578063095ea7b3146100f457806318160ddd1461012457806323b872dd146101425780633092afd514610172578063313ce567146101a2575b600080fd5b6100de6102ce565b6040516100eb9190610dd8565b60405180910390f35b61010e60048036038101906101099190610d1b565b61035c565b60405161011b9190610dbd565b60405180910390f35b61012c610460565b6040516101399190610dfa565b60405180910390f35b61015c60048036038101906101579190610ccc565b610466565b6040516101699190610dbd565b60405180910390f35b61018c60048036038101906101879190610c67565b610778565b6040516101999190610dbd565b60405180910390f35b6101aa61086a565b6040516101b79190610e15565b60405180910390f35b6101da60048036038101906101d59190610d1b565b61087d565b6040516101e79190610dbd565b60405180910390f35b61020a60048036038101906102059190610c67565b61094e565b6040516102179190610dfa565b60405180910390f35b610228610966565b6040516102359190610dd8565b60405180910390f35b61025860048036038101906102539190610c67565b6109f4565b6040516102659190610dbd565b60405180910390f35b61028860048036038101906102839190610d1b565b610aaf565b6040516102959190610dbd565b60405180910390f35b6102b860048036038101906102b39190610c90565b610c18565b6040516102c59190610dfa565b60405180910390f35b600280546102db90610f5e565b80601f016020809104026020016040519081016040528092919081815260200182805461030790610f5e565b80156103545780601f1061032957610100808354040283529160200191610354565b820191906000526020600020905b81548152906001019060200180831161033757829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546103ea9190610e4c565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161044e9190610dfa565b60405180910390a36001905092915050565b60055481565b600081600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156104f157600080fd5b81600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561053d57600080fd5b81600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546105c59190610ea2565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546106949190610ea2565b9250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546106ea9190610e4c565b925050819055503373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167f5f7542858008eeb041631f30e6109ae94b83a58e9a58261dd2c42c508850f939856040516107659190610dfa565b60405180910390a4600190509392505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148061080057508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b61080957600080fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600460009054906101000a900460ff1681565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166108d557600080fd5b81600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546109249190610e4c565b92505081905550816005600082825461093d9190610e4c565b925050819055506001905092915050565b60066020528060005260406000206000915090505481565b6003805461097390610f5e565b80601f016020809104026020016040519081016040528092919081815260200182805461099f90610f5e565b80156109ec5780601f106109c1576101008083540402835291602001916109ec565b820191906000526020600020905b8154815290600101906020018083116109cf57829003601f168201915b505050505081565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a4f57600080fd5b60018060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600081600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610afd57600080fd5b81600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610b4c9190610ea2565b9250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610ba29190610e4c565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610c069190610dfa565b60405180910390a36001905092915050565b6007602052816000526040600020602052806000526040600020600091509150505481565b600081359050610c4c81610fff565b92915050565b600081359050610c6181611016565b92915050565b600060208284031215610c7957600080fd5b6000610c8784828501610c3d565b91505092915050565b60008060408385031215610ca357600080fd5b6000610cb185828601610c3d565b9250506020610cc285828601610c3d565b9150509250929050565b600080600060608486031215610ce157600080fd5b6000610cef86828701610c3d565b9350506020610d0086828701610c3d565b9250506040610d1186828701610c52565b9150509250925092565b60008060408385031215610d2e57600080fd5b6000610d3c85828601610c3d565b9250506020610d4d85828601610c52565b9150509250929050565b610d6081610ee8565b82525050565b6000610d7182610e30565b610d7b8185610e3b565b9350610d8b818560208601610f2b565b610d9481610fee565b840191505092915050565b610da881610f14565b82525050565b610db781610f1e565b82525050565b6000602082019050610dd26000830184610d57565b92915050565b60006020820190508181036000830152610df28184610d66565b905092915050565b6000602082019050610e0f6000830184610d9f565b92915050565b6000602082019050610e2a6000830184610dae565b92915050565b600081519050919050565b600082825260208201905092915050565b6000610e5782610f14565b9150610e6283610f14565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610e9757610e96610f90565b5b828201905092915050565b6000610ead82610f14565b9150610eb883610f14565b925082821015610ecb57610eca610f90565b5b828203905092915050565b6000610ee182610ef4565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b83811015610f49578082015181840152602081019050610f2e565b83811115610f58576000848401525b50505050565b60006002820490506001821680610f7657607f821691505b60208210811415610f8a57610f89610fbf565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b61100881610ed6565b811461101357600080fd5b50565b61101f81610f14565b811461102a57600080fd5b5056fea2646970667358221220d03175765e6a0d5359f40b7022325f34ef08d464c486b4e35a0b1c8927da82f164736f6c63430008020033 -\ No newline at end of file +60806040523480156200001157600080fd5b50604051620017a5380380620017a583398181016040528101906200003791906200025d565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600290805190602001906200008f92919062000124565b508160039080519060200190620000a892919062000124565b5080600460006101000a81548160ff021916908360ff16021790555060018060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050506200047c565b828054620001329062000387565b90600052602060002090601f016020900481019282620001565760008555620001a2565b82601f106200017157805160ff1916838001178555620001a2565b82800160010185558215620001a2579182015b82811115620001a157825182559160200191906001019062000184565b5b509050620001b19190620001b5565b5090565b5b80821115620001d0576000816000905550600101620001b6565b5090565b6000620001eb620001e5846200030e565b620002e5565b9050828152602081018484840111156200020457600080fd5b6200021184828562000351565b509392505050565b600082601f8301126200022b57600080fd5b81516200023d848260208601620001d4565b91505092915050565b600081519050620002578162000462565b92915050565b6000806000606084860312156200027357600080fd5b600084015167ffffffffffffffff8111156200028e57600080fd5b6200029c8682870162000219565b935050602084015167ffffffffffffffff811115620002ba57600080fd5b620002c88682870162000219565b9250506040620002db8682870162000246565b9150509250925092565b6000620002f162000304565b9050620002ff8282620003bd565b919050565b6000604051905090565b600067ffffffffffffffff8211156200032c576200032b62000422565b5b620003378262000451565b9050602081019050919050565b600060ff82169050919050565b60005b838110156200037157808201518184015260208101905062000354565b8381111562000381576000848401525b50505050565b60006002820490506001821680620003a057607f821691505b60208210811415620003b757620003b6620003f3565b5b50919050565b620003c88262000451565b810181811067ffffffffffffffff82111715620003ea57620003e962000422565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b6200046d8162000344565b81146200047957600080fd5b50565b611319806200048c6000396000f3fe608060405234801561001057600080fd5b50600436106100ec576000357c010000000000000000000000000000000000000000000000000000000090048063313ce567116100a957806395d89b411161008357806395d89b411461026b578063983b2d5614610289578063a9059cbb146102b9578063dd62ed3e146102e9576100ec565b8063313ce567146101ed578063449a52f81461020b57806370a082311461023b576100ec565b806301ffc9a7146100f157806306fdde0314610121578063095ea7b31461013f57806318160ddd1461016f57806323b872dd1461018d5780633092afd5146101bd575b600080fd5b61010b60048036038101906101069190610fa1565b610319565b6040516101189190611030565b60405180910390f35b61012961041e565b604051610136919061104b565b60405180910390f35b61015960048036038101906101549190610f65565b6104ac565b6040516101669190611030565b60405180910390f35b610177610630565b604051610184919061106d565b60405180910390f35b6101a760048036038101906101a29190610f16565b610636565b6040516101b49190611030565b60405180910390f35b6101d760048036038101906101d29190610eb1565b610948565b6040516101e49190611030565b60405180910390f35b6101f5610a3a565b6040516102029190611088565b60405180910390f35b61022560048036038101906102209190610f65565b610a4d565b6040516102329190611030565b60405180910390f35b61025560048036038101906102509190610eb1565b610b83565b604051610262919061106d565b60405180910390f35b610273610b9b565b604051610280919061104b565b60405180910390f35b6102a3600480360381019061029e9190610eb1565b610c29565b6040516102b09190611030565b60405180910390f35b6102d360048036038101906102ce9190610f65565b610ce4565b6040516102e09190611030565b60405180910390f35b61030360048036038101906102fe9190610eda565b610e4d565b604051610310919061106d565b60405180910390f35b600063c6bb4b707c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561036e5760019050610419565b63449a52f87c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156103c15760019050610419565b6301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156104145760019050610419565b600090505b919050565b6002805461042b906111fd565b80601f0160208091040260200160405190810160405280929190818152602001828054610457906111fd565b80156104a45780601f10610479576101008083540402835291602001916104a4565b820191906000526020600020905b81548152906001019060200180831161048757829003601f168201915b505050505081565b600080821115610540576000600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541461053f57600080fd5b5b81600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161061e919061106d565b60405180910390a36001905092915050565b60055481565b600081600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156106c157600080fd5b81600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561070d57600080fd5b81600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546107959190611115565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546108649190611115565b9250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546108ba91906110bf565b925050819055503373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167f5f7542858008eeb041631f30e6109ae94b83a58e9a58261dd2c42c508850f93985604051610935919061106d565b60405180910390a4600190509392505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806109d057508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6109d957600080fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600460009054906101000a900460ff1681565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610aa557600080fd5b81600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610af491906110bf565b925050819055508160056000828254610b0d91906110bf565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f884604051610b71919061106d565b60405180910390a36001905092915050565b60066020528060005260406000206000915090505481565b60038054610ba8906111fd565b80601f0160208091040260200160405190810160405280929190818152602001828054610bd4906111fd565b8015610c215780601f10610bf657610100808354040283529160200191610c21565b820191906000526020600020905b815481529060010190602001808311610c0457829003601f168201915b505050505081565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c8457600080fd5b60018060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600081600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610d3257600080fd5b81600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610d819190611115565b9250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610dd791906110bf565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610e3b919061106d565b60405180910390a36001905092915050565b6007602052816000526040600020602052806000526040600020600091509150505481565b600081359050610e818161129e565b92915050565b600081359050610e96816112b5565b92915050565b600081359050610eab816112cc565b92915050565b600060208284031215610ec357600080fd5b6000610ed184828501610e72565b91505092915050565b60008060408385031215610eed57600080fd5b6000610efb85828601610e72565b9250506020610f0c85828601610e72565b9150509250929050565b600080600060608486031215610f2b57600080fd5b6000610f3986828701610e72565b9350506020610f4a86828701610e72565b9250506040610f5b86828701610e9c565b9150509250925092565b60008060408385031215610f7857600080fd5b6000610f8685828601610e72565b9250506020610f9785828601610e9c565b9150509250929050565b600060208284031215610fb357600080fd5b6000610fc184828501610e87565b91505092915050565b610fd38161115b565b82525050565b6000610fe4826110a3565b610fee81856110ae565b9350610ffe8185602086016111ca565b6110078161128d565b840191505092915050565b61101b816111b3565b82525050565b61102a816111bd565b82525050565b60006020820190506110456000830184610fca565b92915050565b600060208201905081810360008301526110658184610fd9565b905092915050565b60006020820190506110826000830184611012565b92915050565b600060208201905061109d6000830184611021565b92915050565b600081519050919050565b600082825260208201905092915050565b60006110ca826111b3565b91506110d5836111b3565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561110a5761110961122f565b5b828201905092915050565b6000611120826111b3565b915061112b836111b3565b92508282101561113e5761113d61122f565b5b828203905092915050565b600061115482611193565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b838110156111e85780820151818401526020810190506111cd565b838111156111f7576000848401525b50505050565b6000600282049050600182168061121557607f821691505b602082108114156112295761122861125e565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b6112a781611149565b81146112b257600080fd5b50565b6112be81611167565b81146112c957600080fd5b50565b6112d5816111b3565b81146112e057600080fd5b5056fea264697066735822122081dda93f8f62cdd00d5a28d40736a4d2ce80f280f7c878ee8bc8ac6980493dbe64736f6c63430008040033 +\ No newline at end of file diff --git a/python/giftable_erc20_token/data/GiftableToken.json b/python/giftable_erc20_token/data/GiftableToken.json @@ -1 +1 @@ -[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"mintTo","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"removeMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] +[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_minter","type":"address"},{"indexed":true,"internalType":"address","name":"_beneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"mintTo","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"removeMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/python/giftable_erc20_token/factory.py b/python/giftable_erc20_token/factory.py @@ -40,6 +40,7 @@ class GiftableToken(TxFactory): def gas(code=None): return 1500000 + @staticmethod def abi(): if GiftableToken.__abi == None: diff --git a/python/requirements.txt b/python/requirements.txt @@ -1,4 +1,4 @@ confini~=0.3.6rc3 -crypto-dev-signer~=0.4.14b3 -chainlib~=0.0.3a1 +crypto-dev-signer~=0.4.14b6 +chainlib~=0.0.4a1 potaahto~=0.0.1a2 diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-erc20 -version = 0.0.9a2 +version = 0.0.10a1 description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens. author = Louis Holbrook author_email = dev@holbrook.no diff --git a/python/tests/conftest.py b/python/tests/conftest.py @@ -1,25 +0,0 @@ -# standard imports -import os - -# external imports -import pytest -from crypto_dev_signer.keystore.dict import DictKeystore -from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer - - -@pytest.fixture(scope='session') -def keystore(): - ks = DictKeystore() - - pk = os.urandom(32) - ks.import_raw_key(pk) - return ks - - -@pytest.fixture(scope='session') -def signer( - keystore, - ): - - s = EIP155Signer(keystore) - return s diff --git a/python/tests/test_erc20.py b/python/tests/test_erc20.py @@ -1,74 +0,0 @@ -# standard imports -import logging -import os - -# external imports -from hexathon import ( - strip_0x, - add_0x, - ) -from chainlib.eth.address import to_checksum_address -from chainlib.eth.tx import ( - unpack, - TxFormat, - ) -from chainlib.eth.pytest import * - -# local imports -from eth_erc20 import ERC20 - -logg = logging.getLogger() - -contract_address = to_checksum_address('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef') -benefactor_address = to_checksum_address('0xefdeadbeefdeadbeefdeadbeefdeadbeefdeadbe') - - -# TODO: use unittest instead -def test_erc20_balance( - default_chain_spec, - ): - e = ERC20(default_chain_spec,) - - holder_address = to_checksum_address('0xbeefdeadbeefdeadbeefdeadbeefdeadbeefdead') - o = e.balance_of(contract_address, holder_address) - assert len(o['params'][0]['data']) == 64 + 8 + 2 - assert o['params'][0]['data'][:10] == add_0x('70a08231') - - -def test_erc20_decimals( - default_chain_spec, - ): - e = ERC20(default_chain_spec) - - o = e.decimals(contract_address) - assert o['params'][0]['data'] == add_0x('313ce567') - - -def test_erc20_transfer( - keystore, - signer, - default_chain_spec, - ): - e = ERC20(default_chain_spec, signer=signer) - - addresses = keystore.list() - (tx_hash_hex, o) = e.transfer(contract_address, addresses[0], benefactor_address, 1024) - - -def test_erc20_parse_transfer_request( - keystore, - signer, - default_chain_spec, - ): - - e = ERC20(default_chain_spec, signer=signer) - - addresses = keystore.list() - (tx_hash_hex, o) = e.transfer(contract_address, addresses[0], benefactor_address, 1024, tx_format=TxFormat.RLP_SIGNED) - b = bytes.fromhex(strip_0x(o)) - - #chain_spec = ChainSpec('evm', 'foo', 1, 'bar') - tx = unpack(b, default_chain_spec) - r = ERC20.parse_transfer_request(tx['data']) - assert r[0] == benefactor_address - assert r[1] == 1024 diff --git a/python/tests/test_erc20_interface.py b/python/tests/test_erc20_interface.py @@ -0,0 +1,189 @@ +# standard imports +import logging +import unittest + +# external imports +from chainlib.eth.unittest.ethtester import EthTesterCase +from chainlib.connection import RPCConnection +from chainlib.eth.nonce import RPCNonceOracle +from chainlib.eth.gas import OverrideGasOracle +from chainlib.eth.tx import ( + transaction, + receipt, + ) +from chainlib.eth.address import to_checksum_address + +# local imports +from giftable_erc20_token import GiftableToken +from eth_erc20 import ERC20 + +logg = logging.getLogger(__name__) + + +class TestToken(EthTesterCase): + + def setUp(self): + super(TestToken, self).setUp() + self.conn = RPCConnection.connect(self.chain_spec, 'default') + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + self.symbol = 'FOO' + self.name = 'Foo Token' + self.decimals = 16 + (tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals) + r = self.conn.do(o) + logg.debug('deployed with hash {}'.format(r)) + + o = receipt(r) + r = self.conn.do(o) + self.address = to_checksum_address(r['contract_address']) + + self.initial_supply = 1 << 40 + (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], self.initial_supply) + r = self.conn.do(o) + o = receipt(tx_hash) + r = self.conn.do(o) + self.assertEqual(r['status'], 1) + + + def test_balance(self): + c = ERC20(self.chain_spec) + o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0]) + r = self.conn.do(o) + balance = ERC20.parse_balance(r) + self.assertEqual(self.initial_supply, balance) + + + def test_supply(self): + c = ERC20(self.chain_spec) + o = c.total_supply(self.address, sender_address=self.accounts[0]) + r = self.conn.do(o) + supply = ERC20.parse_total_supply(r) + self.assertEqual(self.initial_supply, supply) + + + def test_name(self): + c = ERC20(self.chain_spec) + o = c.name(self.address, sender_address=self.accounts[0]) + r = self.conn.do(o) + name = ERC20.parse_name(r) + self.assertEqual(self.name, name) + + + def test_symbol(self): + c = ERC20(self.chain_spec) + o = c.symbol(self.address, sender_address=self.accounts[0]) + r = self.conn.do(o) + symbol = ERC20.parse_symbol(r) + self.assertEqual(self.symbol, symbol) + + + def test_transfer(self): + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) + (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.accounts[1], 1000) + r = self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0]) + r = self.rpc.do(o) + balance = c.parse_balance(r) + self.assertEqual(balance, self.initial_supply - 1000) + + o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) + r = self.rpc.do(o) + balance = c.parse_balance(r) + self.assertEqual(balance, 1000) + + o = transaction(tx_hash) + r = self.rpc.do(o) + data = c.parse_transfer_request(r['data']) + self.assertEqual(data[0], self.accounts[1]) + self.assertEqual(data[1], 1000) + + + def test_transfer_from(self): + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) + (tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 1000) + r = self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + o = transaction(tx_hash) + r = self.rpc.do(o) + data = c.parse_approve_request(r['data']) + self.assertEqual(data[0], self.accounts[1]) + self.assertEqual(data[1], 1000) + + nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) + (tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1001) + r = self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + + o = transaction(tx_hash) + r = self.rpc.do(o) + data = c.parse_transfer_from_request(r['data']) + self.assertEqual(data[0], self.accounts[0]) + self.assertEqual(data[1], self.accounts[2]) + self.assertEqual(data[2], 1001) + + (tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1000) + r = self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0]) + r = self.rpc.do(o) + balance = c.parse_balance(r) + self.assertEqual(balance, self.initial_supply - 1000) + + o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0]) + r = self.rpc.do(o) + balance = c.parse_balance(r) + self.assertEqual(balance, 1000) + + + def test_revoke_approve(self): + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) + (tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 1000) + r = self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + (tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 999) + r = self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + + (tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 0) + r = self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) + (tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1) + r = self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + + + +if __name__ == '__main__': + unittest.main() diff --git a/solidity/GiftableToken.bin b/solidity/GiftableToken.bin @@ -1 +1 @@ -60806040523480156200001157600080fd5b50604051620014ef380380620014ef83398181016040528101906200003791906200025d565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600290805190602001906200008f92919062000124565b508160039080519060200190620000a892919062000124565b5080600460006101000a81548160ff021916908360ff16021790555060018060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050506200047c565b828054620001329062000387565b90600052602060002090601f016020900481019282620001565760008555620001a2565b82601f106200017157805160ff1916838001178555620001a2565b82800160010185558215620001a2579182015b82811115620001a157825182559160200191906001019062000184565b5b509050620001b19190620001b5565b5090565b5b80821115620001d0576000816000905550600101620001b6565b5090565b6000620001eb620001e5846200030e565b620002e5565b9050828152602081018484840111156200020457600080fd5b6200021184828562000351565b509392505050565b600082601f8301126200022b57600080fd5b81516200023d848260208601620001d4565b91505092915050565b600081519050620002578162000462565b92915050565b6000806000606084860312156200027357600080fd5b600084015167ffffffffffffffff8111156200028e57600080fd5b6200029c8682870162000219565b935050602084015167ffffffffffffffff811115620002ba57600080fd5b620002c88682870162000219565b9250506040620002db8682870162000246565b9150509250925092565b6000620002f162000304565b9050620002ff8282620003bd565b919050565b6000604051905090565b600067ffffffffffffffff8211156200032c576200032b62000422565b5b620003378262000451565b9050602081019050919050565b600060ff82169050919050565b60005b838110156200037157808201518184015260208101905062000354565b8381111562000381576000848401525b50505050565b60006002820490506001821680620003a057607f821691505b60208210811415620003b757620003b6620003f3565b5b50919050565b620003c88262000451565b810181811067ffffffffffffffff82111715620003ea57620003e962000422565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b6200046d8162000344565b81146200047957600080fd5b50565b611063806200048c6000396000f3fe608060405234801561001057600080fd5b50600436106100d1576000357c010000000000000000000000000000000000000000000000000000000090048063449a52f81161008e578063449a52f8146101c057806370a08231146101f057806395d89b4114610220578063983b2d561461023e578063a9059cbb1461026e578063dd62ed3e1461029e576100d1565b806306fdde03146100d6578063095ea7b3146100f457806318160ddd1461012457806323b872dd146101425780633092afd514610172578063313ce567146101a2575b600080fd5b6100de6102ce565b6040516100eb9190610dd8565b60405180910390f35b61010e60048036038101906101099190610d1b565b61035c565b60405161011b9190610dbd565b60405180910390f35b61012c610460565b6040516101399190610dfa565b60405180910390f35b61015c60048036038101906101579190610ccc565b610466565b6040516101699190610dbd565b60405180910390f35b61018c60048036038101906101879190610c67565b610778565b6040516101999190610dbd565b60405180910390f35b6101aa61086a565b6040516101b79190610e15565b60405180910390f35b6101da60048036038101906101d59190610d1b565b61087d565b6040516101e79190610dbd565b60405180910390f35b61020a60048036038101906102059190610c67565b61094e565b6040516102179190610dfa565b60405180910390f35b610228610966565b6040516102359190610dd8565b60405180910390f35b61025860048036038101906102539190610c67565b6109f4565b6040516102659190610dbd565b60405180910390f35b61028860048036038101906102839190610d1b565b610aaf565b6040516102959190610dbd565b60405180910390f35b6102b860048036038101906102b39190610c90565b610c18565b6040516102c59190610dfa565b60405180910390f35b600280546102db90610f5e565b80601f016020809104026020016040519081016040528092919081815260200182805461030790610f5e565b80156103545780601f1061032957610100808354040283529160200191610354565b820191906000526020600020905b81548152906001019060200180831161033757829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546103ea9190610e4c565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161044e9190610dfa565b60405180910390a36001905092915050565b60055481565b600081600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156104f157600080fd5b81600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561053d57600080fd5b81600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546105c59190610ea2565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546106949190610ea2565b9250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546106ea9190610e4c565b925050819055503373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167f5f7542858008eeb041631f30e6109ae94b83a58e9a58261dd2c42c508850f939856040516107659190610dfa565b60405180910390a4600190509392505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148061080057508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b61080957600080fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600460009054906101000a900460ff1681565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166108d557600080fd5b81600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546109249190610e4c565b92505081905550816005600082825461093d9190610e4c565b925050819055506001905092915050565b60066020528060005260406000206000915090505481565b6003805461097390610f5e565b80601f016020809104026020016040519081016040528092919081815260200182805461099f90610f5e565b80156109ec5780601f106109c1576101008083540402835291602001916109ec565b820191906000526020600020905b8154815290600101906020018083116109cf57829003601f168201915b505050505081565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a4f57600080fd5b60018060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600081600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610afd57600080fd5b81600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610b4c9190610ea2565b9250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610ba29190610e4c565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610c069190610dfa565b60405180910390a36001905092915050565b6007602052816000526040600020602052806000526040600020600091509150505481565b600081359050610c4c81610fff565b92915050565b600081359050610c6181611016565b92915050565b600060208284031215610c7957600080fd5b6000610c8784828501610c3d565b91505092915050565b60008060408385031215610ca357600080fd5b6000610cb185828601610c3d565b9250506020610cc285828601610c3d565b9150509250929050565b600080600060608486031215610ce157600080fd5b6000610cef86828701610c3d565b9350506020610d0086828701610c3d565b9250506040610d1186828701610c52565b9150509250925092565b60008060408385031215610d2e57600080fd5b6000610d3c85828601610c3d565b9250506020610d4d85828601610c52565b9150509250929050565b610d6081610ee8565b82525050565b6000610d7182610e30565b610d7b8185610e3b565b9350610d8b818560208601610f2b565b610d9481610fee565b840191505092915050565b610da881610f14565b82525050565b610db781610f1e565b82525050565b6000602082019050610dd26000830184610d57565b92915050565b60006020820190508181036000830152610df28184610d66565b905092915050565b6000602082019050610e0f6000830184610d9f565b92915050565b6000602082019050610e2a6000830184610dae565b92915050565b600081519050919050565b600082825260208201905092915050565b6000610e5782610f14565b9150610e6283610f14565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610e9757610e96610f90565b5b828201905092915050565b6000610ead82610f14565b9150610eb883610f14565b925082821015610ecb57610eca610f90565b5b828203905092915050565b6000610ee182610ef4565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b83811015610f49578082015181840152602081019050610f2e565b83811115610f58576000848401525b50505050565b60006002820490506001821680610f7657607f821691505b60208210811415610f8a57610f89610fbf565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b61100881610ed6565b811461101357600080fd5b50565b61101f81610f14565b811461102a57600080fd5b5056fea2646970667358221220d03175765e6a0d5359f40b7022325f34ef08d464c486b4e35a0b1c8927da82f164736f6c63430008020033 -\ No newline at end of file +60806040523480156200001157600080fd5b50604051620017a5380380620017a583398181016040528101906200003791906200025d565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600290805190602001906200008f92919062000124565b508160039080519060200190620000a892919062000124565b5080600460006101000a81548160ff021916908360ff16021790555060018060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050506200047c565b828054620001329062000387565b90600052602060002090601f016020900481019282620001565760008555620001a2565b82601f106200017157805160ff1916838001178555620001a2565b82800160010185558215620001a2579182015b82811115620001a157825182559160200191906001019062000184565b5b509050620001b19190620001b5565b5090565b5b80821115620001d0576000816000905550600101620001b6565b5090565b6000620001eb620001e5846200030e565b620002e5565b9050828152602081018484840111156200020457600080fd5b6200021184828562000351565b509392505050565b600082601f8301126200022b57600080fd5b81516200023d848260208601620001d4565b91505092915050565b600081519050620002578162000462565b92915050565b6000806000606084860312156200027357600080fd5b600084015167ffffffffffffffff8111156200028e57600080fd5b6200029c8682870162000219565b935050602084015167ffffffffffffffff811115620002ba57600080fd5b620002c88682870162000219565b9250506040620002db8682870162000246565b9150509250925092565b6000620002f162000304565b9050620002ff8282620003bd565b919050565b6000604051905090565b600067ffffffffffffffff8211156200032c576200032b62000422565b5b620003378262000451565b9050602081019050919050565b600060ff82169050919050565b60005b838110156200037157808201518184015260208101905062000354565b8381111562000381576000848401525b50505050565b60006002820490506001821680620003a057607f821691505b60208210811415620003b757620003b6620003f3565b5b50919050565b620003c88262000451565b810181811067ffffffffffffffff82111715620003ea57620003e962000422565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b6200046d8162000344565b81146200047957600080fd5b50565b611319806200048c6000396000f3fe608060405234801561001057600080fd5b50600436106100ec576000357c010000000000000000000000000000000000000000000000000000000090048063313ce567116100a957806395d89b411161008357806395d89b411461026b578063983b2d5614610289578063a9059cbb146102b9578063dd62ed3e146102e9576100ec565b8063313ce567146101ed578063449a52f81461020b57806370a082311461023b576100ec565b806301ffc9a7146100f157806306fdde0314610121578063095ea7b31461013f57806318160ddd1461016f57806323b872dd1461018d5780633092afd5146101bd575b600080fd5b61010b60048036038101906101069190610fa1565b610319565b6040516101189190611030565b60405180910390f35b61012961041e565b604051610136919061104b565b60405180910390f35b61015960048036038101906101549190610f65565b6104ac565b6040516101669190611030565b60405180910390f35b610177610630565b604051610184919061106d565b60405180910390f35b6101a760048036038101906101a29190610f16565b610636565b6040516101b49190611030565b60405180910390f35b6101d760048036038101906101d29190610eb1565b610948565b6040516101e49190611030565b60405180910390f35b6101f5610a3a565b6040516102029190611088565b60405180910390f35b61022560048036038101906102209190610f65565b610a4d565b6040516102329190611030565b60405180910390f35b61025560048036038101906102509190610eb1565b610b83565b604051610262919061106d565b60405180910390f35b610273610b9b565b604051610280919061104b565b60405180910390f35b6102a3600480360381019061029e9190610eb1565b610c29565b6040516102b09190611030565b60405180910390f35b6102d360048036038101906102ce9190610f65565b610ce4565b6040516102e09190611030565b60405180910390f35b61030360048036038101906102fe9190610eda565b610e4d565b604051610310919061106d565b60405180910390f35b600063c6bb4b707c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561036e5760019050610419565b63449a52f87c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156103c15760019050610419565b6301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156104145760019050610419565b600090505b919050565b6002805461042b906111fd565b80601f0160208091040260200160405190810160405280929190818152602001828054610457906111fd565b80156104a45780601f10610479576101008083540402835291602001916104a4565b820191906000526020600020905b81548152906001019060200180831161048757829003601f168201915b505050505081565b600080821115610540576000600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541461053f57600080fd5b5b81600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161061e919061106d565b60405180910390a36001905092915050565b60055481565b600081600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156106c157600080fd5b81600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561070d57600080fd5b81600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546107959190611115565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546108649190611115565b9250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546108ba91906110bf565b925050819055503373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167f5f7542858008eeb041631f30e6109ae94b83a58e9a58261dd2c42c508850f93985604051610935919061106d565b60405180910390a4600190509392505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806109d057508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6109d957600080fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600460009054906101000a900460ff1681565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610aa557600080fd5b81600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610af491906110bf565b925050819055508160056000828254610b0d91906110bf565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f884604051610b71919061106d565b60405180910390a36001905092915050565b60066020528060005260406000206000915090505481565b60038054610ba8906111fd565b80601f0160208091040260200160405190810160405280929190818152602001828054610bd4906111fd565b8015610c215780601f10610bf657610100808354040283529160200191610c21565b820191906000526020600020905b815481529060010190602001808311610c0457829003601f168201915b505050505081565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c8457600080fd5b60018060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600081600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610d3257600080fd5b81600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610d819190611115565b9250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610dd791906110bf565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610e3b919061106d565b60405180910390a36001905092915050565b6007602052816000526040600020602052806000526040600020600091509150505481565b600081359050610e818161129e565b92915050565b600081359050610e96816112b5565b92915050565b600081359050610eab816112cc565b92915050565b600060208284031215610ec357600080fd5b6000610ed184828501610e72565b91505092915050565b60008060408385031215610eed57600080fd5b6000610efb85828601610e72565b9250506020610f0c85828601610e72565b9150509250929050565b600080600060608486031215610f2b57600080fd5b6000610f3986828701610e72565b9350506020610f4a86828701610e72565b9250506040610f5b86828701610e9c565b9150509250925092565b60008060408385031215610f7857600080fd5b6000610f8685828601610e72565b9250506020610f9785828601610e9c565b9150509250929050565b600060208284031215610fb357600080fd5b6000610fc184828501610e87565b91505092915050565b610fd38161115b565b82525050565b6000610fe4826110a3565b610fee81856110ae565b9350610ffe8185602086016111ca565b6110078161128d565b840191505092915050565b61101b816111b3565b82525050565b61102a816111bd565b82525050565b60006020820190506110456000830184610fca565b92915050565b600060208201905081810360008301526110658184610fd9565b905092915050565b60006020820190506110826000830184611012565b92915050565b600060208201905061109d6000830184611021565b92915050565b600081519050919050565b600082825260208201905092915050565b60006110ca826111b3565b91506110d5836111b3565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561110a5761110961122f565b5b828201905092915050565b6000611120826111b3565b915061112b836111b3565b92508282101561113e5761113d61122f565b5b828203905092915050565b600061115482611193565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b838110156111e85780820151818401526020810190506111cd565b838111156111f7576000848401525b50505050565b6000600282049050600182168061121557607f821691505b602082108114156112295761122861125e565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b6112a781611149565b81146112b257600080fd5b50565b6112be81611167565b81146112c957600080fd5b50565b6112d5816111b3565b81146112e057600080fd5b5056fea264697066735822122081dda93f8f62cdd00d5a28d40736a4d2ce80f280f7c878ee8bc8ac6980493dbe64736f6c63430008040033 +\ No newline at end of file diff --git a/solidity/GiftableToken.json b/solidity/GiftableToken.json @@ -1 +1 @@ -[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"mintTo","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"removeMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] +[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_minter","type":"address"},{"indexed":true,"internalType":"address","name":"_beneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"mintTo","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"removeMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/solidity/GiftableToken.sol b/solidity/GiftableToken.sol @@ -82,13 +82,16 @@ contract GiftableToken { // Implements ERC20 function approve(address _spender, uint256 _value) public returns (bool) { - allowance[msg.sender][_spender] += _value; + if (_value > 0) { + require(allowance[msg.sender][_spender] == 0); + } + allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } // Implements EIP165 - function supportsInterface(bytes4 _sum) { + function supportsInterface(bytes4 _sum) public returns (bool) { if (_sum == 0xc6bb4b70) { // ERC20 return true; }