/
path_multisig_address_test.go
93 lines (79 loc) · 2.09 KB
/
path_multisig_address_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
92
93
package btc
import (
"context"
"testing"
"github.com/hashicorp/vault/logical"
)
func TestMultiSigAddress(t *testing.T) {
b, storage := getTestBackend(t)
m := 2
n := 3
name := "test"
network := "testnet"
pubkeys := []string{"", ""}
_, err := newMultiSigWallet(t, b, storage, name, network, m, n, pubkeys)
if err != nil {
t.Fatal(err)
}
resp, err := newMultiSigAuthToken(t, b, storage, name)
token := resp.Data["token"].(string)
t.Run("Get address for multisig wallet", func(t *testing.T) {
resp, err := newMultiSigAddress(t, b, storage, name, token)
if err != nil {
t.Fatal(err)
}
if resp == nil {
t.Fatal("No response received")
}
})
t.Run("Get address with expired auth token should fail", func(t *testing.T) {
t.Parallel()
exp := InvalidTokenError
_, err := newMultiSigAddress(t, b, storage, name, token)
if err == nil {
t.Fatal("Should have failed before")
}
if err.Error() != exp {
t.Fatalf("Want: %v, got %v", exp, err)
}
})
t.Run("Get address without auth token should fail", func(t *testing.T) {
t.Parallel()
token := ""
exp := MissingTokenError
_, err := newMultiSigAddress(t, b, storage, name, token)
if err == nil {
t.Fatal("Should have failed before")
}
if err.Error() != exp {
t.Fatalf("Want: %v, got: %v", exp, err)
}
})
t.Run("Get address with invalid auth token should fail", func(t *testing.T) {
t.Parallel()
token := "testtoken"
exp := InvalidTokenError
_, err := newMultiSigAddress(t, b, storage, name, token)
if err == nil {
t.Fatal("Should have failed before")
}
if err.Error() != exp {
t.Fatalf("Want: %v, got: %v", exp, err)
}
})
}
func newMultiSigAddress(t *testing.T, b logical.Backend, store logical.Storage, name string, token string) (*logical.Response, error) {
resp, err := b.HandleRequest(context.Background(), &logical.Request{
Storage: store,
Path: "address/multisig/" + name,
Operation: logical.UpdateOperation,
Data: map[string]interface{}{"token": token},
})
if err != nil {
return nil, err
}
if resp.IsError() {
return nil, resp.Error()
}
return resp, nil
}