forked from OpenBazaar/openbazaar-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
78 lines (67 loc) · 1.69 KB
/
node.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
package test
import (
// "github.com/ipfs/go-ipfs/thirdparty/testutil"
"github.com/OpenBazaar/openbazaar-go/core"
"github.com/OpenBazaar/openbazaar-go/ipfs"
"github.com/OpenBazaar/openbazaar-go/net"
"github.com/OpenBazaar/openbazaar-go/net/service"
"github.com/OpenBazaar/openbazaar-go/repo"
"github.com/OpenBazaar/spvwallet"
"github.com/btcsuite/btcd/chaincfg"
"gx/ipfs/QmWUswjn261LSyVxWAEpMVtPdy8zmKBJJfBpG3Qdpa8ZsE/go-libp2p-peer"
)
// NewNode creates a new *core.OpenBazaarNode prepared for testing
func NewNode() (*core.OpenBazaarNode, error) {
// Create test repo
repository, err := NewRepository()
if err != nil {
return nil, err
}
repository.Reset()
if err != nil {
return nil, err
}
// Create test ipfs node
ipfsNode, err := ipfs.NewMockNode()
if err != nil {
return nil, err
}
// Create test context
ctx, err := ipfs.MockCmdsCtx()
if err != nil {
return nil, err
}
// Create test wallet
mnemonic, err := repository.DB.Config().GetMnemonic()
if err != nil {
return nil, err
}
walletCfg, err := repo.GetWalletConfig(repository.ConfigFile())
if err != nil {
return nil, err
}
wallet, err := spvwallet.NewSPVWallet(
mnemonic,
&chaincfg.TestNet3Params, 50000, 8000, 16000, 24000, walletCfg.FeeAPI,
repository.Path,
repository.DB,
"OpenBazaar-Test",
walletCfg.TrustedPeer,
nil,
NewLogger(),
)
if err != nil {
return nil, err
}
// Put it all together in an OpenBazaarNode
node := &core.OpenBazaarNode{
Context: ctx,
RepoPath: GetRepoPath(),
IpfsNode: ipfsNode,
Datastore: repository.DB,
Wallet: wallet,
BanManager: net.NewBanManager([]peer.ID{}),
}
node.Service = service.New(node, ctx, repository.DB)
return node, nil
}