mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 06:44:23 +01:00
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
package itest
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/breez/lntest"
|
|
)
|
|
|
|
var defaultTimeout time.Duration = time.Second * 120
|
|
|
|
func TestLspd(t *testing.T) {
|
|
testCases := allTestCases
|
|
// runTests(t, testCases, "LND-lspd", func(h *lntest.TestHarness, m *lntest.Miner) (LspNode, *breezClient) {
|
|
// return NewLndLspdNode(h, m, "lsp"), newLndBreezClient(h, m, "breez-client")
|
|
// })
|
|
|
|
runTests(t, testCases, "CLN-lspd", func(h *lntest.TestHarness, m *lntest.Miner) (LspNode, *breezClient) {
|
|
return NewClnLspdNode(h, m, "lsp"), newClnBreezClient(h, m, "breez-client")
|
|
})
|
|
}
|
|
|
|
func runTests(t *testing.T, testCases []*testCase, prefix string, nodesFunc func(h *lntest.TestHarness, m *lntest.Miner) (LspNode, *breezClient)) {
|
|
for _, testCase := range testCases {
|
|
testCase := testCase
|
|
t.Run(fmt.Sprintf("%s: %s", prefix, testCase.name), func(t *testing.T) {
|
|
runTest(t, testCase, prefix, nodesFunc)
|
|
})
|
|
}
|
|
}
|
|
|
|
func runTest(t *testing.T, testCase *testCase, prefix string, nodesFunc func(h *lntest.TestHarness, m *lntest.Miner) (LspNode, *breezClient)) {
|
|
log.Printf("%s: Running test case '%s'", prefix, testCase.name)
|
|
var dd time.Duration
|
|
to := testCase.timeout
|
|
if to == dd {
|
|
to = defaultTimeout
|
|
}
|
|
|
|
deadline := time.Now().Add(to)
|
|
log.Printf("Using deadline %v", deadline.String())
|
|
|
|
h := lntest.NewTestHarness(t, deadline)
|
|
defer h.TearDown()
|
|
|
|
log.Printf("Creating miner")
|
|
miner := lntest.NewMiner(h)
|
|
log.Printf("Creating lsp")
|
|
lsp, c := nodesFunc(h, miner)
|
|
log.Printf("Run testcase")
|
|
testCase.test(&testParams{
|
|
t: t,
|
|
h: h,
|
|
m: miner,
|
|
c: c,
|
|
lsp: lsp,
|
|
})
|
|
}
|
|
|
|
type testCase struct {
|
|
name string
|
|
test func(t *testParams)
|
|
timeout time.Duration
|
|
}
|
|
|
|
var allTestCases = []*testCase{
|
|
{
|
|
name: "testOpenZeroConfChannelOnReceive",
|
|
test: testOpenZeroConfChannelOnReceive,
|
|
},
|
|
{
|
|
name: "testOpenZeroConfSingleHtlc",
|
|
test: testOpenZeroConfSingleHtlc,
|
|
},
|
|
{
|
|
name: "testZeroReserve",
|
|
test: testZeroReserve,
|
|
},
|
|
}
|