forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Integration tests for batcher contracts #110
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 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 hidden or 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,99 @@ | ||
| package environment_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/big" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| env "github.com/ethereum-optimism/optimism/espresso/environment" | ||
| "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/geth" | ||
| "github.com/ethereum-optimism/optimism/op-e2e/system/e2esys" | ||
| "github.com/ethereum/go-ethereum/crypto" | ||
| ) | ||
|
|
||
| // TestE2eDevNetWithInvalidAttestation verifies that the batcher correctly fails to register | ||
| // when provided with an invalid attestation. This test ensures that the batch inbox contract | ||
| // properly validates attestations | ||
| func TestE2eDevNetWithInvalidAttestation(t *testing.T) { | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| launcher := new(env.EspressoDevNodeLauncherDocker) | ||
|
|
||
| privateKey, err := crypto.GenerateKey() | ||
| if err != nil { | ||
| t.Fatalf("failed to generate private key") | ||
| } | ||
|
|
||
| system, _, err := | ||
| launcher.StartDevNet(ctx, t, | ||
| env.SetBatcherKey(*privateKey), | ||
| env.Config(func(cfg *e2esys.SystemConfig) { | ||
| cfg.DisableBatcher = true | ||
| }), | ||
| ) | ||
|
|
||
| if have, want := err, error(nil); have != want { | ||
| t.Fatalf("failed to start dev environment with espresso dev node:\nhave:\n\t\"%v\"\nwant:\n\t\"%v\"\n", have, want) | ||
| } | ||
|
|
||
| batchDriver := system.BatchSubmitter.TestDriver() | ||
| batchDriver.Attestation = []byte{1} | ||
| err = batchDriver.StartBatchSubmitting() | ||
|
|
||
| if err == nil { | ||
| t.Fatalf("batcher should've failed to register with invalid attestation but got nil error") | ||
| } | ||
|
|
||
| // Check for the key part of the error message | ||
| expectedMsg := "could not register with batch inbox contract" | ||
| errMsg := err.Error() | ||
| if !strings.Contains(errMsg, expectedMsg) { | ||
| t.Fatalf("error message does not contain expected message %q:\ngot: %q", expectedMsg, errMsg) | ||
| } | ||
|
|
||
| cancel() | ||
| } | ||
|
|
||
| // TestE2eDevNetWithUnattestedBatcherKey verifies that when a batcher key is not properly | ||
| // attested, the L2 chain can still produce unsafe blocks but cannot progress to safe L2 blocks. | ||
| func TestE2eDevNetWithUnattestedBatcherKey(t *testing.T) { | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| launcher := new(env.EspressoDevNodeLauncherDocker) | ||
|
|
||
| privateKey, err := crypto.GenerateKey() | ||
| if err != nil { | ||
| t.Fatalf("failed to generate private key") | ||
| } | ||
|
|
||
| system, _, err := | ||
| launcher.StartDevNet(ctx, t, | ||
| env.SetBatcherKey(*privateKey), | ||
| ) | ||
| if have, want := err, error(nil); have != want { | ||
| t.Fatalf("failed to start dev environment with espresso dev node:\nhave:\n\t\"%v\"\nwant:\n\t\"%v\"\n", have, want) | ||
| } | ||
|
|
||
| l2Seq := system.NodeClient("sequencer") | ||
|
|
||
| // Check that unsafe L2 is progressing... | ||
| _, err = geth.WaitForBlock(big.NewInt(15), l2Seq) | ||
| if have, want := err, error(nil); have != want { | ||
| t.Fatalf("failed to wait for block:\nhave:\n\t\"%v\"\nwant:\n\t\"%v\"\n", have, want) | ||
| } | ||
|
|
||
| // ...but safe L2 is not | ||
| _, err = geth.WaitForBlockToBeSafe(big.NewInt(1), l2Seq, 2*time.Minute) | ||
| if err == nil { | ||
| t.Fatalf("block shouldn't be safe") | ||
| } | ||
|
|
||
| _ = system | ||
|
|
||
| // Signal the testnet to shut down | ||
| cancel() | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.