Skip to content

Commit

Permalink
refactor: adding split back and use string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
mo committed Oct 28, 2024
1 parent 3335322 commit 602ff84
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
8 changes: 5 additions & 3 deletions x/logic/predicate/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package predicate
import (
"context"
"fmt"
"strings"
"testing"

"github.com/axone-protocol/prolog/engine"
Expand Down Expand Up @@ -35,6 +36,7 @@ import (
)

func TestBank(t *testing.T) {
bench32DecodingFail := strings.Join(strings.Split("decoding bech32 failed: invalid bech32 string length 3", ""), ",")
Convey("Under a mocked environment", t, func() {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down Expand Up @@ -172,7 +174,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),[decoding bech32 failed: invalid bech32 string length 3],bank_balances/2)"),
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_balances/2)", bench32DecodingFail),
},
{
ctx: context.Background(),
Expand Down Expand Up @@ -306,7 +308,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),[decoding bech32 failed: invalid bech32 string length 3],bank_spendable_balances/2)"),
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_spendable_balances/2)", bench32DecodingFail),
},

{
Expand Down Expand Up @@ -450,7 +452,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),[decoding bech32 failed: invalid bech32 string length 3],bank_locked_balances/2)"),
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_locked_balances/2)", bench32DecodingFail),
},
}
for nc, tc := range cases {
Expand Down
8 changes: 6 additions & 2 deletions x/logic/predicate/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package predicate

import (
"fmt"
"strings"
"testing"

"github.com/axone-protocol/prolog/engine"
Expand Down Expand Up @@ -158,6 +159,9 @@ func TestCryptoOperations(t *testing.T) {
}

func TestXVerify(t *testing.T) {
badPublicKeyLength := strings.Join(strings.Split("ed25519: bad public key length: 33", ""), ",")
failedToParsePublicKey := strings.Join(strings.Split("failed to parse compressed public key (first 10 bytes): 0213c8426be471e55506", ""), ",")

Convey("Given a test cases", t, func() {
cases := []struct {
program string
Expand Down Expand Up @@ -203,7 +207,7 @@ func TestXVerify(t *testing.T) {
eddsa_verify(PubKey, Msg, Sig, encoding(octet)).`,
query: `verify.`,
wantSuccess: false,
wantError: fmt.Errorf("error(syntax_error([ed25519: bad public key length: 33]),eddsa_verify/4)"),
wantError: fmt.Errorf("error(syntax_error([%s]),eddsa_verify/4)", badPublicKeyLength),
},
{ // Wrong signature
program: `verify :-
Expand Down Expand Up @@ -254,7 +258,7 @@ func TestXVerify(t *testing.T) {
ecdsa_verify(PubKey, Msg, Sig, encoding(octet)).`,
query: `verify.`,
wantSuccess: false,
wantError: fmt.Errorf("error(syntax_error([failed to parse compressed public key (first 10 bytes): 0213c8426be471e55506]),ecdsa_verify/4)"),
wantError: fmt.Errorf("error(syntax_error([%s]),ecdsa_verify/4)", failedToParsePublicKey),
},
{ // Unsupported algo
program: `verify :-
Expand Down
4 changes: 3 additions & 1 deletion x/logic/predicate/did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package predicate

import (
"fmt"
"strings"
"testing"

"github.com/axone-protocol/prolog/engine"
Expand All @@ -22,6 +23,7 @@ import (
)

func TestDID(t *testing.T) {
invalidDID := strings.Join(strings.Split("invalid DID", ""), ",")
Convey("Given a test cases", t, func() {
cases := []struct {
program string
Expand Down Expand Up @@ -78,7 +80,7 @@ func TestDID(t *testing.T) {
{
query: `did_components('foo',X).`,
wantResult: []testutil.TermResults{},
wantError: fmt.Errorf("error(domain_error(encoding(did),foo),[invalid DID],did_components/2)"),
wantError: fmt.Errorf("error(domain_error(encoding(did),foo),[%s],did_components/2)", invalidDID),
},
{
query: `did_components(123,X).`,
Expand Down
5 changes: 4 additions & 1 deletion x/logic/predicate/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package predicate

import (
"fmt"
"strings"
"testing"

"github.com/axone-protocol/prolog"
Expand All @@ -22,6 +23,8 @@ import (
)

func TestHexBytesPredicate(t *testing.T) {
hexEncodingErrorFmt := strings.Join(strings.Split("encoding/hex: invalid byte: U+0069 'i'", ""), ",")

Convey("Given a test cases", t, func() {
cases := []struct {
program string
Expand Down Expand Up @@ -57,7 +60,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),[encoding/hex: invalid byte: U+0069 'i'],hex_bytes/2)"),
wantError: fmt.Errorf("error(domain_error(encoding(hex),fail),[%s],hex_bytes/2)", hexEncodingErrorFmt),
wantSuccess: false,
},
{
Expand Down
4 changes: 3 additions & 1 deletion x/logic/predicate/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package predicate

import (
"fmt"
"strings"
"testing"

"github.com/axone-protocol/prolog/engine"
Expand All @@ -22,6 +23,7 @@ import (
)

func TestURIEncoded(t *testing.T) {
invalidUrlEscape := strings.Join(strings.Split("invalid URL escape \"%%3\"", ""), ",")

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

View workflow job for this annotation

GitHub Actions / lint-go

var-naming: var invalidUrlEscape should be invalidURLEscape (revive)

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

View workflow job for this annotation

GitHub Actions / lint-go

ST1003: var invalidUrlEscape should be invalidURLEscape (stylecheck)
Convey("Given a test cases", t, func() {
cases := []struct {
program string
Expand Down Expand Up @@ -166,7 +168,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),[invalid URL escape \"%%3\"],uri_encoded/3)"),
wantError: fmt.Errorf("error(domain_error(encoding(uri),bar%%%%3foo),[%s],uri_encoded/3)", invalidUrlEscape),
},
}
for nc, tc := range cases {
Expand Down

0 comments on commit 602ff84

Please sign in to comment.