Skip to content

Commit d0830d1

Browse files
author
mo
committed
refactor: adding split back and use string literals
1 parent dd0a369 commit d0830d1

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

x/logic/predicate/bank_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package predicate
44
import (
55
"context"
66
"fmt"
7+
"strings"
78
"testing"
89

910
"github.com/axone-protocol/prolog/engine"
@@ -35,6 +36,7 @@ import (
3536
)
3637

3738
func TestBank(t *testing.T) {
39+
bench32DecodingFail := strings.Join(strings.Split("decoding bech32 failed: invalid bech32 string length 3", ""), ",")
3840
Convey("Under a mocked environment", t, func() {
3941
ctrl := gomock.NewController(t)
4042
defer ctrl.Finish()
@@ -172,7 +174,7 @@ func TestBank(t *testing.T) {
172174
balances: []bank.Balance{},
173175
query: `bank_balances('foo', X).`,
174176
wantResult: []testutil.TermResults{{"X": "[uaxone-100]"}},
175-
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[decoding bech32 failed: invalid bech32 string length 3],bank_balances/2)"),
177+
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_balances/2)", bench32DecodingFail),
176178
},
177179
{
178180
ctx: context.Background(),
@@ -306,7 +308,7 @@ func TestBank(t *testing.T) {
306308
spendableCoins: []bank.Balance{},
307309
query: `bank_spendable_balances('foo', X).`,
308310
wantResult: []testutil.TermResults{{"X": "[uaxone-100]"}},
309-
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[decoding bech32 failed: invalid bech32 string length 3],bank_spendable_balances/2)"),
311+
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_spendable_balances/2)", bench32DecodingFail),
310312
},
311313

312314
{
@@ -450,7 +452,7 @@ func TestBank(t *testing.T) {
450452
lockedCoins: []bank.Balance{},
451453
query: `bank_locked_balances('foo', X).`,
452454
wantResult: []testutil.TermResults{{"X": "[uaxone-100]"}},
453-
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[decoding bech32 failed: invalid bech32 string length 3],bank_locked_balances/2)"),
455+
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_locked_balances/2)", bench32DecodingFail),
454456
},
455457
}
456458
for nc, tc := range cases {

x/logic/predicate/crypto_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package predicate
33

44
import (
55
"fmt"
6+
"strings"
67
"testing"
78

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

160161
func TestXVerify(t *testing.T) {
162+
badPublicKeyLength := strings.Join(strings.Split("ed25519: bad public key length: 33", ""), ",")
163+
failedToParsePublicKey := strings.Join(strings.Split("failed to parse compressed public key (first 10 bytes): 0213c8426be471e55506", ""), ",")
164+
161165
Convey("Given a test cases", t, func() {
162166
cases := []struct {
163167
program string
@@ -203,7 +207,7 @@ func TestXVerify(t *testing.T) {
203207
eddsa_verify(PubKey, Msg, Sig, encoding(octet)).`,
204208
query: `verify.`,
205209
wantSuccess: false,
206-
wantError: fmt.Errorf("error(syntax_error([ed25519: bad public key length: 33]),eddsa_verify/4)"),
210+
wantError: fmt.Errorf("error(syntax_error([%s]),eddsa_verify/4)", badPublicKeyLength),
207211
},
208212
{ // Wrong signature
209213
program: `verify :-
@@ -254,7 +258,7 @@ func TestXVerify(t *testing.T) {
254258
ecdsa_verify(PubKey, Msg, Sig, encoding(octet)).`,
255259
query: `verify.`,
256260
wantSuccess: false,
257-
wantError: fmt.Errorf("error(syntax_error([failed to parse compressed public key (first 10 bytes): 0213c8426be471e55506]),ecdsa_verify/4)"),
261+
wantError: fmt.Errorf("error(syntax_error([%s]),ecdsa_verify/4)", failedToParsePublicKey),
258262
},
259263
{ // Unsupported algo
260264
program: `verify :-

x/logic/predicate/did_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package predicate
33

44
import (
55
"fmt"
6+
"strings"
67
"testing"
78

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

2425
func TestDID(t *testing.T) {
26+
invalidDID := strings.Join(strings.Split("invalid DID", ""), ",")
2527
Convey("Given a test cases", t, func() {
2628
cases := []struct {
2729
program string
@@ -78,7 +80,7 @@ func TestDID(t *testing.T) {
7880
{
7981
query: `did_components('foo',X).`,
8082
wantResult: []testutil.TermResults{},
81-
wantError: fmt.Errorf("error(domain_error(encoding(did),foo),[invalid DID],did_components/2)"),
83+
wantError: fmt.Errorf("error(domain_error(encoding(did),foo),[%s],did_components/2)", invalidDID),
8284
},
8385
{
8486
query: `did_components(123,X).`,

x/logic/predicate/encoding_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package predicate
22

33
import (
44
"fmt"
5+
"strings"
56
"testing"
67

78
"github.com/axone-protocol/prolog"
@@ -22,6 +23,8 @@ import (
2223
)
2324

2425
func TestHexBytesPredicate(t *testing.T) {
26+
hexEncodingErrorFmt := strings.Join(strings.Split("encoding/hex: invalid byte: U+0069 'i'", ""), ",")
27+
2528
Convey("Given a test cases", t, func() {
2629
cases := []struct {
2730
program string
@@ -57,7 +60,7 @@ func TestHexBytesPredicate(t *testing.T) {
5760
{
5861
query: `hex_bytes('fail',
5962
[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]).`,
60-
wantError: fmt.Errorf("error(domain_error(encoding(hex),fail),[encoding/hex: invalid byte: U+0069 'i'],hex_bytes/2)"),
63+
wantError: fmt.Errorf("error(domain_error(encoding(hex),fail),[%s],hex_bytes/2)", hexEncodingErrorFmt),
6164
wantSuccess: false,
6265
},
6366
{

x/logic/predicate/uri_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package predicate
33

44
import (
55
"fmt"
6+
"strings"
67
"testing"
78

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

2425
func TestURIEncoded(t *testing.T) {
26+
invalidUrlEscape := strings.Join(strings.Split("invalid URL escape \"%%3\"", ""), ",")
2527
Convey("Given a test cases", t, func() {
2628
cases := []struct {
2729
program string
@@ -166,7 +168,7 @@ func TestURIEncoded(t *testing.T) {
166168
{
167169
query: "uri_encoded(path, Decoded, 'bar%%3foo').",
168170
wantSuccess: false,
169-
wantError: fmt.Errorf("error(domain_error(encoding(uri),bar%%%%3foo),[invalid URL escape \"%%3\"],uri_encoded/3)"),
171+
wantError: fmt.Errorf("error(domain_error(encoding(uri),bar%%%%3foo),[%s],uri_encoded/3)", invalidUrlEscape),
170172
},
171173
}
172174
for nc, tc := range cases {

0 commit comments

Comments
 (0)