forked from scaling-lightning/scaling-lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
82 lines (71 loc) · 2.4 KB
/
example_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
package main
import (
"testing"
"time"
"github.com/cockroachdb/errors"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
sl "github.com/scaling-lightning/scaling-lightning/pkg/network"
"github.com/scaling-lightning/scaling-lightning/pkg/tools"
"github.com/stretchr/testify/assert"
)
// will need a longish (few mins) timeout
func TestMain(t *testing.T) {
zerolog.SetGlobalLevel(zerolog.TraceLevel)
assert := assert.New(t)
network := sl.NewSLNetwork("../helmfiles/public.yaml", "", sl.Regtest)
err := network.Start()
if err != nil {
log.Fatal().Err(err).Msg("Problem starting network")
}
cln2, err := network.GetLightningNode("cln2")
assert.NoError(err)
assert.NoError(err)
defer func() {
err = network.Stop()
assert.NoError(err)
}()
// this one will take a little while as the network is starting up
err = tools.Retry(func() error {
_, err := network.Send("bitcoind", "cln1", 1_000_000)
return errors.Wrap(err, "Sending million sats to cln1")
}, time.Second*15, time.Minute*2)
assert.NoError(err)
err = tools.Retry(func() error {
return errors.Wrap(network.ConnectPeer("cln1", "cln2"), "Connecting cln1 to cln2")
}, time.Second*15, time.Minute*3)
assert.NoError(err)
err = tools.Retry(func() error {
_, err := network.OpenChannel("cln1", "cln2", 40_001)
return errors.Wrap(err, "Opening channel from cln1 to cln2")
}, time.Second*15, time.Minute*3)
assert.NoError(err)
err = tools.Retry(func() error {
balance, err := network.GetWalletBalance("cln1")
if err != nil {
return errors.Wrap(err, "Getting cln1 balance")
}
log.Info().Msgf("cln1 balance: %d", balance.AsSats())
return nil
}, time.Second*15, time.Minute*2)
assert.NoError(err)
err = tools.Retry(func() error {
connectionDetails, err := network.GetConnectionDetails("cln2")
if err != nil {
return errors.Wrap(err, "Getting cln2 connection details")
}
log.Info().Msgf("cln2 connection host: %v", connectionDetails[0].Host)
log.Info().Msgf("cln2 connection host: %d", connectionDetails[0].Port)
return nil
}, time.Second*15, time.Minute*2)
assert.NoError(err)
err = tools.Retry(func() error {
connectionFiles, err := cln2.GetConnectionFiles(network.Network.String(), "")
if err != nil {
return errors.Wrap(err, "Getting cln2 connection files")
}
log.Info().Msgf("cln2 client cert size : %v", len(connectionFiles.CLN.ClientCert))
return nil
}, time.Second*15, time.Minute*2)
assert.NoError(err)
}