-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpayment_test.go
91 lines (88 loc) · 6.62 KB
/
payment_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package dpp
import (
"testing"
"github.com/matryer/is"
)
func TestPaymentCreate_Validate(t *testing.T) {
is := is.New(t)
tests := map[string]struct {
req Payment
exp string
}{
"valid request should return no errors": {
req: Payment{
MerchantData: Merchant{
ExtendedData: map[string]interface{}{
"paymentReference": "abc123",
},
},
ProofCallbacks: map[string]ProofCallback{
"http://myproofs/proofs": {
Token: "abc123",
},
},
RawTx: func() *string {
s := "0200000004c4b8372f640f9fab1dc2c14eda6a9669d13ca0f4fff42c318f388cf917399fa9000000004847304402203f2c94003474010010a11cdc4bfac3065e117b22ff1e218fb31230be12a80d5202205b69e27a1815a7d6668a5b73e57b15a6117c94b15b3d915ff3304803e233af5341feffffff417e443a9da68f5bea767bb90f09737df50ff7592d662407dc16ed17af0b821d000000006a47304402200fe1bb41b168aa1e071b39c1bd00d7f960d98406b36c76cbeff98acbe20c117902205628cf5755676f85b2cd360406fc771ed3244395d2cd2bf2292e06e0a8f7e4dc412103b811b71802653c97388faa8a7275a49a2742896285515fb01e2801948ee9cc4cfeffffff94b976366984846918b8ef346da50db6231dcf870c6d48754a98976b3a989c23000000004847304402201baa75b71f066eaa5297efaa878f215fd08e3132e3de2d5c7038e8433ef49cf8022044655ef242869210ed8a9a290c5ccc7cfa70a0d6b8cc7d6dc832d1d728ef106341feffffff4383ff843f365a8c9a6ce44ba1c584840125227e7ad06409f7194423ca614aff000000006a4730440220328b446736fa1a47e8675e7ea31a86f6025ece36aa2e158e21e85758a1cf1db8022073cf6f9f3353337a537bfbfef818497941b6f00f6918d40e87d06751610e739e412102065bd35d20f59e1c8c1254690254f14e40710409481320df3854bbfc867b4698feffffff027a898400000000001976a914fc54fbfac51db40cd845ebe6d243d6c950f4bf4088ac0065cd1d000000001976a914ba903fcaa03a280a9577da32db79e52373b8d0e388ac1b040000"
return &s
}(),
Memo: "test this please",
},
}, "merchant data missing extended data should error": {
req: Payment{
RawTx: func() *string {
s := "0200000004c4b8372f640f9fab1dc2c14eda6a9669d13ca0f4fff42c318f388cf917399fa9000000004847304402203f2c94003474010010a11cdc4bfac3065e117b22ff1e218fb31230be12a80d5202205b69e27a1815a7d6668a5b73e57b15a6117c94b15b3d915ff3304803e233af5341feffffff417e443a9da68f5bea767bb90f09737df50ff7592d662407dc16ed17af0b821d000000006a47304402200fe1bb41b168aa1e071b39c1bd00d7f960d98406b36c76cbeff98acbe20c117902205628cf5755676f85b2cd360406fc771ed3244395d2cd2bf2292e06e0a8f7e4dc412103b811b71802653c97388faa8a7275a49a2742896285515fb01e2801948ee9cc4cfeffffff94b976366984846918b8ef346da50db6231dcf870c6d48754a98976b3a989c23000000004847304402201baa75b71f066eaa5297efaa878f215fd08e3132e3de2d5c7038e8433ef49cf8022044655ef242869210ed8a9a290c5ccc7cfa70a0d6b8cc7d6dc832d1d728ef106341feffffff4383ff843f365a8c9a6ce44ba1c584840125227e7ad06409f7194423ca614aff000000006a4730440220328b446736fa1a47e8675e7ea31a86f6025ece36aa2e158e21e85758a1cf1db8022073cf6f9f3353337a537bfbfef818497941b6f00f6918d40e87d06751610e739e412102065bd35d20f59e1c8c1254690254f14e40710409481320df3854bbfc867b4698feffffff027a898400000000001976a914fc54fbfac51db40cd845ebe6d243d6c950f4bf4088ac0065cd1d000000001976a914ba903fcaa03a280a9577da32db79e52373b8d0e388ac1b040000"
return &s
}(),
Memo: "test this please",
},
exp: "[merchantData.extendedData: value cannot be empty]",
}, "merchant data missing payment reference should error": {
req: Payment{
RawTx: func() *string {
s := "0200000004c4b8372f640f9fab1dc2c14eda6a9669d13ca0f4fff42c318f388cf917399fa9000000004847304402203f2c94003474010010a11cdc4bfac3065e117b22ff1e218fb31230be12a80d5202205b69e27a1815a7d6668a5b73e57b15a6117c94b15b3d915ff3304803e233af5341feffffff417e443a9da68f5bea767bb90f09737df50ff7592d662407dc16ed17af0b821d000000006a47304402200fe1bb41b168aa1e071b39c1bd00d7f960d98406b36c76cbeff98acbe20c117902205628cf5755676f85b2cd360406fc771ed3244395d2cd2bf2292e06e0a8f7e4dc412103b811b71802653c97388faa8a7275a49a2742896285515fb01e2801948ee9cc4cfeffffff94b976366984846918b8ef346da50db6231dcf870c6d48754a98976b3a989c23000000004847304402201baa75b71f066eaa5297efaa878f215fd08e3132e3de2d5c7038e8433ef49cf8022044655ef242869210ed8a9a290c5ccc7cfa70a0d6b8cc7d6dc832d1d728ef106341feffffff4383ff843f365a8c9a6ce44ba1c584840125227e7ad06409f7194423ca614aff000000006a4730440220328b446736fa1a47e8675e7ea31a86f6025ece36aa2e158e21e85758a1cf1db8022073cf6f9f3353337a537bfbfef818497941b6f00f6918d40e87d06751610e739e412102065bd35d20f59e1c8c1254690254f14e40710409481320df3854bbfc867b4698feffffff027a898400000000001976a914fc54fbfac51db40cd845ebe6d243d6c950f4bf4088ac0065cd1d000000001976a914ba903fcaa03a280a9577da32db79e52373b8d0e388ac1b040000"
return &s
}(),
MerchantData: Merchant{ExtendedData: map[string]interface{}{"test": "value"}},
Memo: "test this please",
},
exp: "[merchantData.paymentReference: value cannot be empty]",
}, "refundTo too long should error": {
req: Payment{
RawTx: func() *string {
s := "0200000004c4b8372f640f9fab1dc2c14eda6a9669d13ca0f4fff42c318f388cf917399fa9000000004847304402203f2c94003474010010a11cdc4bfac3065e117b22ff1e218fb31230be12a80d5202205b69e27a1815a7d6668a5b73e57b15a6117c94b15b3d915ff3304803e233af5341feffffff417e443a9da68f5bea767bb90f09737df50ff7592d662407dc16ed17af0b821d000000006a47304402200fe1bb41b168aa1e071b39c1bd00d7f960d98406b36c76cbeff98acbe20c117902205628cf5755676f85b2cd360406fc771ed3244395d2cd2bf2292e06e0a8f7e4dc412103b811b71802653c97388faa8a7275a49a2742896285515fb01e2801948ee9cc4cfeffffff94b976366984846918b8ef346da50db6231dcf870c6d48754a98976b3a989c23000000004847304402201baa75b71f066eaa5297efaa878f215fd08e3132e3de2d5c7038e8433ef49cf8022044655ef242869210ed8a9a290c5ccc7cfa70a0d6b8cc7d6dc832d1d728ef106341feffffff4383ff843f365a8c9a6ce44ba1c584840125227e7ad06409f7194423ca614aff000000006a4730440220328b446736fa1a47e8675e7ea31a86f6025ece36aa2e158e21e85758a1cf1db8022073cf6f9f3353337a537bfbfef818497941b6f00f6918d40e87d06751610e739e412102065bd35d20f59e1c8c1254690254f14e40710409481320df3854bbfc867b4698feffffff027a898400000000001976a914fc54fbfac51db40cd845ebe6d243d6c950f4bf4088ac0065cd1d000000001976a914ba903fcaa03a280a9577da32db79e52373b8d0e388ac1b040000"
return &s
}(),
RefundTo: func() *string {
bb := make([]byte, 0)
// generate string 1 more byte than 10000
for i := 0; i <= 100; i++ {
bb = append(bb, 42)
}
out := string(bb)
return &out
}(),
MerchantData: Merchant{
ExtendedData: map[string]interface{}{
"paymentReference": "abc123",
},
},
Memo: "test this please",
},
exp: "[refundTo: value must be between 0 and 100 characters]",
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
is.NewRelaxed(t)
v := test.req.Validate()
if test.exp == "" {
is.NoErr(v)
return
}
if v == nil {
is.Fail()
}
is.Equal(test.exp, v.Error())
})
}
}