forked from ethereum-optimism/op-geth
-
Notifications
You must be signed in to change notification settings - Fork 3
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 Celo2 Signer compatibility with both Celo1 and Celo2 transactions #308
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c09f4e
Fix typo
Kourin1996 fccd6d4
Add unit tests for forks
Kourin1996 72f44d9
Add unit tests for Celo signer
Kourin1996 2053311
Format code
Kourin1996 50cbf1a
Simplify Test_forks_activeForks and Test_forks_findTxFuncs
Kourin1996 617fb92
Merge remote-tracking branch 'origin/celo11' into Kourin1996/add-lega…
Kourin1996 c0f5c39
Remove Test_forks_findTxFuncs
Kourin1996 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Test_forks_activeForks tests that the correct forks are returned for a given block time and chain config | ||
func Test_forks_activeForks(t *testing.T) { | ||
t.Parallel() | ||
|
||
cel2Time := uint64(1000) | ||
|
||
t.Run("Non-Celo", func(t *testing.T) { | ||
config := ¶ms.ChainConfig{ | ||
Cel2Time: nil, | ||
} | ||
assert.Equal(t, []fork(nil), celoForks.activeForks(1000, config)) | ||
}) | ||
|
||
t.Run("Celo1", func(t *testing.T) { | ||
config := ¶ms.ChainConfig{ | ||
Cel2Time: &cel2Time, | ||
} | ||
assert.Equal(t, []fork{&celoLegacy{}}, celoForks.activeForks(500, config)) | ||
}) | ||
|
||
t.Run("Celo2", func(t *testing.T) { | ||
config := ¶ms.ChainConfig{ | ||
Cel2Time: &cel2Time, | ||
} | ||
assert.Equal(t, []fork{&cel2{}, &celoLegacy{}}, celoForks.activeForks(1000, config)) | ||
}) | ||
} | ||
|
||
// Test_forks_findTxFuncs tests that the correct txFuncs are returned for a given transaction type and chain config | ||
func Test_forks_findTxFuncs(t *testing.T) { | ||
t.Parallel() | ||
|
||
cel2Time := uint64(1000) | ||
config := ¶ms.ChainConfig{ | ||
Cel2Time: &cel2Time, | ||
} | ||
|
||
celo2Forks := forks(celoForks.activeForks(cel2Time, config)) | ||
t.Run("Celo LegacyTx in Celo2", func(t *testing.T) { | ||
assert.Equal(t, deprecatedTxFuncs, celo2Forks.findTxFuncs(NewTx(&LegacyTx{CeloLegacy: true}))) | ||
}) | ||
|
||
t.Run("Ethereum LegacyTx in Celo2", func(t *testing.T) { | ||
assert.Equal(t, (*txFuncs)(nil), celo2Forks.findTxFuncs(NewTx(&LegacyTx{CeloLegacy: false}))) | ||
}) | ||
|
||
t.Run("AccessListTx in Celo2", func(t *testing.T) { | ||
assert.Equal(t, accessListTxFuncs, celo2Forks.findTxFuncs(NewTx(&AccessListTx{}))) | ||
}) | ||
|
||
t.Run("DynamicFeeTx in Celo2", func(t *testing.T) { | ||
assert.Equal(t, dynamicFeeTxFuncs, celo2Forks.findTxFuncs(NewTx(&DynamicFeeTx{}))) | ||
}) | ||
|
||
t.Run("CeloDynamicFeeTx in Celo2", func(t *testing.T) { | ||
assert.Equal(t, deprecatedTxFuncs, celo2Forks.findTxFuncs(NewTx(&CeloDynamicFeeTx{}))) | ||
}) | ||
|
||
t.Run("CeloDynamicFeeTxV2 in Celo2", func(t *testing.T) { | ||
assert.Equal(t, celoDynamicFeeTxV2Funcs, celo2Forks.findTxFuncs(NewTx(&CeloDynamicFeeTxV2{}))) | ||
}) | ||
|
||
celo1Forks := forks(celoForks.activeForks(uint64(100), config)) | ||
t.Run("Celo LegacyTx in Celo1", func(t *testing.T) { | ||
assert.Equal(t, celoLegacyTxFuncs, celo1Forks.findTxFuncs(NewTx(&LegacyTx{CeloLegacy: true}))) | ||
}) | ||
|
||
t.Run("Ethereum LegacyTx in Celo1", func(t *testing.T) { | ||
assert.Equal(t, (*txFuncs)(nil), celo1Forks.findTxFuncs(NewTx(&LegacyTx{CeloLegacy: false}))) | ||
}) | ||
|
||
t.Run("AccessListTx in Celo1", func(t *testing.T) { | ||
assert.Equal(t, accessListTxFuncs, celo1Forks.findTxFuncs(NewTx(&AccessListTx{}))) | ||
}) | ||
|
||
t.Run("DynamicFeeTx in Celo1", func(t *testing.T) { | ||
assert.Equal(t, dynamicFeeTxFuncs, celo1Forks.findTxFuncs(NewTx(&DynamicFeeTx{}))) | ||
}) | ||
|
||
t.Run("CeloDynamicFeeTx in Celo1", func(t *testing.T) { | ||
assert.Equal(t, celoDynamicFeeTxFuncs, celo1Forks.findTxFuncs(NewTx(&CeloDynamicFeeTx{}))) | ||
}) | ||
|
||
t.Run("CeloDynamicFeeTxV2 in Celo1", func(t *testing.T) { | ||
assert.Equal(t, celoDynamicFeeTxV2Funcs, celo1Forks.findTxFuncs(NewTx(&CeloDynamicFeeTxV2{}))) | ||
}) | ||
|
||
t.Run("CeloDenominatedTx in Celo1", func(t *testing.T) { | ||
assert.Equal(t, (*txFuncs)(nil), celo1Forks.findTxFuncs(NewTx(&CeloDenominatedTx{}))) | ||
}) | ||
} |
Oops, something went wrong.
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.
Hey @Kourin1996 I think this test would be more useful if it tested from the level of the
Signer
using a similar approach toTestProtectedCeloLegacyTxSigning
.So generating a
Signer
for a given config and then signing each transaction with that signer and checking that the sender address can be correctly recovered, of course for some transactions an error will be returned because they are not supported or deprecated.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.
@piersy
I believe such cases are covered by
TestCeloSigner_SignAndRecovery
.TestCeloSigner_SignAndRecovery
test focuses on signing only in Celo2 but includes actual scenarios.On the other hand, this
Test_forks_findTxFuncs
test is just a low-level test designed to detect unexpected changes.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.
Good point, what's being tested here is already covered by the two tests you mentioned. It seems to me that this test doesn’t add much value, so my preference would be to remove it. That said, I’m also fine with keeping it if you feel strongly about it.
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.
@piersy OK. I removed it!