From 9e3a07f79347ae02ce560323d661008d212f1471 Mon Sep 17 00:00:00 2001 From: Agnieszka Date: Tue, 11 Oct 2016 18:08:18 +0200 Subject: [PATCH 1/4] use defaultAccount instead of coinbase for default `from` value in transactions --- web3/contract.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3/contract.py b/web3/contract.py index 0aedac6..7a605c1 100644 --- a/web3/contract.py +++ b/web3/contract.py @@ -434,7 +434,7 @@ class Contract(object): if self.address is not None: transact_transaction.setdefault('to', self.address) - transact_transaction.setdefault('from', self.web3.eth.coinbase) + transact_transaction.setdefault('from', self.web3.eth.defaultAccount) if 'to' not in transact_transaction: if isinstance(self, type): From ee37909337b1537588980195a289e928a24111c9 Mon Sep 17 00:00:00 2001 From: Agnieszka Date: Wed, 12 Oct 2016 09:20:16 +0200 Subject: [PATCH 2/4] tests to make sure defaultAccount is used correctly --- .../test_contract_transact_interface.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/contracts/test_contract_transact_interface.py b/tests/contracts/test_contract_transact_interface.py index 514af18..cb0c8f5 100644 --- a/tests/contracts/test_contract_transact_interface.py +++ b/tests/contracts/test_contract_transact_interface.py @@ -63,6 +63,30 @@ def test_transacting_with_contract_with_arguments(web3_tester, assert final_value - initial_value == 5 +def test_deploy_when_default_account_is_different_than_coinbase(web3_tester, + STRING_CONTRACT): + web3_tester.eth.defaultAccount = web3_tester.eth.accounts[1] + assert web3_tester.eth.defaultAccount != web3_tester.eth.coinbase + + StringContract = web3_tester.eth.contract(**STRING_CONTRACT) + + deploy_txn = StringContract.deploy(args=["Caqalai"]) + deploy_receipt = wait_for_transaction_receipt(web3_tester, deploy_txn, 30) + assert deploy_receipt['from'] == web3_tester.eth.defaultAccount + + +def test_transact_when_default_account_is_different_than_coinbase(web3_tester, + math_contract, + transact_args, + transact_kwargs): + web3_tester.eth.defaultAccount = web3_tester.eth.accounts[1] + assert web3_tester.eth.defaultAccount != web3_tester.eth.coinbase + + txn_hash = math_contract.transact().increment(*transact_args, **transact_kwargs) + txn_receipt = web3_tester.eth.getTransactionReceipt(txn_hash) + assert txn_receipt['from'] == web3_tester.eth.defaultAccount + + def test_transacting_with_contract_with_string_argument(web3_tester, string_contract): # eth_abi will pass as raw bytes, no encoding # unless we encode ourselves From c32ec53e49a912cf1f214bc808bf67407218ab42 Mon Sep 17 00:00:00 2001 From: Agnieszka Date: Wed, 12 Oct 2016 09:20:37 +0200 Subject: [PATCH 3/4] removed a duplicate test --- tests/contracts/test_contract_transact_interface.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/contracts/test_contract_transact_interface.py b/tests/contracts/test_contract_transact_interface.py index cb0c8f5..3d208b0 100644 --- a/tests/contracts/test_contract_transact_interface.py +++ b/tests/contracts/test_contract_transact_interface.py @@ -99,19 +99,6 @@ def test_transacting_with_contract_with_string_argument(web3_tester, string_cont assert force_bytes(final_value) == force_bytes("ÄLÄMÖLÖ") -def test_transacting_with_contract_with_string_argument(web3_tester, string_contract): - - # eth_abi will pass as raw bytes, no encoding - # unless we encode ourselves - txn_hash = string_contract.transact().setValue(force_bytes("ÄLÄMÖLÖ")) - txn_receipt = web3_tester.eth.getTransactionReceipt(txn_hash) - assert txn_receipt is not None - - final_value = string_contract.call().getValue() - - assert force_bytes(final_value) == force_bytes("ÄLÄMÖLÖ") - - def test_transacting_with_contract_respects_explicit_gas(web3, STRING_CONTRACT, skip_if_testrpc, From 258714a5dd691b7c61256752af98b15998bfafda Mon Sep 17 00:00:00 2001 From: Agnieszka Date: Wed, 12 Oct 2016 09:50:20 +0200 Subject: [PATCH 4/4] fixed tests --- .../test_contract_transact_interface.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/contracts/test_contract_transact_interface.py b/tests/contracts/test_contract_transact_interface.py index 3d208b0..5c0d573 100644 --- a/tests/contracts/test_contract_transact_interface.py +++ b/tests/contracts/test_contract_transact_interface.py @@ -64,6 +64,7 @@ def test_transacting_with_contract_with_arguments(web3_tester, def test_deploy_when_default_account_is_different_than_coinbase(web3_tester, + wait_for_transaction, STRING_CONTRACT): web3_tester.eth.defaultAccount = web3_tester.eth.accounts[1] assert web3_tester.eth.defaultAccount != web3_tester.eth.coinbase @@ -71,20 +72,21 @@ def test_deploy_when_default_account_is_different_than_coinbase(web3_tester, StringContract = web3_tester.eth.contract(**STRING_CONTRACT) deploy_txn = StringContract.deploy(args=["Caqalai"]) - deploy_receipt = wait_for_transaction_receipt(web3_tester, deploy_txn, 30) - assert deploy_receipt['from'] == web3_tester.eth.defaultAccount + wait_for_transaction(web3_tester, deploy_txn) + txn_after = web3_tester.eth.getTransaction(deploy_txn) + assert txn_after['from'] == web3_tester.eth.defaultAccount def test_transact_when_default_account_is_different_than_coinbase(web3_tester, - math_contract, - transact_args, - transact_kwargs): + wait_for_transaction, + math_contract): web3_tester.eth.defaultAccount = web3_tester.eth.accounts[1] assert web3_tester.eth.defaultAccount != web3_tester.eth.coinbase - txn_hash = math_contract.transact().increment(*transact_args, **transact_kwargs) - txn_receipt = web3_tester.eth.getTransactionReceipt(txn_hash) - assert txn_receipt['from'] == web3_tester.eth.defaultAccount + txn_hash = math_contract.transact().increment() + wait_for_transaction(web3_tester, txn_hash) + txn_after = web3_tester.eth.getTransaction(txn_hash) + assert txn_after['from'] == web3_tester.eth.defaultAccount def test_transacting_with_contract_with_string_argument(web3_tester, string_contract):