eth-owned

EIP-173 interface and tools for chainlib-eth
git clone git://holbrook.no/eth-owned.git
Log | Files | Refs

commit af77c938219ae28d756d2aacb6f01da01d56bb99
parent 46138507d584e798087439bf73f6958aba0f40b3
Author: lash <dev@holbrook.no>
Date:   Tue, 28 Feb 2023 20:37:00 +0000

Simplify default contract, add unittest module

Diffstat:
Mpython/eth_owned/__init__.py | 2+-
Mpython/eth_owned/data/Owned.bin | 4++--
Apython/eth_owned/data/OwnedSimple.bin | 2++
Apython/eth_owned/data/OwnedSimple.json | 1+
Mpython/eth_owned/data/VoidOwner.bin | 4++--
Apython/eth_owned/unittest/__init__.py | 2++
Apython/eth_owned/unittest/base.py | 46++++++++++++++++++++++++++++++++++++++++++++++
Apython/eth_owned/unittest/interface.py | 132+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpython/setup.cfg | 7++++---
Mpython/tests/test_owned.py | 143+++----------------------------------------------------------------------------
Msolidity/Makefile | 11+++++++++--
Asolidity/OwnedSimple.sol | 22++++++++++++++++++++++
12 files changed, 227 insertions(+), 149 deletions(-)

