-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Add tests for convertInternalLogsToOvmLogs #21
Merged
+167
−120
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0adabb2
Add tests for convertInternalLogsToOvmLogs
masonforest dfe7eb5
Merge remote-tracking branch 'origin/master' into YAS-184/HardenTheOv…
masonforest 4ef8f91
Fix merge conflict
masonforest 32d122a
Pass tests
masonforest 904311c
Combine test path globs
masonforest 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,9 @@ contract ExecutionManager is FullStateManager { | |
address _codeContractAddress, | ||
bytes32 _codeContractHash | ||
); | ||
event CallingWithEOA(); | ||
event CallingWithEOA( | ||
address _ovmFromAddress | ||
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. 👍 |
||
); | ||
event EOACreatedContract( | ||
address _ovmContractAddress | ||
); | ||
|
@@ -183,6 +185,7 @@ contract ExecutionManager is FullStateManager { | |
require(eoaAddress != ZERO_ADDRESS, "Failed to recover signature"); | ||
// Require nonce to be correct | ||
require(_nonce == getOvmContractNonce(eoaAddress), "Incorrect nonce!"); | ||
emit CallingWithEOA(eoaAddress); | ||
executionContext.ovmTxOrigin = eoaAddress; | ||
// Make the EOA call for the account | ||
executeUnsignedEOACall(_timestamp, _queueOrigin, _ovmEntrypoint, _callBytes, eoaAddress); | ||
|
@@ -206,7 +209,6 @@ contract ExecutionManager is FullStateManager { | |
address _fromAddress | ||
) public { | ||
uint _nonce = getOvmContractNonce(_fromAddress); | ||
emit CallingWithEOA(); | ||
// Initialize our context | ||
initializeContext(_timestamp, _queueOrigin); | ||
|
||
|
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,77 @@ | ||
import { Contract, ethers } from 'ethers' | ||
import { add0x, ZERO_ADDRESS, TestUtils } from '@eth-optimism/core-utils' | ||
/* Contract Imports */ | ||
import { getWallets } from 'ethereum-waffle' | ||
import { TransactionReceipt, JsonRpcProvider, Log } from 'ethers/providers' | ||
import { | ||
convertInternalLogsToOvmLogs, | ||
getOvmTransactionMetadata, | ||
} from '../../src/app' | ||
import { buildLog } from '../helpers' | ||
|
||
const ALICE = '0x0000000000000000000000000000000000000001' | ||
const BOB = '0x0000000000000000000000000000000000000002' | ||
const CONTRACT = '0x000000000000000000000000000000000000000C' | ||
const CODE_CONTRACT = '0x00000000000000000000000000000000000000CC' | ||
const CODE_CONTRACT_HASH = add0x('00'.repeat(32)) | ||
// We're not actually making any calls to the | ||
// Execution manager so this can be the zero address | ||
const EXECUTION_MANAGER_ADDRESS = ZERO_ADDRESS | ||
|
||
describe('convertInternalLogsToOvmLogs', () => { | ||
it('should replace the address of the event with the address of the last active contract event', async () => { | ||
convertInternalLogsToOvmLogs( | ||
[ | ||
[EXECUTION_MANAGER_ADDRESS, 'ActiveContract(address)', [ALICE]], | ||
[EXECUTION_MANAGER_ADDRESS, 'EventFromAlice()', []], | ||
[EXECUTION_MANAGER_ADDRESS, 'ActiveContract(address)', [BOB]], | ||
[EXECUTION_MANAGER_ADDRESS, 'EventFromBob()', []], | ||
].map((args) => buildLog.apply(null, args)) | ||
).should.deep.eq( | ||
[ | ||
[ALICE, 'EventFromAlice()', []], | ||
[BOB, 'EventFromBob()', []], | ||
].map((args) => buildLog.apply(null, args)) | ||
) | ||
}) | ||
}) | ||
|
||
describe('getOvmTransactionMetadata', () => { | ||
it('should return transaction metadata from calls from externally owned accounts', async () => { | ||
const transactionReceipt: TransactionReceipt = { | ||
byzantium: true, | ||
logs: [ | ||
[EXECUTION_MANAGER_ADDRESS, 'ActiveContract(address)', [ALICE]], | ||
[EXECUTION_MANAGER_ADDRESS, 'CallingWithEOA(address)', [ALICE]], | ||
[EXECUTION_MANAGER_ADDRESS, 'ActiveContract(address)', [ALICE]], | ||
[EXECUTION_MANAGER_ADDRESS, 'EOACreatedContract(address)', [CONTRACT]], | ||
[EXECUTION_MANAGER_ADDRESS, 'ActiveContract(address)', [CONTRACT]], | ||
[ | ||
EXECUTION_MANAGER_ADDRESS, | ||
'CreatedContract(address,address,bytes32)', | ||
[CONTRACT, CODE_CONTRACT, CODE_CONTRACT_HASH], | ||
], | ||
].map((args) => buildLog.apply(null, args)), | ||
} | ||
|
||
getOvmTransactionMetadata(transactionReceipt).should.deep.eq({ | ||
ovmCreatedContractAddress: CONTRACT, | ||
ovmFrom: ALICE, | ||
ovmTo: CONTRACT, | ||
ovmTxSucceeded: true, | ||
}) | ||
}) | ||
|
||
it('should return with ovmTxSucceeded equal to false if the transaction reverted', async () => { | ||
const transactionReceipt: TransactionReceipt = { | ||
byzantium: true, | ||
logs: [[EXECUTION_MANAGER_ADDRESS, 'EOACallRevert()', []]].map((args) => | ||
buildLog.apply(null, args) | ||
), | ||
} | ||
|
||
getOvmTransactionMetadata(transactionReceipt).ovmTxSucceeded.should.eq( | ||
false | ||
) | ||
}) | ||
}) |
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
Oops, something went wrong.
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.
Can we use
test/**/*.spec.ts
instead of writing both out?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.
Unfortunately we can't match on everything in
test
because that would matchtest/govm
which we want to run separately withtest:govm
. We might be able to removegovm
tests in a separate PR if we decide to tablegovm
for the time being.I did at least combine app and contracts into one though 👍