From 44713b22373dcd9c1605e64c1bf08d546433b5fa Mon Sep 17 00:00:00 2001 From: zsystm Date: Thu, 5 Sep 2024 09:51:29 +0900 Subject: [PATCH] test(evmengine/types): add tcs for upgrade_contract increased coverage to 100% --- .../evmengine/types/upgrade_contract_test.go | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 client/x/evmengine/types/upgrade_contract_test.go diff --git a/client/x/evmengine/types/upgrade_contract_test.go b/client/x/evmengine/types/upgrade_contract_test.go new file mode 100644 index 00000000..ffa6a826 --- /dev/null +++ b/client/x/evmengine/types/upgrade_contract_test.go @@ -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) + }) + } + }) + } +}