diff --git a/python/eth_owned/__init__.py b/python/eth_owned/__init__.py @@ -1,2 +1,2 @@ -from .owned import EIP173 +from .owned import EIP173, Owned, Owned from eth_owned.data import data_dir diff --git a/python/eth_owned/data/Owned.bin b/python/eth_owned/data/Owned.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506105c1806100606000396000f3fe608060405234801561001057600080fd5b5060043610610069576000357c010000000000000000000000000000000000000000000000000000000090048063069b17751461006e57806379ba50971461009e5780638da5cb5b146100bc578063f2fde38b146100da575b600080fd5b610088600480360381019061008391906104a5565b61010a565b60405161009591906104ed565b60405180910390f35b6100a66101c5565b6040516100b391906104ed565b60405180910390f35b6100c461035f565b6040516100d19190610517565b60405180910390f35b6100f460048036038101906100ef91906104a5565b610383565b60405161010191906104ed565b60405180910390f35b60003073ffffffffffffffffffffffffffffffffffffffff1663f2fde38b836040518263ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016101619190610517565b6020604051808303816000875af1158015610180573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101a4919061055e565b5060018060146101000a81548160ff021916908360ff160217905550919050565b6000803373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461022257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360018060149054906101000a900460ff1660ff1603610357576002600160146101000a81548160ff021916908360ff1602179055505b600191505090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60003373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146103dd57600080fd5b6002600160149054906101000a900460ff1660ff16106103fc57600080fd5b81600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061047282610447565b9050919050565b61048281610467565b811461048d57600080fd5b50565b60008135905061049f81610479565b92915050565b6000602082840312156104bb576104ba610442565b5b60006104c984828501610490565b91505092915050565b60008115159050919050565b6104e7816104d2565b82525050565b600060208201905061050260008301846104de565b92915050565b61051181610467565b82525050565b600060208201905061052c6000830184610508565b92915050565b61053b816104d2565b811461054657600080fd5b50565b60008151905061055881610532565b92915050565b60006020828403121561057457610573610442565b5b600061058284828501610549565b9150509291505056fea2646970667358221220d8ee713b16e7ffab13ce45a1c39c02a8ab7914c4620a7c5b7aba5f1e3a8ef3e464736f6c63430008110033 -\ No newline at end of file +608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506105c1806100606000396000f3fe608060405234801561001057600080fd5b5060043610610069576000357c010000000000000000000000000000000000000000000000000000000090048063069b17751461006e57806379ba50971461009e5780638da5cb5b146100bc578063f2fde38b146100da575b600080fd5b610088600480360381019061008391906104a5565b61010a565b60405161009591906104ed565b60405180910390f35b6100a66101c5565b6040516100b391906104ed565b60405180910390f35b6100c461035f565b6040516100d19190610517565b60405180910390f35b6100f460048036038101906100ef91906104a5565b610383565b60405161010191906104ed565b60405180910390f35b60003073ffffffffffffffffffffffffffffffffffffffff1663f2fde38b836040518263ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016101619190610517565b6020604051808303816000875af1158015610180573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101a4919061055e565b5060018060146101000a81548160ff021916908360ff160217905550919050565b6000803373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461022257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360018060149054906101000a900460ff1660ff1603610357576002600160146101000a81548160ff021916908360ff1602179055505b600191505090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60003373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146103dd57600080fd5b6002600160149054906101000a900460ff1660ff16106103fc57600080fd5b81600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061047282610447565b9050919050565b61048281610467565b811461048d57600080fd5b50565b60008135905061049f81610479565b92915050565b6000602082840312156104bb576104ba610442565b5b60006104c984828501610490565b91505092915050565b60008115159050919050565b6104e7816104d2565b82525050565b600060208201905061050260008301846104de565b92915050565b61051181610467565b82525050565b600060208201905061052c6000830184610508565b92915050565b61053b816104d2565b811461054657600080fd5b50565b60008151905061055881610532565b92915050565b60006020828403121561057457610573610442565b5b600061058284828501610549565b9150509291505056fea2646970667358221220d69d7691687d7a6bcec73e317e394174925c2dcdda243139fd9952022ff9b1e064736f6c63430008120033 +\ No newline at end of file diff --git a/python/eth_owned/data/OwnedSimple.bin b/python/eth_owned/data/OwnedSimple.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061028f806100606000396000f3fe608060405234801561001057600080fd5b5060043610610053576000357c0100000000000000000000000000000000000000000000000000000000900480638da5cb5b14610058578063f2fde38b14610076575b600080fd5b6100606100a6565b60405161006d91906101aa565b60405180910390f35b610090600480360381019061008b91906101f6565b6100ca565b60405161009d919061023e565b60405180910390f35b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60003373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461012457600080fd5b816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061019482610169565b9050919050565b6101a481610189565b82525050565b60006020820190506101bf600083018461019b565b92915050565b600080fd5b6101d381610189565b81146101de57600080fd5b50565b6000813590506101f0816101ca565b92915050565b60006020828403121561020c5761020b6101c5565b5b600061021a848285016101e1565b91505092915050565b60008115159050919050565b61023881610223565b82525050565b6000602082019050610253600083018461022f565b9291505056fea264697066735822122092b047ab39e2b913b88dcd90b915bcb50f03bed936e808dbf79d8b80e32fccec64736f6c63430008120033 +\ No newline at end of file diff --git a/python/eth_owned/data/OwnedSimple.json b/python/eth_owned/data/OwnedSimple.json @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"_newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/python/eth_owned/data/VoidOwner.bin b/python/eth_owned/data/VoidOwner.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b506107ea806100206000396000f3fe608060405234801561001057600080fd5b5060043610610053576000357c01000000000000000000000000000000000000000000000000000000009004806301ffc9a7146100585780636b57833914610088575b600080fd5b610072600480360381019061006d91906104c0565b6100b8565b60405161007f9190610508565b60405180910390f35b6100a2600480360381019061009d9190610581565b610168565b6040516100af9190610508565b60405180910390f35b6000636b5783397c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19160361010c5760019050610163565b6301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19160361015e5760019050610163565b600090505b919050565b600080606060008473ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f79ba5097000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051610216919061061f565b6000604051808303816000865af19150503d8060008114610253576040519150601f19603f3d011682016040523d82523d6000602084013e610258565b606091505b508093508194505050826102a1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161029890610693565b60405180910390fd5b8473ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f8da5cb5b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051610348919061061f565b6000604051808303816000865af19150503d8060008114610385576040519150601f19603f3d011682016040523d82523d6000602084013e61038a565b606091505b508093508194505050826103d3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103ca906106ff565b60405180910390fd5b818060200190518101906103e7919061075d565b90508073ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff161461042157600080fd5b7fdc3c82f4776932041f15a08f769aadd6ed44c2a975e64bbf0fde8cf812f8b6b8856040516104509190610799565b60405180910390a1829350505050919050565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61049d81610468565b81146104a857600080fd5b50565b6000813590506104ba81610494565b92915050565b6000602082840312156104d6576104d5610463565b5b60006104e4848285016104ab565b91505092915050565b60008115159050919050565b610502816104ed565b82525050565b600060208201905061051d60008301846104f9565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061054e82610523565b9050919050565b61055e81610543565b811461056957600080fd5b50565b60008135905061057b81610555565b92915050565b60006020828403121561059757610596610463565b5b60006105a58482850161056c565b91505092915050565b600081519050919050565b600081905092915050565b60005b838110156105e25780820151818401526020810190506105c7565b60008484015250505050565b60006105f9826105ae565b61060381856105b9565b93506106138185602086016105c4565b80840191505092915050565b600061062b82846105ee565b915081905092915050565b600082825260208201905092915050565b7f4552525f41434345505400000000000000000000000000000000000000000000600082015250565b600061067d600a83610636565b915061068882610647565b602082019050919050565b600060208201905081810360008301526106ac81610670565b9050919050565b7f4552525f494e5445524641434500000000000000000000000000000000000000600082015250565b60006106e9600d83610636565b91506106f4826106b3565b602082019050919050565b60006020820190508181036000830152610718816106dc565b9050919050565b600061072a82610523565b9050919050565b61073a8161071f565b811461074557600080fd5b50565b60008151905061075781610731565b92915050565b60006020828403121561077357610772610463565b5b600061078184828501610748565b91505092915050565b61079381610543565b82525050565b60006020820190506107ae600083018461078a565b9291505056fea2646970667358221220b22c68a3519c208498bb3b4cffe66bbc0f3b4c799354c38acdf9554483b9ce3964736f6c63430008110033 -\ No newline at end of file +608060405234801561001057600080fd5b506107ea806100206000396000f3fe608060405234801561001057600080fd5b5060043610610053576000357c01000000000000000000000000000000000000000000000000000000009004806301ffc9a7146100585780636b57833914610088575b600080fd5b610072600480360381019061006d91906104c0565b6100b8565b60405161007f9190610508565b60405180910390f35b6100a2600480360381019061009d9190610581565b610168565b6040516100af9190610508565b60405180910390f35b6000636b5783397c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19160361010c5760019050610163565b6301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19160361015e5760019050610163565b600090505b919050565b600080606060008473ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f79ba5097000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051610216919061061f565b6000604051808303816000865af19150503d8060008114610253576040519150601f19603f3d011682016040523d82523d6000602084013e610258565b606091505b508093508194505050826102a1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161029890610693565b60405180910390fd5b8473ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f8da5cb5b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051610348919061061f565b6000604051808303816000865af19150503d8060008114610385576040519150601f19603f3d011682016040523d82523d6000602084013e61038a565b606091505b508093508194505050826103d3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103ca906106ff565b60405180910390fd5b818060200190518101906103e7919061075d565b90508073ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff161461042157600080fd5b7fdc3c82f4776932041f15a08f769aadd6ed44c2a975e64bbf0fde8cf812f8b6b8856040516104509190610799565b60405180910390a1829350505050919050565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61049d81610468565b81146104a857600080fd5b50565b6000813590506104ba81610494565b92915050565b6000602082840312156104d6576104d5610463565b5b60006104e4848285016104ab565b91505092915050565b60008115159050919050565b610502816104ed565b82525050565b600060208201905061051d60008301846104f9565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061054e82610523565b9050919050565b61055e81610543565b811461056957600080fd5b50565b60008135905061057b81610555565b92915050565b60006020828403121561059757610596610463565b5b60006105a58482850161056c565b91505092915050565b600081519050919050565b600081905092915050565b60005b838110156105e25780820151818401526020810190506105c7565b60008484015250505050565b60006105f9826105ae565b61060381856105b9565b93506106138185602086016105c4565b80840191505092915050565b600061062b82846105ee565b915081905092915050565b600082825260208201905092915050565b7f4552525f41434345505400000000000000000000000000000000000000000000600082015250565b600061067d600a83610636565b915061068882610647565b602082019050919050565b600060208201905081810360008301526106ac81610670565b9050919050565b7f4552525f494e5445524641434500000000000000000000000000000000000000600082015250565b60006106e9600d83610636565b91506106f4826106b3565b602082019050919050565b60006020820190508181036000830152610718816106dc565b9050919050565b600061072a82610523565b9050919050565b61073a8161071f565b811461074557600080fd5b50565b60008151905061075781610731565b92915050565b60006020828403121561077357610772610463565b5b600061078184828501610748565b91505092915050565b61079381610543565b82525050565b60006020820190506107ae600083018461078a565b9291505056fea26469706673582212200a7add836ee15d593967ec6abe3381c9a1e395ba95b284261e23c2dc5832add864736f6c63430008120033 +\ No newline at end of file diff --git a/python/eth_owned/unittest/__init__.py b/python/eth_owned/unittest/__init__.py @@ -0,0 +1,2 @@ +from .base import TestOwned +from .interface import TestInterface diff --git a/python/eth_owned/unittest/base.py b/python/eth_owned/unittest/base.py @@ -0,0 +1,46 @@ +# standard imports +import unittest +import os +import logging + +# external imports +from chainlib.eth.unittest.ethtester import EthTesterCase +from chainlib.eth.nonce import RPCNonceOracle +from chainlib.eth.gas import OverrideGasOracle +from chainlib.connection import RPCConnection +from chainlib.eth.tx import TxFactory +from chainlib.eth.tx import receipt +from hexathon import strip_0x + +# local imports +from eth_owned.owned import EIP173 +from eth_owned.owned import Owned + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + +script_dir = os.path.realpath(os.path.dirname(__file__)) + + +class TestOwned(EthTesterCase): + + def setUp(self): + super(TestOwned, self).setUp() + self.conn = RPCConnection.connect(self.chain_spec, 'default') + nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) + + f = open(os.path.join(script_dir, '..', 'data', 'OwnedSimple.bin')) + code = f.read() + f.close() + + txf = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + tx = txf.template(self.accounts[0], None, use_nonce=True) + tx = txf.set_code(tx, code) + (tx_hash_hex, o) = txf.build(tx) + + r = self.conn.do(o) + logg.debug('Owned test conrtact published with hash {}'.format(r)) + + o = receipt(tx_hash_hex) + r = self.conn.do(o) + self.address = r['contract_address'] diff --git a/python/eth_owned/unittest/interface.py b/python/eth_owned/unittest/interface.py @@ -0,0 +1,132 @@ +# standard imports +import unittest +import os +import logging + +# external imports +from chainlib.eth.unittest.ethtester import EthTesterCase +from chainlib.eth.nonce import RPCNonceOracle +from chainlib.eth.gas import OverrideGasOracle +from chainlib.connection import RPCConnection +from chainlib.eth.tx import ( + TxFactory, + receipt, + ) +from hexathon import strip_0x + +# local imports +from eth_owned.owned import ( + EIP173, + Owned, + ) + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + +script_dir = os.path.realpath(os.path.dirname(__file__)) + + +class TestInterface: #(EthTesterCase): + + def test_owned(self): + c = EIP173(self.chain_spec) + o = c.owner(self.address, sender_address=self.accounts[0]) + r = self.conn.do(o) + owner = c.parse_owner(r) + self.assertEqual(owner, strip_0x(self.accounts[0])) + + + def test_transfer_ownership(self): + nonce_oracle = RPCNonceOracle(self.accounts[2], self.conn) + gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn) + c = EIP173(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) + (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[2], self.accounts[1]) + r = self.conn.do(o) + + o = receipt(tx_hash_hex) + r = self.conn.do(o) + self.assertEqual(r['status'], 0) + + nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) + c = EIP173(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) + (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1]) + r = self.conn.do(o) + + o = receipt(tx_hash_hex) + r = self.conn.do(o) + self.assertEqual(r['status'], 1) + + o = c.owner(self.address, sender_address=self.accounts[0]) + r = self.conn.do(o) + owner = c.parse_owner(r) + self.assertEqual(owner, strip_0x(self.accounts[1])) + + +# def test_accept_ownership(self): +# nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) +# gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn) +# c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) +# (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1]) +# r = self.conn.do(o) +# +# nonce_oracle = RPCNonceOracle(self.accounts[2], self.conn) +# c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) +# (tx_hash_hex, o) = c.accept_ownership(self.address, self.accounts[2]) +# r = self.conn.do(o) +# +# o = receipt(tx_hash_hex) +# r = self.conn.do(o) +# self.assertEqual(r['status'], 0) +# +# nonce_oracle = RPCNonceOracle(self.accounts[1], self.conn) +# c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) +# (tx_hash_hex, o) = c.accept_ownership(self.address, self.accounts[1]) +# r = self.conn.do(o) +# +# o = receipt(tx_hash_hex) +# r = self.conn.do(o) +# self.assertEqual(r['status'], 1) +# +# o = c.owner(self.address, sender_address=self.accounts[0]) +# r = self.conn.do(o) +# owner = c.parse_owner(r) +# self.assertEqual(owner, strip_0x(self.accounts[1])) +# +# +# def test_take_ownership(self): +# nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) +# gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn) +# c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) +# (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.address) +# r = self.conn.do(o) +# +# (tx_hash_hex, o) = c.take_ownership(self.address, self.accounts[0], self.address) +# r = self.conn.do(o) +# +# o = receipt(tx_hash_hex) +# r = self.conn.do(o) +# self.assertEqual(r['status'], 1) +# +# o = c.owner(self.address, sender_address=self.accounts[0]) +# r = self.conn.do(o) +# owner = c.parse_owner(r) +# self.assertEqual(owner, strip_0x(self.address)) +# +# +# def test_ownership_final(self): +# nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) +# gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn) +# c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) +# (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1], final=True) +# r = self.conn.do(o) +# +# c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) +# (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1], final=True) +# r = self.conn.do(o) +# o = receipt(tx_hash_hex) +# r = self.conn.do(o) +# self.assertEqual(r['status'], 0) + + +if __name__ == '__main__': + unittest.main() diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-owned -version = 0.0.5 +version = 0.0.6 description = EIP 173 interface and tools author = Louis Holbrook author_email = dev@holbrook.no @@ -27,6 +27,7 @@ python_requires = >= 3.6 packages = eth_owned eth_owned.data + eth_owned.unittest eth_owned.runnable [options.extras_require] @@ -42,6 +43,6 @@ testing = [options.entry_points] console_scripts = - eth-owner-void-deploy = eth_owned.runnable.void_deploy:main - eth-owner-void = eth_owned.runnable.void:main + #eth-owner-void-deploy = eth_owned.runnable.void_deploy:main + #eth-owner-void = eth_owned.runnable.void:main eth-owner = eth_owned.runnable.owner:main diff --git a/python/tests/test_owned.py b/python/tests/test_owned.py @@ -1,148 +1,13 @@ # standard imports import unittest -import os -import logging - -# external imports -from chainlib.eth.unittest.ethtester import EthTesterCase -from chainlib.eth.nonce import RPCNonceOracle -from chainlib.eth.gas import OverrideGasOracle -from chainlib.connection import RPCConnection -from chainlib.eth.tx import ( - TxFactory, - receipt, - ) -from hexathon import strip_0x # local imports -from eth_owned.owned import ( - EIP173, - Owned, - ) - -logging.basicConfig(level=logging.DEBUG) -logg = logging.getLogger() - -script_dir = os.path.realpath(os.path.dirname(__file__)) - - -class TestOwned(EthTesterCase): - - def setUp(self): - super(TestOwned, self).setUp() - self.conn = RPCConnection.connect(self.chain_spec, 'default') - nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) - - f = open(os.path.join(script_dir, 'testdata', 'Owned.bin')) - code = f.read() - f.close() - - txf = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) - tx = txf.template(self.accounts[0], None, use_nonce=True) - tx = txf.set_code(tx, code) - (tx_hash_hex, o) = txf.build(tx) - - r = self.conn.do(o) - logg.debug('deployed with hash {}'.format(r)) - - o = receipt(tx_hash_hex) - r = self.conn.do(o) - self.address = r['contract_address'] - - - def test_owned(self): - c = EIP173(self.chain_spec) - o = c.owner(self.address, sender_address=self.accounts[0]) - r = self.conn.do(o) - owner = c.parse_owner(r) - self.assertEqual(owner, strip_0x(self.accounts[0])) - - - def test_transfer_ownership(self): - nonce_oracle = RPCNonceOracle(self.accounts[2], self.conn) - gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn) - c = EIP173(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) - (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[2], self.accounts[1]) - r = self.conn.do(o) - - o = receipt(tx_hash_hex) - r = self.conn.do(o) - self.assertEqual(r['status'], 0) - - nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) - c = EIP173(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) - (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1]) - r = self.conn.do(o) - - o = receipt(tx_hash_hex) - r = self.conn.do(o) - self.assertEqual(r['status'], 1) - - - def test_accept_ownership(self): - nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) - gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn) - c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) - (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1]) - r = self.conn.do(o) - - nonce_oracle = RPCNonceOracle(self.accounts[2], self.conn) - c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) - (tx_hash_hex, o) = c.accept_ownership(self.address, self.accounts[2]) - r = self.conn.do(o) - - o = receipt(tx_hash_hex) - r = self.conn.do(o) - self.assertEqual(r['status'], 0) - - nonce_oracle = RPCNonceOracle(self.accounts[1], self.conn) - c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) - (tx_hash_hex, o) = c.accept_ownership(self.address, self.accounts[1]) - r = self.conn.do(o) - - o = receipt(tx_hash_hex) - r = self.conn.do(o) - self.assertEqual(r['status'], 1) - - o = c.owner(self.address, sender_address=self.accounts[0]) - r = self.conn.do(o) - owner = c.parse_owner(r) - self.assertEqual(owner, strip_0x(self.accounts[1])) - - - def test_take_ownership(self): - nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) - gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn) - c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) - (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.address) - r = self.conn.do(o) - - (tx_hash_hex, o) = c.take_ownership(self.address, self.accounts[0], self.address) - r = self.conn.do(o) - - o = receipt(tx_hash_hex) - r = self.conn.do(o) - self.assertEqual(r['status'], 1) - - o = c.owner(self.address, sender_address=self.accounts[0]) - r = self.conn.do(o) - owner = c.parse_owner(r) - self.assertEqual(owner, strip_0x(self.address)) - +from eth_owned.unittest import TestOwned as TestOwnedBase +from eth_owned.unittest import TestInterface - def test_ownership_final(self): - nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) - gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn) - c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) - (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1], final=True) - r = self.conn.do(o) - c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) - (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1], final=True) - r = self.conn.do(o) - o = receipt(tx_hash_hex) - r = self.conn.do(o) - self.assertEqual(r['status'], 0) +class TestOwned(TestOwnedBase, TestInterface): + pass if __name__ == '__main__': diff --git a/solidity/Makefile b/solidity/Makefile @@ -7,12 +7,19 @@ all: $(SOLC) Owned.sol --abi --evm-version byzantium | awk 'NR>3' > Owned.json $(SOLC) Owned.sol --bin --evm-version byzantium | awk 'NR>3' > Owned.bin truncate -s -1 Owned.bin + $(SOLC) OwnedSimple.sol --abi --evm-version byzantium | awk 'NR>3' > OwnedSimple.json + $(SOLC) OwnedSimple.sol --bin --evm-version byzantium | awk 'NR>3' > OwnedSimple.bin + truncate -s -1 OwnedSimple.bin test: all python ../python/tests/test_basic.py install: all - cp -v VoidOwner.{json,bin} ../python/eth_owned/data/ - cp -v Owned.{json,bin} ../python/eth_owned/data/ + cp -v VoidOwner.json ../python/eth_owned/data/ + cp -v VoidOwner.bin ../python/eth_owned/data/ + cp -v Owned.json ../python/eth_owned/data/ + cp -v Owned.bin ../python/eth_owned/data/ + cp -v OwnedSimple.json ../python/eth_owned/data/ + cp -v OwnedSimple.bin ../python/eth_owned/data/ .PHONY: test install diff --git a/solidity/OwnedSimple.sol b/solidity/OwnedSimple.sol @@ -0,0 +1,22 @@ +pragma solidity >= 0.6.11; + +// SPDX-License-Identifier: GPL-3.0-or-later + +contract Owned { + + // EIP173 + address public owner; + + // EIP173 + event OwnershipTransferred(address indexed _previousOwner, address indexed _newOwner); + + constructor() public { + owner = msg.sender; + } + + // EIP173 + function transferOwnership(address _newOwner) public returns (bool) { + require(owner == msg.sender); + owner = _newOwner; + } +}