Skip to content

Commit

Permalink
add init unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Aug 20, 2024
1 parent d2bcc79 commit adbc0a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions precompiles/prototype/prototype.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ var (
)

func init() {
initABI()
}

func initABI() {
if prototypeABI == "" {
panic("missing prototype ABI")
}
Expand Down
23 changes: 23 additions & 0 deletions precompiles/prototype/prototype_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package prototype

import (
"encoding/json"
"testing"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -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()
}

0 comments on commit adbc0a6

Please sign in to comment.