commit e4f08d353404d029bf4b2f505bbdffa35e431cdc
parent 320c9fdde9ea20beacf417078d4fd5eece9c60f9
Author: nolash <dev@holbrook.no>
Date: Sat, 17 Apr 2021 11:22:22 +0200
Add test for accept, use owned methods instead of raw txfactory in void test
Diffstat:
2 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/python/eth_owner/owned.py b/python/eth_owner/owned.py
@@ -18,6 +18,7 @@ from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.jsonrpc import (
jsonrpc_template,
)
+from hexathon import add_0x
logg = logging.getLogger()
@@ -29,7 +30,7 @@ class Owned(TxFactory):
interfaces = None
- def owner(self, contract_address, idx, sender_address=ZERO_ADDRESS):
+ def owner(self, contract_address, sender_address=ZERO_ADDRESS):
o = jsonrpc_template()
o['method'] = 'eth_call'
enc = ABIContractEncoder()
@@ -53,7 +54,7 @@ class Owned(TxFactory):
return tx
- def accept_ownership(self, sender_address, contract_address, address, tx_format=TxFormat.JSONRPC):
+ def accept_ownership(self, sender_address, contract_address, tx_format=TxFormat.JSONRPC):
enc = ABIContractEncoder()
enc.method('acceptOwnership')
data = enc.get()
diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py
@@ -69,20 +69,40 @@ class Test(EthTesterCase):
self.owned_demo_address = r['contract_address']
- def test_takeover(self):
-
+ def test_accept(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
txf = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
- enc = ABIContractEncoder()
- enc.method('transferOwnership')
- enc.typ(ABIContractType.ADDRESS)
- enc.address(self.address)
- data = enc.get()
- tx = txf.template(self.accounts[0], self.owned_demo_address, use_nonce=True)
- tx = txf.set_code(tx, data)
- (tx_hash_hex, o) = txf.finalize(tx)
+ c = Owned(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash_hex, o) = c.transfer_ownership(self.accounts[0], 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)
+
+ 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.accounts[1], 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, 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.accounts[0], self.owned_demo_address, self.address)
r = self.conn.do(o)
o = receipt(tx_hash_hex)
@@ -98,14 +118,8 @@ class Test(EthTesterCase):
r = self.conn.do(o)
self.assertEqual(r['status'], 1)
- o = jsonrpc_template()
- o['method'] = 'eth_call'
- enc = ABIContractEncoder()
- enc.method('owner')
- data = add_0x(enc.get())
- tx = txf.template(self.accounts[0], self.owned_demo_address)
- tx = txf.set_code(tx, data)
- o['params'].append(txf.normalize(tx))
+ c = Owned(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ 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)