Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify error messages in test cases #795

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions x/logic/predicate/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import (
"context"
"fmt"
"strings"

Check failure on line 7 in x/logic/predicate/bank_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used

Check failure on line 7 in x/logic/predicate/bank_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used

Check failure on line 7 in x/logic/predicate/bank_test.go

View workflow job for this annotation

GitHub Actions / test-go

"strings" imported and not used
"testing"

"github.com/axone-protocol/prolog/engine"
Expand Down Expand Up @@ -173,8 +173,7 @@
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 @@
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 @@
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 @@ -3,7 +3,7 @@

import (
"fmt"
"strings"

Check failure on line 6 in x/logic/predicate/crypto_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used

Check failure on line 6 in x/logic/predicate/crypto_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used

Check failure on line 6 in x/logic/predicate/crypto_test.go

View workflow job for this annotation

GitHub Actions / test-go

"strings" imported and not used
"testing"

"github.com/axone-protocol/prolog/engine"
Expand Down Expand Up @@ -204,8 +204,7 @@
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 @@
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 @@ -3,7 +3,7 @@

import (
"fmt"
"strings"

Check failure on line 6 in x/logic/predicate/did_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used

Check failure on line 6 in x/logic/predicate/did_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used

Check failure on line 6 in x/logic/predicate/did_test.go

View workflow job for this annotation

GitHub Actions / test-go

"strings" imported and not used
"testing"

"github.com/axone-protocol/prolog/engine"
Expand Down Expand Up @@ -79,8 +79,7 @@
{
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 @@ -2,7 +2,7 @@

import (
"fmt"
"strings"

Check failure on line 5 in x/logic/predicate/encoding_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used

Check failure on line 5 in x/logic/predicate/encoding_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used

Check failure on line 5 in x/logic/predicate/encoding_test.go

View workflow job for this annotation

GitHub Actions / test-go

"strings" imported and not used
"testing"

"github.com/axone-protocol/prolog"
Expand Down Expand Up @@ -58,8 +58,7 @@
{
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)"),
ccamel marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -3,7 +3,7 @@

import (
"fmt"
"strings"

Check failure on line 6 in x/logic/predicate/uri_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used (typecheck)

Check failure on line 6 in x/logic/predicate/uri_test.go

View workflow job for this annotation

GitHub Actions / lint-go

"strings" imported and not used (typecheck)

Check failure on line 6 in x/logic/predicate/uri_test.go

View workflow job for this annotation

GitHub Actions / test-go

"strings" imported and not used
"testing"

"github.com/axone-protocol/prolog/engine"
Expand Down Expand Up @@ -167,8 +167,7 @@
{
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
Loading