Skip to content
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

MTCannon: add EmptyThreadStack test #12082

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cannon/mipsevm/tests/evm_multithreaded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,48 @@ func TestEVM_UnsupportedSyscall(t *testing.T) {
}
}

func TestEVM_EmptyThreadStacks(t *testing.T) {
t.Parallel()
var tracer *tracing.Hooks

cases := []struct {
name string
activeStackSize int
otherStackSize int
shouldPanic bool
}{
{name: "Empty stacks", activeStackSize: 0, otherStackSize: 0, shouldPanic: true},
{name: "Active stack only", activeStackSize: 1, otherStackSize: 0, shouldPanic: false},
{name: "Other stack only", activeStackSize: 0, otherStackSize: 1, shouldPanic: true},
{name: "Active and other stacks", activeStackSize: 1, otherStackSize: 1, shouldPanic: false},
{name: "Multiple active stacks", activeStackSize: 2, otherStackSize: 0, shouldPanic: false},
{name: "Multiple other stacks", activeStackSize: 0, otherStackSize: 2, shouldPanic: true},
{name: "Multiple stacks both", activeStackSize: 2, otherStackSize: 2, shouldPanic: false},
}

for i, c := range cases {
c := c
i := i
t.Run(c.name, func(t *testing.T) {
t.Parallel()
goVm, state, contracts := setup(t, i*123, nil)
mttestutil.SetupThreads(int64(i*123), state, false, c.activeStackSize, c.otherStackSize)

if c.shouldPanic {
require.Panics(t, func() {
goVm.Step(true)
testutil.AssertEVMReverts(t, state, contracts, tracer)
})
} else {
require.NotPanics(t, func() {
goVm.Step(true)
testutil.AssertEVMReverts(t, state, contracts, tracer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the case where shouldPanic == false, you should use testutil.ValidateEVM as is done here. AssertEVMReverts doesn't actually panic. But rather runs a require assertion against the EVM execution status.

})
}
})
}
}

func TestEVM_NormalTraversalStep_HandleWaitingThread(t *testing.T) {
var tracer *tracing.Hooks
cases := []struct {
Expand Down