-
Notifications
You must be signed in to change notification settings - Fork 28
/
orbitdb_many_adds_test.go
79 lines (63 loc) · 1.59 KB
/
orbitdb_many_adds_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
package weshnet
import (
"context"
crand "crypto/rand"
"fmt"
"os"
"testing"
"github.com/libp2p/go-libp2p/core/crypto"
orbitdb "berty.tech/go-orbit-db"
"berty.tech/weshnet/v2/pkg/cryptoutil"
"berty.tech/weshnet/v2/pkg/ipfsutil"
"berty.tech/weshnet/v2/pkg/protocoltypes"
)
func TestAdd(t *testing.T) {
amount := 20 // speeding up tests, 2000 takes ~25 seconds
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ipfs := ipfsutil.TestingCoreAPI(ctx, t)
dir := "./orbitdb/benchmarks"
defer os.RemoveAll(dir)
orbit, err := orbitdb.NewOrbitDB(ctx, ipfs.API(), &orbitdb.NewOrbitDBOptions{Directory: &dir})
if err != nil {
t.Fatal(err)
}
defer orbit.Close()
if err := orbit.RegisterAccessControllerType(NewSimpleAccessController); err != nil {
t.Fatal(err)
}
sigk, _, err := crypto.GenerateEd25519Key(crand.Reader)
if err != nil {
t.Fatal(err)
}
ks := &BertySignedKeyStore{}
err = ks.SetKey(sigk)
if err != nil {
t.Fatal(err)
}
sigkB, err := cryptoutil.SeedFromEd25519PrivateKey(sigk)
if err != nil {
t.Fatal(err)
}
pubkB, err := sigk.GetPublic().Raw()
if err != nil {
t.Fatal(err)
}
g := &protocoltypes.Group{PublicKey: pubkB, Secret: sigkB}
replicate := false
opts, err := DefaultOrbitDBOptions(g, &orbitdb.CreateDBOptions{Replicate: &replicate}, ks, "log", GroupOpenModeWrite)
if err != nil {
t.Fatal(err)
}
db, err := orbit.Log(ctx, "DemoLog", opts)
if err != nil {
t.Fatal(err)
}
defer db.Drop()
defer db.Close()
for n := 0; n < amount; n++ {
if _, err := db.Add(ctx, []byte(fmt.Sprintf("%d", n))); err != nil {
t.Fatal(err)
}
}
}