Skip to content

Commit 782c51c

Browse files
author
panmini
committed
test(logic): simplify error messages in test cases
1 parent 107b920 commit 782c51c

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

x/logic/predicate/bank_test.go

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

109
"github.com/axone-protocol/prolog/engine"
@@ -36,6 +35,9 @@ import (
3635
)
3736

3837
func TestBank(t *testing.T) {
38+
const (
39+
bench32DecodingFail = "d,e,c,o,d,i,n,g, ,b,e,c,h,3,2, ,f,a,i,l,e,d,:, ,i,n,v,a,l,i,d, ,b,e,c,h,3,2, ,s,t,r,i,n,g, ,l,e,n,g,t,h, ,3"
40+
)
3941
Convey("Under a mocked environment", t, func() {
4042
ctrl := gomock.NewController(t)
4143
defer ctrl.Finish()
@@ -173,8 +175,7 @@ func TestBank(t *testing.T) {
173175
balances: []bank.Balance{},
174176
query: `bank_balances('foo', X).`,
175177
wantResult: []testutil.TermResults{{"X": "[uaxone-100]"}},
176-
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_balances/2)",
177-
strings.Join(strings.Split("decoding bech32 failed: invalid bech32 string length 3", ""), ",")),
178+
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_balances/2)", bench32DecodingFail),
178179
},
179180
{
180181
ctx: context.Background(),
@@ -308,8 +309,7 @@ func TestBank(t *testing.T) {
308309
spendableCoins: []bank.Balance{},
309310
query: `bank_spendable_balances('foo', X).`,
310311
wantResult: []testutil.TermResults{{"X": "[uaxone-100]"}},
311-
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_spendable_balances/2)",
312-
strings.Join(strings.Split("decoding bech32 failed: invalid bech32 string length 3", ""), ",")),
312+
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_spendable_balances/2)", bench32DecodingFail),
313313
},
314314

