Skip to content

Commit

Permalink
assert error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Oct 25, 2023
1 parent b09130e commit d52f3b6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion types/chain_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestParseChainIDFromGenesis(t *testing.T) {
name string
json string
expChainID string
expError string
}{
{
"success",
Expand All @@ -29,6 +30,7 @@ func TestParseChainIDFromGenesis(t *testing.T) {
"chain_id": "test-chain-id"
}`,
"test-chain-id",
"",
},
{
"nested",
Expand All @@ -41,6 +43,7 @@ func TestParseChainIDFromGenesis(t *testing.T) {
}
}`,
"",
"missing chain-id in genesis file",
},
{
"not exist",
Expand All @@ -53,33 +56,39 @@ func TestParseChainIDFromGenesis(t *testing.T) {
"chain-id": "test-chain-id"
}`,
"",
"missing chain-id in genesis file",
},
{
"invalid type",
`{
"chain-id":1,
"chain-id": 1,
}`,
"",
"invalid character '}' looking for beginning of object key string",
},
{
"invalid json",
`[ " ': }`,
"",
"expected {, got [",
},
{
"empty chain_id",
`{"chain_id": ""}`,
"",
"genesis doc must include non-empty chain_id",
},
{
"whitespace chain_id",
`{"chain_id": " "}`,
"",
"genesis doc must include non-empty chain_id",
},
{
"chain_id too long",
`{"chain_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}`,
"",
"chain_id in genesis doc is too long",
},
}

Expand All @@ -88,6 +97,7 @@ func TestParseChainIDFromGenesis(t *testing.T) {
chain_id, err := ParseChainIDFromGenesis(strings.NewReader(tc.json))
if tc.expChainID == "" {
require.Error(t, err)
require.Contains(t, err.Error(), tc.expError)
} else {
require.NoError(t, err)
require.Equal(t, tc.expChainID, chain_id)
Expand Down

0 comments on commit d52f3b6

Please sign in to comment.