-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
YAS 292: fix test provider's eth_sendTransaction
behavior
#103
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ import { | |
} from '../../src' | ||
import * as SimpleStorage from '../contracts/build/untranspiled/SimpleStorage.json' | ||
import * as EmptyContract from '../contracts/build/untranspiled/EmptyContract.json' | ||
import * as CallerStorer from '../contracts/build/transpiled/CallerStorer.json' | ||
import { getOvmTransactionMetadata } from '@eth-optimism/ovm' | ||
|
||
const log = getLogger('test-web3-handler', true) | ||
|
||
|
@@ -225,7 +227,7 @@ describe('TestHandler', () => { | |
await testRpcServer.close() | ||
}) | ||
|
||
it('should run the transaction', async () => { | ||
it('should run the transaction for arbitrary from, to, and data, correctly filling optional fields including nonce', async () => { | ||
const storageKey = add0x('01'.repeat(32)) | ||
const storageValue = add0x('02'.repeat(32)) | ||
const executionManagerAddress = await httpProvider.send( | ||
|
@@ -242,23 +244,38 @@ describe('TestHandler', () => { | |
'setStorage' | ||
].encode([executionManagerAddress, storageKey, storageValue]) | ||
const transaction = { | ||
nonce: 0, | ||
from: wallet.address, | ||
to: simpleStorage.address, | ||
gasPrice: 0, | ||
gasLimit: 0, | ||
value: 0, | ||
data: transactionData, | ||
} | ||
|
||
const response = await httpProvider.send('eth_sendTransaction', [ | ||
transaction, | ||
]) | ||
await httpProvider.send('eth_sendTransaction', [transaction]) | ||
const res = await simpleStorage.getStorage( | ||
executionManagerAddress, | ||
storageKey | ||
) | ||
res.should.equal(storageValue) | ||
}) | ||
|
||
it('the EVM should actually see the arbitrary .from as the sender of the tx', async () => { | ||
const factory = new ContractFactory( | ||
CallerStorer.abi, | ||
CallerStorer.bytecode, | ||
wallet | ||
) | ||
const callerStorer = await factory.deploy() | ||
const setData = await callerStorer.interface.functions[ | ||
'storeMsgSender' | ||
].encode([]) | ||
const randomFromAddress = add0x('02'.repeat(20)) | ||
const transaction = { | ||
from: randomFromAddress, | ||
to: callerStorer.address, | ||
data: setData, | ||
} | ||
await httpProvider.send('eth_sendTransaction', [transaction]) | ||
const res = await callerStorer.getLastMsgSender() | ||
res.should.equal(randomFromAddress) | ||
}) | ||
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. 👍 |
||
}) | ||
}) |
11 changes: 11 additions & 0 deletions
11
packages/rollup-full-node/test/contracts/transpiled/CallerStorer.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
contract CallerStorer { | ||
address public lastMsgSender; | ||
function storeMsgSender() public { | ||
lastMsgSender = msg.sender; | ||
} | ||
function getLastMsgSender() public view returns(address) { | ||
return lastMsgSender; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It might be slightly cleaner to set this to
null
instead? Like I actually don't know what clients normally do when decoding / encoding Ethereum transactions, but the way contract creations normally work is we end up decoding the tx and get ato: null
in the result, I believe. I want to know exactly how Ethereum encodes EOA contract creation though....Though after thinking about it, this approach does actually work so could also keep it. Maybe it would be good to have a test which does a contract creation too? My only thought is if we ever move away from using the weird
to=ZERO_ADDRESS
to signify a contract creation this could fail silently.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.
did this because the execution manager checks for
isCreate
withtarget===ZERO_ADDRESS
, but will def add a test