-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement and add web3.eth.signTransaction test to integration tests #1277
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,6 +196,23 @@ def test_eth_sign(self, web3, unlocked_account_dual_type): | |
) | ||
assert new_signature != signature | ||
|
||
def test_eth_signTransaction(self, web3, unlocked_account, geth_signed_tx=None): | ||
txn_params = { | ||
'from': unlocked_account, | ||
'to': unlocked_account, | ||
'value': 1, | ||
'gas': 21000, | ||
'gasPrice': web3.eth.gasPrice, | ||
'nonce': 0, | ||
} | ||
COINBASE_PK = '0x58d23b55bc9cdce1f18c2500f40ff4ab7245df9a89505e9b1fa4851f623d241d' | ||
result = web3.eth.signTransaction(txn_params) | ||
actual = web3.eth.account.signTransaction(txn_params, COINBASE_PK) | ||
if geth_signed_tx: | ||
assert result['raw'] == geth_signed_tx | ||
else: | ||
assert result['raw'] == actual.rawTransaction | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carver Any thoughts on a better test for this? I'm having trouble figuring out why the Also according to the spec the jsonrpc response should only include the raw signed transaction. However, both parity and geth also return the original tx params submitted in the request. What behavior do we want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it is Web3.py's job to enforce spec compliance, that is going to be a separate thing that clients start testing for. For now, we should probably be quite forgiving with what data is returned (with respect to allowing these extra fields and formatting them in the expected way) In the future, I could see it being reasonable for web3.py to even decode the transaction and populate these fields when the clients stop returning them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with ⬆️ |
||
|
||
def test_eth_sendTransaction_addr_checksum_required(self, web3, unlocked_account): | ||
non_checksum_addr = unlocked_account.lower() | ||
txn_params = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a dumb question, but why do we need both
web3.eth.signTransaction
andweb3.eth.account.signTransaction
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not dumb at all, it could very well be a dumb idea. My thinking was that
web3.eth.account.signTransaction
(akaAccount.signTransaction
frometh-account
does pretty much the same thing as sending aeth_signTransaction
JSONRPC request to a client, which is whatweb3.eth.signTransaction
does. Since the eth-account implementation was well-done, it seemed to me a fair test comparison to make sure thatweb3.eth.signTransaction
is performing as expectedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, pretty much the only difference is whether your private key is managed by your python app or your node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! That was the missing link 🔗. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No dumb questions.... only dumb people 😈