diff --git a/precompiles/prototype/prototype.go b/precompiles/prototype/prototype.go index dde0711af8..5a19e1373f 100644 --- a/precompiles/prototype/prototype.go +++ b/precompiles/prototype/prototype.go @@ -33,6 +33,10 @@ var ( ) func init() { + initABI() +} + +func initABI() { if prototypeABI == "" { panic("missing prototype ABI") } diff --git a/precompiles/prototype/prototype_test.go b/precompiles/prototype/prototype_test.go index 4f5e2e735b..a97fc01e3b 100644 --- a/precompiles/prototype/prototype_test.go +++ b/precompiles/prototype/prototype_test.go @@ -1,6 +1,7 @@ package prototype import ( + "encoding/json" "testing" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -277,4 +278,26 @@ func Test_InvalidMethod(t *testing.T) { // Test for non existent method. _, doNotExist := abi.Methods["invalidMethod"] require.False(t, doNotExist, "invalidMethod should not be present in the ABI") +} + +func Test_MissingABI(t *testing.T) { + prototypeABI = "" + defer func() { + if r := recover(); r != nil { + require.Equal(t, "missing prototype ABI", r, "expected error: missing ABI, got: %v", r) + } + }() + + initABI() +} + +func Test_InvalidABI(t *testing.T) { + prototypeABI = "invalid json" + defer func() { + if r := recover(); r != nil { + require.IsType(t, &json.SyntaxError{}, r, "expected error type: json.SyntaxError, got: %T", r) + } + }() + + initABI() } \ No newline at end of file