Skip to content

Commit

Permalink
refactor: simplify error messages in test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mo committed Oct 28, 2024
1 parent 107b920 commit 1d3421a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
9 changes: 3 additions & 6 deletions x/logic/predicate/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ func TestBank(t *testing.T) {
balances: []bank.Balance{},
query: `bank_balances('foo', X).`,
wantResult: []testutil.TermResults{{"X": "[uaxone-100]"}},
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_balances/2)",
strings.Join(strings.Split("decoding bech32 failed: invalid bech32 string length 3", ""), ",")),
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[decoding bech32 failed: invalid bech32 string length 3],bank_balances/2)"),
},
{
ctx: context.Background(),
Expand Down Expand Up @@ -308,8 +307,7 @@ func TestBank(t *testing.T) {
spendableCoins: []bank.Balance{},
query: `bank_spendable_balances('foo', X).`,
wantResult: []testutil.TermResults{{"X": "[uaxone-100]"}},
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_spendable_balances/2)",
strings.Join(strings.Split("decoding bech32 failed: invalid bech32 string length 3", ""), ",")),
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[decoding bech32 failed: invalid bech32 string length 3],bank_spendable_balances/2)"),
},

{
Expand Down Expand Up @@ -453,8 +451,7 @@ func TestBank(t *testing.T) {
lockedCoins: []bank.Balance{},
query: `bank_locked_balances('foo', X).`,
wantResult: []testutil.TermResults{{"X": "[uaxone-100]"}},
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_locked_balances/2)",
strings.Join(strings.Split("decoding bech32 failed: invalid bech32 string length 3", ""), ",")),
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[decoding bech32 failed: invalid bech32 string length 3],bank_locked_balances/2)"),
},
}
for nc, tc := range cases {
Expand Down
6 changes: 2 additions & 4 deletions x/logic/predicate/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ func TestXVerify(t *testing.T) {
eddsa_verify(PubKey, Msg, Sig, encoding(octet)).`,
query: `verify.`,
wantSuccess: false,
wantError: fmt.Errorf("error(syntax_error([%s]),eddsa_verify/4)",
strings.Join(strings.Split("ed25519: bad public key length: 33", ""), ",")),
wantError: fmt.Errorf("error(syntax_error([ed25519: bad public key length: 33]),eddsa_verify/4)"),
},
{ // Wrong signature
program: `verify :-
Expand Down Expand Up @@ -256,8 +255,7 @@ func TestXVerify(t *testing.T) {
ecdsa_verify(PubKey, Msg, Sig, encoding(octet)).`,
query: `verify.`,
wantSuccess: false,
wantError: fmt.Errorf("error(syntax_error([%s]),ecdsa_verify/4)",
strings.Join(strings.Split("failed to parse compressed public key (first 10 bytes): 0213c8426be471e55506", ""), ",")),
wantError: fmt.Errorf("error(syntax_error([failed to parse compressed public key (first 10 bytes): 0213c8426be471e55506]),ecdsa_verify/4)"),
},
{ // Unsupported algo
program: `verify :-
Expand Down
3 changes: 1 addition & 2 deletions x/logic/predicate/did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ func TestDID(t *testing.T) {
{
query: `did_components('foo',X).`,
wantResult: []testutil.TermResults{},
wantError: fmt.Errorf("error(domain_error(encoding(did),foo),[%s],did_components/2)",
strings.Join(strings.Split("invalid DID", ""), ",")),
wantError: fmt.Errorf("error(domain_error(encoding(did),foo),[invalid DID],did_components/2)"),
},
{
query: `did_components(123,X).`,
Expand Down
3 changes: 1 addition & 2 deletions x/logic/predicate/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func TestHexBytesPredicate(t *testing.T) {
{
query: `hex_bytes('fail',
[44,38,180,107,104,255,198,143,249,155,69,60,29,48,65,52,19,66,45,112,100,131,191,160,249,138,94,136,98,102,231,174]).`,
wantError: fmt.Errorf("error(domain_error(encoding(hex),fail),[%s],hex_bytes/2)",
strings.Join(strings.Split("encoding/hex: invalid byte: U+0069 'i'", ""), ",")),
wantError: fmt.Errorf("error(domain_error(encoding(hex),fail),[encoding/hex: invalid byte: U+0069 'i'],hex_bytes/2)"),
wantSuccess: false,
},
{
Expand Down
3 changes: 1 addition & 2 deletions x/logic/predicate/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ func TestURIEncoded(t *testing.T) {
{
query: "uri_encoded(path, Decoded, 'bar%%3foo').",
wantSuccess: false,
wantError: fmt.Errorf("error(domain_error(encoding(uri),bar%%%%3foo),[%s],uri_encoded/3)",
strings.Join(strings.Split("invalid URL escape \"%%3\"", ""), ",")),
wantError: fmt.Errorf("error(domain_error(encoding(uri),bar%%%%3foo),[invalid URL escape \"%%3\"],uri_encoded/3)"),
},
}
for nc, tc := range cases {
Expand Down

0 comments on commit 1d3421a

Please sign in to comment.