commit e332fc71a50482505a48560f00aaa7b7f40ddb9f
parent af77c938219ae28d756d2aacb6f01da01d56bb99
Author: lash <dev@holbrook.no>
Date: Sat, 25 Mar 2023 13:49:56 +0000
Reduce to pure ERC173
Diffstat:
7 files changed, 10 insertions(+), 163 deletions(-)
diff --git a/python/CHANGELOG b/python/CHANGELOG
@@ -1,3 +1,5 @@
+- 0.1.0
+ * Remove code outside ERC173 interface
- 0.0.5
* Enable finalization of ownership transfer
- 0.0.4
diff --git a/python/eth_owned/__init__.py b/python/eth_owned/__init__.py
@@ -1,2 +1,2 @@
-from .owned import EIP173, Owned, Owned
+from .owned import ERC173
from eth_owned.data import data_dir
diff --git a/python/eth_owned/owned.py b/python/eth_owned/owned.py
@@ -17,7 +17,7 @@ from chainlib.eth.tx import (
)
from chainlib.eth.constant import ZERO_ADDRESS
-class EIP173(TxFactory):
+class ERC173(TxFactory):
def transfer_ownership(self, contract_address, sender_address, new_owner_address, final=False, tx_format=TxFormat.JSONRPC):
enc = ABIContractEncoder()
@@ -52,27 +52,3 @@ class EIP173(TxFactory):
@classmethod
def parse_owner(self, v):
return abi_decode_single(ABIContractType.ADDRESS, v)
-
-
-class Owned(EIP173):
-
- def accept_ownership(self, contract_address, sender_address, tx_format=TxFormat.JSONRPC):
- enc = ABIContractEncoder()
- enc.method('acceptOwnership')
- 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)
- return tx
-
-
- def take_ownership(self, contract_address, sender_address, resource_address, tx_format=TxFormat.JSONRPC):
- enc = ABIContractEncoder()
- enc.method('takeOwnership')
- enc.typ(ABIContractType.ADDRESS)
- enc.address(resource_address)
- 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)
- return tx
diff --git a/python/eth_owned/unittest/base.py b/python/eth_owned/unittest/base.py
@@ -13,8 +13,7 @@ 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
+from eth_owned import ERC173
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
diff --git a/python/eth_owned/unittest/interface.py b/python/eth_owned/unittest/interface.py
@@ -15,10 +15,7 @@ from chainlib.eth.tx import (
from hexathon import strip_0x
# local imports
-from eth_owned.owned import (
- EIP173,
- Owned,
- )
+from eth_owned.owned import ERC173
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
@@ -29,7 +26,7 @@ script_dir = os.path.realpath(os.path.dirname(__file__))
class TestInterface: #(EthTesterCase):
def test_owned(self):
- c = EIP173(self.chain_spec)
+ c = ERC173(self.chain_spec)
o = c.owner(self.address, sender_address=self.accounts[0])
r = self.conn.do(o)
owner = c.parse_owner(r)
@@ -39,7 +36,7 @@ class TestInterface: #(EthTesterCase):
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)
+ c = ERC173(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)
@@ -48,7 +45,7 @@ class TestInterface: #(EthTesterCase):
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)
+ c = ERC173(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)
diff --git a/python/setup.cfg b/python/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = eth-owned
-version = 0.0.6
+version = 0.1.0
description = EIP 173 interface and tools
author = Louis Holbrook
author_email = dev@holbrook.no
diff --git a/python/tests/test_void.py b/python/tests/test_void.py
@@ -1,127 +0,0 @@
-# standard imports
-import os
-import unittest
-import json
-import logging
-
-# external imports
-from chainlib.eth.unittest.ethtester import EthTesterCase
-from chainlib.connection import RPCConnection
-from chainlib.eth.address import to_checksum_address
-from chainlib.eth.nonce import RPCNonceOracle
-from chainlib.eth.tx import (
- receipt,
- transaction,
- TxFormat,
- TxFactory,
- )
-from chainlib.eth.contract import (
- abi_decode_single,
- ABIContractType,
- )
-from chainlib.eth.contract import (
- ABIContractEncoder,
- )
-from hexathon import (
- add_0x,
- strip_0x,
- )
-
-# local imports
-from eth_owned.void import VoidOwner
-from eth_owned.owned import Owned
-from eth_owned import data_dir
-
-logging.basicConfig(level=logging.DEBUG)
-logg = logging.getLogger()
-
-testdir = os.path.dirname(__file__)
-
-
-class Test(EthTesterCase):
-
-
- def setUp(self):
- super(Test, self).setUp()
- self.conn = RPCConnection.connect(self.chain_spec, 'default')
- nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
- self.o = VoidOwner(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
- (tx_hash_hex, o) = self.o.constructor(self.accounts[0])
- 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']
-
- f = open(os.path.join(data_dir, 'Owned.bin'), 'r')
- b = 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, b)
- (tx_hash_hex, o) = txf.build(tx)
- r = self.conn.do(o)
-
- o = receipt(tx_hash_hex)
- r = self.conn.do(o)
- self.owned_demo_address = r['contract_address']
-
-
- def test_accept(self):
- nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
- txf = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
-
- c = Owned(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
- (tx_hash_hex, o) = c.transfer_ownership(self.owned_demo_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)
-
- nonce_oracle = RPCNonceOracle(self.accounts[1], self.conn)
- c = Owned(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
- (tx_hash_hex, o) = c.accept_ownership(self.owned_demo_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.owned_demo_address, sender_address=self.accounts[0])
- r = self.conn.do(o)
- owner_address = abi_decode_single(ABIContractType.ADDRESS, r)
- self.assertEqual(owner_address, strip_0x(self.accounts[1]))
-
-
- def test_void(self):
- nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
- txf = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
-
- c = Owned(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
- (tx_hash_hex, o) = c.transfer_ownership(self.owned_demo_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)
-
- (tx_hash_hex, o) = c.take_ownership(self.address, self.accounts[0], self.owned_demo_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.owned_demo_address, sender_address=self.accounts[0])
- r = self.conn.do(o)
-
- owner_address = abi_decode_single(ABIContractType.ADDRESS, r)
- self.assertEqual(owner_address, strip_0x(self.address))
-
-
-if __name__ == '__main__':
- unittest.main()