@@ -3,12 +3,18 @@ package proof
33import (
44 "bytes"
55 "context"
6+ "fmt"
7+ "net/url"
68 "testing"
79
810 "github.com/lightninglabs/taproot-assets/asset"
911 "github.com/lightninglabs/taproot-assets/fn"
1012 "github.com/lightninglabs/taproot-assets/internal/test"
13+ "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
14+ "github.com/lightningnetwork/lnd/lntest/port"
1115 "github.com/stretchr/testify/require"
16+ "google.golang.org/grpc"
17+ "google.golang.org/grpc/credentials/insecure"
1218)
1319
1420// TestUniverseRpcCourierLocalArchiveShortCut tests that the local archive is
@@ -72,3 +78,71 @@ func TestUniverseRpcCourierLocalArchiveShortCut(t *testing.T) {
7278 })
7379 require .ErrorContains (t , err , "is missing outpoint" )
7480}
81+
82+ // TestCheckUniverseRpcCourierConnection tests that we can connect to the
83+ // universe rpc courier. We also test that we fail to connect to a
84+ // universe rpc courier that is not listening on the given address.
85+ func TestCheckUniverseRpcCourierConnection (t * testing.T ) {
86+ serverOpts := []grpc.ServerOption {
87+ grpc .Creds (insecure .NewCredentials ()),
88+ }
89+ grpcServer := grpc .NewServer (serverOpts ... )
90+
91+ server := MockUniverseServer {}
92+ universerpc .RegisterUniverseServer (grpcServer , & server )
93+
94+ // We also grab a port that is free to listen on for our negative test.
95+ // Since we know the port is free, and we don't listen on it, we expect
96+ // the connection to fail.
97+ noConnectPort := port .NextAvailablePort ()
98+ noConnectAddr := fmt .Sprintf (test .ListenAddrTemplate , noConnectPort )
99+
100+ mockServerAddr , cleanup , err := test .StartMockGRPCServer (
101+ t , grpcServer , true ,
102+ )
103+ require .NoError (t , err )
104+ t .Cleanup (cleanup )
105+
106+ tests := []struct {
107+ name string
108+ courierAddr * url.URL
109+ expectErr string
110+ }{
111+ {
112+ name : "valid universe rpc courier" ,
113+ courierAddr : MockCourierURL (
114+ t , UniverseRpcCourierType , mockServerAddr ,
115+ ),
116+ },
117+ {
118+ name : "valid universe rpc courier, but can't connect" ,
119+ courierAddr : MockCourierURL (
120+ t , UniverseRpcCourierType , noConnectAddr ,
121+ ),
122+ expectErr : "unable to connect to courier service" ,
123+ },
124+ }
125+
126+ for _ , tt := range tests {
127+ t .Run (tt .name , func (t * testing.T ) {
128+ // We use a short timeout here, since we don't want to
129+ // wait for the full default timeout of the funding
130+ // controller
131+ ctxt , cancel := context .WithTimeout (
132+ context .Background (), test .StartupWaitTime * 2 ,
133+ )
134+ defer cancel ()
135+
136+ err := CheckUniverseRpcCourierConnection (
137+ ctxt , test .StartupWaitTime , tt .courierAddr ,
138+ )
139+ if tt .expectErr != "" {
140+ require .ErrorContains (t , err , tt .expectErr )
141+
142+ return
143+ }
144+
145+ require .NoError (t , err )
146+ })
147+ }
148+ }
0 commit comments