forked from xplorfin/lndmock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlnd_test.go
105 lines (76 loc) · 2.13 KB
/
lnd_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
package mock
import (
"testing"
"github.com/lightningnetwork/lnd/lnrpc"
. "github.com/stretchr/testify/assert"
)
// run through this https://git.io/JqcC4 workflow
func TestLightningMocker(t *testing.T) {
mocker := NewLightningMocker()
defer func() {
Nil(t, mocker.Teardown())
}()
err := mocker.Initialize()
Nil(t, err)
// start btcd as a prereq to lnd
btcdContainer, err := mocker.CreateBtcdContainer()
Nil(t, err)
// start alice's lnd instance
aliceContainer, err := mocker.CreateLndContainer("alice")
Nil(t, err)
// get alices hostname
aliceAddress, err := aliceContainer.Address()
Nil(t, err)
alicePubKey, err := aliceContainer.GetPubKey()
Nil(t, err)
err = btcdContainer.MineToAddress(aliceAddress, 500)
Nil(t, err)
// start bob's lnd instance
bobContainer, err := mocker.CreateLndContainer("bob")
Nil(t, err)
// give bob btc
bobAddress, err := bobContainer.Address()
Nil(t, err)
err = btcdContainer.MineToAddress(bobAddress, 500)
Nil(t, err)
err = aliceContainer.WaitForSync(true, false)
Nil(t, err)
err = bobContainer.WaitForSync(true, false)
Nil(t, err)
// open alice->bob channel
err = bobContainer.OpenChannel(alicePubKey, "alice", 100000)
Nil(t, err)
// get bob pub key
bobPubKey, err := bobContainer.GetPubKey()
Nil(t, err)
err = btcdContainer.Mine(5)
Nil(t, err)
err = bobContainer.WaitForCondition(func(res *lnrpc.GetInfoResponse) bool {
return res.NumActiveChannels == 1
})
Nil(t, err)
// open bob->alice container
err = aliceContainer.OpenChannel(bobPubKey, "bob", 100000)
Nil(t, err)
err = btcdContainer.Mine(5)
Nil(t, err)
err = aliceContainer.WaitForCondition(func(res *lnrpc.GetInfoResponse) bool {
return res.NumActiveChannels == 2
})
Nil(t, err)
err = aliceContainer.WaitForSync(true, true)
Nil(t, err)
err = bobContainer.WaitForSync(true, true)
Nil(t, err)
testRPCClient(t, bobContainer)
testRPCClient(t, aliceContainer)
}
func testRPCClient(t *testing.T, c LndContainer) {
client, err := c.RPCClient()
Nil(t, err)
req := lnrpc.GetInfoRequest{}
res, err := client.GetInfo(c.c.Ctx, &req)
Nil(t, err)
Equal(t, res.NumActiveChannels, uint32(2))
Nil(t, err)
}