Skip to content

Commit

Permalink
feat(MSFDG): copy op-e2e to op-e2e2
Browse files Browse the repository at this point in the history
  • Loading branch information
dajuguan committed Nov 18, 2024
1 parent 5b29c3d commit 163e609
Show file tree
Hide file tree
Showing 164 changed files with 87,291 additions and 0 deletions.
1 change: 1 addition & 0 deletions op-e2e2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
external_*/shim
72 changes: 72 additions & 0 deletions op-e2e2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Generally, JUNIT_FILE is set in CI but may be specified to an arbitrary file location to emulate CI locally
# If JUNIT_FILE is set, JSON_LOG_FILE should also be set
ifdef JUNIT_FILE
go_test = OP_TESTLOG_DISABLE_COLOR=true OP_E2E_DISABLE_PARALLEL=false gotestsum --format=testname --junitfile=$(JUNIT_FILE) --jsonfile=$(JSON_LOG_FILE) -- -failfast
# Note: -parallel must be set to match the number of cores in the resource class
go_test_flags = -timeout=60m -parallel=8
else
go_test = go test
go_test_flags = -v
endif

test: pre-test test-ws
.PHONY: test

test-external-%: pre-test
make -C ./external_$*/
$(go_test) $(go_test_flags) --externalL2 ./external_$*/

test-ws: pre-test
$(go_test) $(go_test_flags) . ./e2eutils/...
.PHONY: test-ws

test-actions: pre-test
$(go_test) $(go_test_flags) ./actions
.PHONY: test-actions

test-http: pre-test
OP_E2E_USE_HTTP=true $(go_test) $(go_test_flags) . ./e2eutils/...
.PHONY: test-http

test-cannon: pre-test
OP_E2E_CANNON_ENABLED=true $(go_test) $(go_test_flags) ./faultproofs
.PHONY: test-cannon

test-fault-proofs: pre-test
$(go_test) $(go_test_flags) ./faultproofs
.PHONY: test-faultproofs

cannon-prestate:
make -C .. cannon-prestate
.PHONY: cannon-prestate

# We depend on the absolute pre-state generated by cannon to deploy the dispute game contracts.
devnet-allocs: pre-test-cannon
make -C .. devnet-allocs
.PHONY: devnet-allocs

pre-test: pre-test-cannon pre-test-allocs
.PHONY: pre-test

pre-test-cannon:
@if [ ! -e ../op-program/bin ]; then \
make cannon-prestate; \
fi
.PHONY: pre-test-cannon

pre-test-allocs:
@if [ ! -e ../.devnet ]; then \
make devnet-allocs; \
fi
.PHONY: pre-test-allocs

clean:
rm -r ../.devnet
rm -r ../op-program/bin
.PHONY: clean

fuzz:
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzFjordCostFunction ./
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzFastLzGethSolidity ./
go test -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzFastLzCgo ./

34 changes: 34 additions & 0 deletions op-e2e2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# op-e2e

The end to end tests in this repo depend on genesis state that is
created with the `bedrock-devnet` package. To create this state,
run the following commands from the root of the repository:

```bash
make install-geth
make cannon-prestate
make devnet-allocs
```

This will leave artifacts in the `.devnet` directory that will be
read into `op-e2e` at runtime. The default deploy configuration
used for starting all `op-e2e` based tests can be found in
`packages/contracts-bedrock/deploy-config/devnetL1.json`. There
are some values that are safe to change in memory in `op-e2e` at
runtime, but others cannot be changed or else it will result in
broken tests. Any changes to `devnetL1.json` should result in
rebuilding the `.devnet` artifacts before the new values will
be present in the `op-e2e` tests.

## Running tests
Consult the [Makefile](./Makefile) in this directory. Run, e.g.:

```bash
make test-http
```

### Troubleshooting
If you encounter errors:
* ensure you have the latest version of foundry installed: `pnpm update:foundry`
* try deleting the `packages/contracts-bedrock/forge-artifacts` directory
* if the above step doesn't fix the error, try `pnpm clean`
91 changes: 91 additions & 0 deletions op-e2e2/actions/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package actions

import (
"context"

op_e2e "github.com/ethereum-optimism/optimism/op-e2e2"

"github.com/ethereum-optimism/optimism/op-e2e2/e2eutils"
)

// Testing is an interface to Go-like testing,
// extended with a context getter for the test runner to shut down individual actions without interrupting the test,
// and a signaling function for when an invalid action is hit.
// This helps custom test runners navigate slow or invalid actions, e.g. during fuzzing.
type Testing interface {
e2eutils.TestingBase
// Ctx shares a context to execute an action with, the test runner may interrupt the action without stopping the test.
Ctx() context.Context
// InvalidAction indicates the failure is due to action incompatibility, does not stop the test.
InvalidAction(format string, args ...any)
}

// Action is a function that may change the state of one or more actors or check their state.
// Action definitions are meant to be very small building blocks,
// and then composed into larger patterns to write more elaborate tests.
type Action func(t Testing)

// ActionStatus defines the state of an action, to make a basic distinction between InvalidAction() and other calls.
type ActionStatus uint

const (
// ActionOK indicates the action is valid to apply
ActionOK ActionStatus = iota
// ActionInvalid indicates the action is not applicable, and a different next action may taken.
ActionInvalid
// More action status types may be used to indicate e.g. required rewinds,
// simple skips, or special cases for fuzzing.
)

// defaultTesting is a simple implementation of Testing that takes standard Go testing framework,
// and handles invalid actions as errors, and exposes a Reset function to change the context and action state,
// to recover after an invalid action or cancelled context.
type defaultTesting struct {
e2eutils.TestingBase
ctx context.Context
state ActionStatus
}

type StatefulTesting interface {
Testing
Reset(actionCtx context.Context)
State() ActionStatus
}

// NewDefaultTesting returns a new testing obj, and enables parallel test execution.
// Returns an interface, we're likely changing the behavior here as we build more action tests.
func NewDefaultTesting(tb e2eutils.TestingBase) StatefulTesting {
op_e2e.InitParallel(tb)

return &defaultTesting{
TestingBase: tb,
ctx: context.Background(),
state: ActionOK,
}
}

// Ctx shares a context to execute an action with, the test runner may interrupt the action without stopping the test.
func (st *defaultTesting) Ctx() context.Context {
return st.ctx
}

// InvalidAction indicates the failure is due to action incompatibility, does not stop the test.
// The format and args behave the same as fmt.Sprintf, testing.T.Errorf, etc.
func (st *defaultTesting) InvalidAction(format string, args ...any) {
st.TestingBase.Helper() // report the error on the call-site to make debugging clear, not here.
st.Errorf("invalid action err: "+format, args...)
st.state = ActionInvalid
}

// Reset prepares the testing util for the next action, changing the context and state back to OK.
func (st *defaultTesting) Reset(actionCtx context.Context) {
st.state = ActionOK
st.ctx = actionCtx
}

// State shares the current action state.
func (st *defaultTesting) State() ActionStatus {
return st.state
}

var _ Testing = (*defaultTesting)(nil)
Loading

0 comments on commit 163e609

Please sign in to comment.