Skip to content

Commit 9046e05

Browse files
authored
Merge pull request #56 from ellemouton/grpc-client
multi: grpc client conn
2 parents f2a6d39 + b6d72c3 commit 9046e05

File tree

10 files changed

+672
-367
lines changed

10 files changed

+672
-367
lines changed

cmd/wasm-client/lnd_conn.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ func mailboxRPCConnection(mailboxServer, pairingPhrase string,
3030
)
3131

3232
ctx := context.Background()
33-
transportConn, err := mailbox.NewClient(ctx, connData)
33+
transportConn, err := mailbox.NewWebsocketsClient(
34+
ctx, mailboxServer, connData,
35+
)
3436
if err != nil {
3537
return nil, nil, err
3638
}

itest/client_harness.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import (
1212
"github.com/lightninglabs/lightning-node-connect/mailbox"
1313
"github.com/lightningnetwork/lnd/keychain"
1414
"google.golang.org/grpc"
15+
"google.golang.org/grpc/credentials"
1516
)
1617

1718
type clientHarness struct {
1819
serverAddr string
20+
grpcClient bool
21+
tlsConfig *tls.Config
1922

2023
grpcConn *grpc.ClientConn
2124
clientConn mockrpc.MockServiceClient
@@ -28,15 +31,24 @@ type clientHarness struct {
2831
cancel func()
2932
}
3033

31-
func newClientHarness(serverAddress string, entropy []byte) (*clientHarness,
32-
error) {
34+
func newClientHarness(serverAddress string, entropy []byte, insecure,
35+
grpcClient bool) (*clientHarness, error) {
3336

3437
privKey, err := btcec.NewPrivateKey()
3538
if err != nil {
3639
return nil, err
3740
}
3841

42+
tlsConfig := &tls.Config{}
43+
if insecure {
44+
tlsConfig = &tls.Config{
45+
InsecureSkipVerify: true,
46+
}
47+
}
48+
3949
return &clientHarness{
50+
tlsConfig: tlsConfig,
51+
grpcClient: grpcClient,
4052
serverAddr: serverAddress,
4153
passphraseEntropy: entropy,
4254
localStatic: &keychain.PrivKeyECDH{PrivKey: privKey},
@@ -62,16 +74,27 @@ func (c *clientHarness) start() error {
6274
},
6375
)
6476

65-
transportConn, err := mailbox.NewClient(ctx, connData)
77+
var err error
78+
if c.grpcClient {
79+
c.client, err = mailbox.NewGrpcClient(
80+
ctx, c.serverAddr, connData,
81+
grpc.WithTransportCredentials(
82+
credentials.NewTLS(c.tlsConfig),
83+
),
84+
)
85+
} else {
86+
c.client, err = mailbox.NewWebsocketsClient(
87+
ctx, c.serverAddr, connData,
88+
)
89+
}
6690
if err != nil {
6791
return err
6892
}
69-
c.client = transportConn
7093

7194
noiseConn := mailbox.NewNoiseGrpcConn(connData)
7295

7396
dialOpts := []grpc.DialOption{
74-
grpc.WithContextDialer(transportConn.Dial),
97+
grpc.WithContextDialer(c.client.Dial),
7598
grpc.WithTransportCredentials(noiseConn),
7699
grpc.WithPerRPCCredentials(noiseConn),
77100
grpc.WithDefaultCallOptions(

itest/connection_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func testHashmailServerReconnect(t *harnessTest) {
4646

4747
// Shut down hashmail server
4848
require.NoError(t.t, t.hmserver.stop())
49-
t.t.Logf("")
5049

5150
// Check that the client and server status are updated appropriately.
5251
assertServerStatus(t, mailbox.ServerStatusNotConnected)

itest/integration_test.go

Lines changed: 36 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,61 @@
11
package itest
22

33
import (
4+
"fmt"
45
"testing"
56
)
67

7-
const testnetMailbox = "mailbox.testnet.lightningcluster.com:443"
8-
98
// TestLightningNodeConnect runs the itests against a local mailbox instance.
109
func TestLightningNodeConnect(t *testing.T) {
1110
// If no tests are registered, then we can exit early.
1211
if len(testCases) == 0 {
1312
t.Skip("integration tests not selected")
1413
}
1514

16-
ht := newHarnessTest(t, nil, nil, nil)
17-
ht.setupLogging()
15+
setupLogging(t)
16+
17+
testConfigs := []*testConfig{
18+
{stagingMailbox: false, grpcClientConn: false},
19+
{stagingMailbox: false, grpcClientConn: true},
20+
{stagingMailbox: true, grpcClientConn: false},
21+
{stagingMailbox: true, grpcClientConn: true},
22+
}
1823

1924
t.Logf("Running %v integration tests", len(testCases))
2025
for _, testCase := range testCases {
2126

2227
testCase := testCase
28+
for _, config := range testConfigs {
29+
config := config
2330

24-
success := t.Run(testCase.name, func(t1 *testing.T) {
25-
clientHarness, serverHarness, hashmailHarness := setupHarnesses(t1)
26-
27-
ht := newHarnessTest(
28-
t1, clientHarness, serverHarness,
29-
hashmailHarness,
30-
)
31-
32-
// Now we have everything to run the test case.
33-
ht.RunTestCase(testCase)
34-
35-
// Shut down both client, server and hashmail server
36-
// to remove all state.
37-
err := ht.shutdown()
38-
if err != nil {
39-
t1.Fatalf("error shutting down harness: %v",
40-
err)
31+
if config.stagingMailbox && testCase.localMailboxOnly {
32+
continue
4133
}
42-
})
43-
44-
// Close at the first failure. Mimic behavior of original test
45-
// framework.
46-
if !success {
47-
break
48-
}
49-
}
50-
}
51-
52-
// TestLightningNodeConnectTestnetMailbox runs the itests using the mailbox
53-
// running in the LL testnet environment.
54-
func TestLightningNodeConnectTestnetMailbox(t *testing.T) {
55-
// If no tests are registered, then we can exit early.
56-
if len(stagingMailboxTests) == 0 {
57-
t.Skip("integration tests not selected")
58-
}
5934

60-
ht := newHarnessTest(t, nil, nil, nil)
61-
ht.setupLogging()
62-
63-
t.Logf("Running %v integration tests", len(stagingMailboxTests))
64-
for _, testCase := range stagingMailboxTests {
65-
66-
testCase := testCase
67-
68-
success := t.Run(testCase.name, func(t1 *testing.T) {
69-
clientHarness, serverHarness :=
70-
setupClientAndServerHarnesses(
71-
t1, testnetMailbox, false,
72-
)
73-
74-
ht := newHarnessTest(
75-
t1, clientHarness, serverHarness, nil,
76-
)
77-
78-
// Now we have everything to run the test case.
79-
ht.RunTestCase(testCase)
80-
81-
// Shut down both client, server and hashmail server
82-
// to remove all state.
83-
err := ht.shutdown()
84-
if err != nil {
85-
t1.Fatalf("error shutting down harness: %v",
86-
err)
35+
name := fmt.Sprintf("%s(stagingMailbox:%t,"+
36+
"grpcClientConn:%t)", testCase.name,
37+
config.stagingMailbox, config.grpcClientConn)
38+
39+
success := t.Run(name, func(t1 *testing.T) {
40+
ht := newHarnessTest(t1, config)
41+
42+
// Now we have everything to run the test case.
43+
ht.RunTestCase(testCase)
44+
45+
// Shut down both client, server and hashmail
46+
// server to remove all state.
47+
err := ht.shutdown()
48+
if err != nil {
49+
t1.Fatalf("error shutting down "+
50+
"harness: %v", err)
51+
}
52+
})
53+
54+
// Close at the first failure. Mimic behavior of
55+
// original test framework.
56+
if !success {
57+
break
8758
}
88-
})
89-
90-
// Close at the first failure. Mimic behavior of original test
91-
// framework.
92-
if !success {
93-
break
9459
}
9560
}
9661
}

0 commit comments

Comments
 (0)