@@ -3,7 +3,9 @@ package itest
33import (
44 "context"
55 "io/ioutil"
6+ "strings"
67 "testing"
8+ "time"
79
810 "github.com/btcsuite/btcd/btcutil"
911 "github.com/lightninglabs/lightning-terminal/litrpc"
@@ -138,7 +140,15 @@ func runAccountSystemTest(t *harnessTest, node *HarnessNode, hostPort,
138140
139141 // Run the actual account restriction tests against the connection with
140142 // the account macaroon.
141- testAccountRestrictions (ctxa , t , net , rawConn , charlie , acctBalance )
143+ newAcctBalance := testAccountRestrictions (
144+ ctxa , t , rawConn , charlie , acctBalance ,
145+ )
146+
147+ // Test the same account restrictions with an LNC session that is bound
148+ // to the account.
149+ testAccountRestrictionsLNC (
150+ ctxm , t , rawConn , newAcctBalance , acctResp .Account .Id ,
151+ )
142152
143153 // Clean up our channel and payments, so we can start the next test
144154 // iteration with a clean slate.
@@ -151,11 +161,68 @@ func runAccountSystemTest(t *harnessTest, node *HarnessNode, hostPort,
151161 require .NoError (t .t , err )
152162}
153163
164+ // testAccountRestrictionsLNC tests that an account restricted session can also
165+ // be created through LNC.
166+ func testAccountRestrictionsLNC (ctxm context.Context , t * harnessTest ,
167+ rawConn grpc.ClientConnInterface , currentAccountBalance uint64 ,
168+ accountID string ) {
169+
170+ // We first need to create an LNC session that we can use to connect.
171+ // We use the UI password to create the session.
172+ litClient := litrpc .NewSessionsClient (rawConn )
173+ sessResp , err := litClient .AddSession (ctxm , & litrpc.AddSessionRequest {
174+ Label : "integration-test" ,
175+ SessionType : litrpc .SessionType_TYPE_MACAROON_ACCOUNT ,
176+ ExpiryTimestampSeconds : uint64 (
177+ time .Now ().Add (5 * time .Minute ).Unix (),
178+ ),
179+ MailboxServerAddr : mailboxServerAddr ,
180+ AccountId : accountID ,
181+ })
182+ require .NoError (t .t , err )
183+
184+ // Try the LNC connection now.
185+ connectPhrase := strings .Split (
186+ sessResp .Session .PairingSecretMnemonic , " " ,
187+ )
188+
189+ ctxb := context .Background ()
190+ ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
191+ defer cancel ()
192+
193+ rawLNCConn , err := connectMailbox (ctxt , connectPhrase )
194+ require .NoError (t .t , err )
195+
196+ lightningClient := lnrpc .NewLightningClient (rawLNCConn )
197+
198+ // The channel balance should always reflect our account balance.
199+ assertChannelBalance (
200+ ctxt , t .t , lightningClient , currentAccountBalance , 0 ,
201+ )
202+
203+ // The on-chain balance should always be zero, no on-chain transactions
204+ // should show up and nothing channel or peer related should be shown.
205+ assertWalletBalance (ctxt , t .t , lightningClient , 0 , 0 , 0 , 0 )
206+ assertNumChannels (ctxt , t .t , lightningClient , 0 , 0 , 0 , 0 )
207+ assertNumPeers (ctxt , t .t , lightningClient , 0 )
208+
209+ txnsResp , err := lightningClient .GetTransactions (
210+ ctxt , & lnrpc.GetTransactionsRequest {},
211+ )
212+ require .NoError (t .t , err )
213+ require .Len (t .t , txnsResp .Transactions , 0 )
214+
215+ // There should be invoices and payments from the previous test over RPC
216+ // directly.
217+ assertNumInvoices (ctxt , t .t , lightningClient , 1 )
218+ assertNumPayments (ctxt , t .t , lightningClient , 1 )
219+ }
220+
154221// testAccountRestrictions tests the different scenarios in which the account
155222// restricted RPC responses differ from the normal responses.
156223func testAccountRestrictions (ctxa context.Context , t * harnessTest ,
157- net * NetworkHarness , rawConn * grpc.ClientConn , charlie * HarnessNode ,
158- initialAccountBalance uint64 ) {
224+ rawConn grpc.ClientConnInterface , charlie * HarnessNode ,
225+ initialAccountBalance uint64 ) uint64 {
159226
160227 // The ctxa variable is the context with the restricted account macaroon
161228 // applied to it. But we also need a timeout context for things we do
@@ -217,6 +284,8 @@ func testAccountRestrictions(ctxa context.Context, t *harnessTest,
217284 ctxa , t .t , lightningClient ,
218285 initialAccountBalance + inboundPaymentAmt - outboundPaymentAmt , 0 ,
219286 )
287+
288+ return initialAccountBalance + inboundPaymentAmt - outboundPaymentAmt
220289}
221290
222291func assertChannelBalance (ctx context.Context , t * testing.T ,
0 commit comments