315315
{
@@ -453,8 +453,7 @@ func TestBank(t *testing.T) {
453453
lockedCoins: []bank.Balance{},
454454
query: `bank_locked_balances('foo', X).`,
455455
wantResult: []testutil.TermResults{{"X": "[uaxone-100]"}},
456-
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_locked_balances/2)",
457-
strings.Join(strings.Split("decoding bech32 failed: invalid bech32 string length 3", ""), ",")),
456+
wantError: fmt.Errorf("error(domain_error(encoding(bech32),foo),[%s],bank_locked_balances/2)", bench32DecodingFail),
458457
},
459458
}
460459
for nc, tc := range cases {

x/logic/predicate/crypto_test.go

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

44
import (
55
"fmt"
6-
"strings"
76
"testing"
87

98
"github.com/axone-protocol/prolog/engine"
@@ -159,6 +158,11 @@ func TestCryptoOperations(t *testing.T) {
159158
}
160159

161160
func TestXVerify(t *testing.T) {
161+
const (
162+
badPublicKeyLength = "e,d,2,5,5,1,9,:, ,b,a,d, ,p,u,b,l,i,c, ,k,e,y, ,l,e,n,g,t,h,:, ,3,3"
163+
failedToParsePublicKey = "f,a,i,l,e,d, ,t,o, ,p,a,r,s,e, ,c,o,m,p,r,e,s,s,e,d, ,p,u,b,l,i,c, ,k,e,y, ,(,f,i,r,s,t, ,1,0, ,b,y,t,e,s,),:, ,0,2,1,3,c,8,4,2,6,b,e,4,7,1,e,5,5,5,0,6"
164+
)
165+
162166
Convey("Given a test cases", t, func() {
163167
cases := []struct {
164168
program string
@@ -204,8 +208,7 @@ func TestXVerify(t *testing.T) {
204208
eddsa_verify(PubKey, Msg, Sig, encoding(octet)).`,
205209
query: `verify.`,
206210
wantSuccess: false,
207-
wantError: fmt.Errorf("error(syntax_error([%s]),eddsa_verify/4)",
208-
strings.Join(strings.Split("ed25519: bad public key length: 33", ""), ",")),
211+
wantError: fmt.Errorf("error(syntax_error([%s]),eddsa_verify/4)", badPublicKeyLength),
209212
},
210213
{ // Wrong signature
211214
program: `verify :-
@@ -256,8 +259,7 @@ func TestXVerify(t *testing.T) {
256259
ecdsa_verify(PubKey, Msg, Sig, encoding(octet)).`,
257260
query: `verify.`,
258261
wantSuccess: false,
259-
wantError: fmt.Errorf("error(syntax_error([%s]),ecdsa_verify/4)",
260-
strings.Join(strings.Split("failed to parse compressed public key (first 10 bytes): 0213c8426be471e55506", ""), ",")),
262+
wantError: fmt.Errorf("error(syntax_error([%s]),ecdsa_verify/4)", failedToParsePublicKey),
261263
},
262264
{ // Unsupported algo
263265
program: `verify :-

x/logic/predicate/did_test.go

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

44
import (
55
"fmt"
6-
"strings"
76
"testing"
87

98
"github.com/axone-protocol/prolog/engine"
@@ -23,6 +22,9 @@ import (
2322
)
2423

2524
func TestDID(t *testing.T) {
25+
const (
26+
invalidDID = "i,n,v,a,l,i,d, ,D,I,D"
27+
)
2628
Convey("Given a test cases", t, func() {
2729
cases := []struct {
2830
program string
@@ -79,8 +81,7 @@ func TestDID(t *testing.T) {
7981
{
8082
query: `did_components('foo',X).`,
8183
wantResult: []testutil.TermResults{},
82-
wantError: fmt.Errorf("error(domain_error(encoding(did),foo),[%s],did_components/2)",
83-
strings.Join(strings.Split("invalid DID", ""), ",")),
84+
wantError: fmt.Errorf("error(domain_error(encoding(did),foo),[%s],did_components/2)", invalidDID),
8485
},
8586
{
8687
query: `did_components(123,X).`,

x/logic/predicate/encoding_test.go

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

33
import (
44
"fmt"
5-
"strings"
65
"testing"
76

87
"github.com/axone-protocol/prolog"
@@ -23,6 +22,10 @@ import (
2322
)
2423

2524
func TestHexBytesPredicate(t *testing.T) {
25+
const (
26+
hexEncodingErrorFmt = "e,n,c,o,d,i,n,g,/,h,e,x,:, ,i,n,v,a,l,i,d, ,b,y,t,e,:, ,U,+,0,0,6,9, ,',i,'"
27+
)
28+
2629
Convey("Given a test cases", t, func() {
2730
cases := []struct {
2831
program string
@@ -58,8 +61,7 @@ func TestHexBytesPredicate(t *testing.T) {
5861
{
5962
query: `hex_bytes('fail',
6063
[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]).`,
61-
wantError: fmt.Errorf("error(domain_error(encoding(hex),fail),[%s],hex_bytes/2)",
62-
strings.Join(strings.Split("encoding/hex: invalid byte: U+0069 'i'", ""), ",")),
64+
wantError: fmt.Errorf("error(domain_error(encoding(hex),fail),[%s],hex_bytes/2)", hexEncodingErrorFmt),
6365
wantSuccess: false,
6466
},
6567
{

x/logic/predicate/uri_test.go

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

44
import (
55
"fmt"
6-
"strings"
76
"testing"
87

98
"github.com/axone-protocol/prolog/engine"
@@ -23,6 +22,9 @@ import (
2322
)
2423

2524
func TestURIEncoded(t *testing.T) {
25+
const (
26+
invalidURLEscape = "i,n,v,a,l,i,d, ,U,R,L, ,e,s,c,a,p,e, ,\",%,%,3,\""
27+
)
2628
Convey("Given a test cases", t, func() {
2729
cases := []struct {
2830
program string
@@ -167,8 +169,7 @@ func TestURIEncoded(t *testing.T) {
167169
{
168170
query: "uri_encoded(path, Decoded, 'bar%%3foo').",
169171
wantSuccess: false,
170-
wantError: fmt.Errorf("error(domain_error(encoding(uri),bar%%%%3foo),[%s],uri_encoded/3)",
171-
strings.Join(strings.Split("invalid URL escape \"%%3\"", ""), ",")),
172+
wantError: fmt.Errorf("error(domain_error(encoding(uri),bar%%%%3foo),[%s],uri_encoded/3)", invalidURLEscape),
172173
},
173174
}
174175
for nc, tc := range cases {

0 commit comments

Comments
 (0)