Skip to content

Commit

Permalink
Merge pull request #116 from 4gn3s/fix_default_account_for_tx
Browse files Browse the repository at this point in the history
Closes #115 defaultAccount used as transaction from
  • Loading branch information
pipermerriam committed Oct 12, 2016
2 parents 9c5e329 + 258714a commit 791e653
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
31 changes: 22 additions & 9 deletions tests/contracts/test_contract_transact_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,33 @@ def test_transacting_with_contract_with_arguments(web3_tester,
assert final_value - initial_value == 5


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
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

final_value = string_contract.call().getValue()
StringContract = web3_tester.eth.contract(**STRING_CONTRACT)

assert force_bytes(final_value) == force_bytes("ÄLÄMÖLÖ")
deploy_txn = StringContract.deploy(args=["Caqalai"])
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_transacting_with_contract_with_string_argument(web3_tester, string_contract):
def test_transact_when_default_account_is_different_than_coinbase(web3_tester,
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()
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):
# eth_abi will pass as raw bytes, no encoding
# unless we encode ourselves
txn_hash = string_contract.transact().setValue(force_bytes("ÄLÄMÖLÖ"))
Expand Down
2 changes: 1 addition & 1 deletion web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def transact(self, transaction=None):

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):
Expand Down

0 comments on commit 791e653

Please sign in to comment.