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

test(evmengine/types): add test cases for upgrade contract #82

Merged
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
84 changes: 84 additions & 0 deletions client/x/evmengine/types/upgrade_contract_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//nolint:testpackage // Ignore this linter rule because we want to test private method, so package name should be same with the target package name.
package types

import (
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"

"github.com/piplabs/story/contracts/bindings"
)

func Test_mustGetABI(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
input *bind.MetaData
expectPanic bool
}{
{
name: "No Panic with valid metadata",
input: bindings.UpgradeEntrypointMetaData,
expectPanic: false,
},
{
name: "Panics with invalid metadata",
input: &bind.MetaData{ABI: "invalid ABI"},
expectPanic: true,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

if tc.expectPanic {
require.Panics(t, func() {
mustGetABI(tc.input)
})
} else {
require.NotPanics(t, func() {
mustGetABI(tc.input)
})
}
})
}
}

func Test_mustGetEvent(t *testing.T) {
t.Parallel()
abi := mustGetABI(bindings.UpgradeEntrypointMetaData)
testCases := []struct {
name string
eventName string
expectPanic bool
}{
{
name: "No Panic for valid event SoftwareUpgrade",
eventName: "SoftwareUpgrade",
expectPanic: false,
},
{
name: "Panics for non-existent event",
eventName: "NonExistentEvent",
expectPanic: true,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

if tc.expectPanic {
require.Panics(t, func() {
mustGetEvent(abi, tc.eventName)
})
} else {
require.NotPanics(t, func() {
mustGetEvent(abi, tc.eventName)
})
}
})
}
}
Loading