-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(evmengine/types): add tcs for upgrade_contract
increased coverage to 100%
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
}) | ||
} | ||
} |