-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstorage_test.go
115 lines (103 loc) · 2.49 KB
/
storage_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package handshake
import (
"encoding/base64"
"testing"
)
func TestHashmapSet(t *testing.T) {
// this needs to be refactored to use a mock server
privateKeyString := "6zjTWCoDkKESjroDj26qrw0/xSU0B14Co/lIZZHhbHUFFt6rMcqyLt21y1PmoPJbokhXrvO4p+zauvk+GuujzA=="
privateKey, err := base64.StdEncoding.DecodeString(privateKeyString)
if err != nil {
t.Errorf("base64 failed to decode: %v\n", err)
}
publicKey := privateKey[32:]
n := node{
URL: "https://prototype.hashmap.sh",
}
sig := signatureAlgorithm{
Type: ed25519,
PrivateKey: privateKey,
PublicKey: publicKey,
}
opts := StorageOptions{
WriteNodes: []node{n},
Signatures: []signatureAlgorithm{sig},
WriteRule: defaultConsensusRule,
}
hms, err := newHashmapStorage(opts)
if err != nil {
t.Errorf("new hashmapStore failed: %v\n", err)
}
if _, err := hms.Set("", []byte("this was generated from a go test. right now for real")); err != nil {
t.Errorf("set failed: %v\n", err)
}
}
func TestHashmapStorageGet(t *testing.T) {
n := node{
URL: "https://prototype.hashmap.sh/2DrjgbL8QfKRvxU9KtFYFdNiPZrQijyxkvWXH17QnvNmzB3apR",
// 2Drjgb5DseoVAvRLngcVmd4YfJAi3J1145kiNFV3CL32Hs6vzb
}
opts := StorageOptions{
ReadNodes: []node{n},
ReadRule: defaultConsensusRule,
}
hms, err := newHashmapStorage(opts)
if err != nil {
t.Errorf("new hashmapStore failed: %v\n", err)
}
response, err := hms.Get("")
if err != nil {
t.Errorf("response failed: %v\n", err)
}
t.Log(string(response))
}
func TestGetFromIPFS(t *testing.T) {
settings := make(map[string]string)
settings["query_type"] = "api"
happyNodes := []node{
// node{
// URL: "http://127.0.0.1:5001",
// Settings: settings,
// },
node{
URL: "https://ipfs.infura.io:5001/",
Settings: settings,
},
node{
URL: "https://cloudflare-ipfs.com",
},
}
hash := "QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN"
for _, n := range happyNodes {
resp, err := getFromIPFS(n, hash)
if err != nil {
t.Error(err)
}
t.Log(string(resp))
}
}
func TestPostToIPFS(t *testing.T) {
settings := make(map[string]string)
settings["query_type"] = "api"
happyNodes := []node{
// node{
// URL: "http://127.0.0.1:5001",
// Settings: settings,
// },
node{
URL: "https://ipfs.infura.io:5001/",
Settings: settings,
},
node{
URL: "https://hardbin.com",
},
}
body := []byte("hello, world")
for _, n := range happyNodes {
resp, err := postToIPFS(n, body)
if err != nil {
t.Error(err)
}
t.Log(string(resp))
}
}