Skip to content

Commit

Permalink
test(evmengine/types): add tcs for upgrade_contract
Browse files Browse the repository at this point in the history
increased coverage to 100%
  • Loading branch information
zsystm committed Sep 6, 2024
1 parent 8ceb729 commit 44713b2
Showing 1 changed file with 84 additions and 0 deletions.
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)
})
}
})
}
}

0 comments on commit 44713b2

Please sign in to comment.