|
| 1 | +package itest |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/lightninglabs/taproot-assets/rfqmsg" |
| 7 | + tchrpc "github.com/lightninglabs/taproot-assets/taprpc/tapchannelrpc" |
| 8 | + "github.com/lightningnetwork/lnd/lnrpc" |
| 9 | + "github.com/lightningnetwork/lnd/lnrpc/routerrpc" |
| 10 | + "github.com/lightningnetwork/lnd/record" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | +) |
| 13 | + |
| 14 | +var ( |
| 15 | + dummyByteArr = [32]byte{0x01, 0x02, 0x03, 0x04} |
| 16 | +) |
| 17 | + |
| 18 | +// testChannelRPCs tests that we can call all Taproot Asset Channel related |
| 19 | +// RPCs and get the correct error message back (as we can't really test the |
| 20 | +// actual functionality without running within litd). This at least makes sure |
| 21 | +// we've set up everything correctly in terms of macaroons and permissions. |
| 22 | +func testChannelRPCs(t *harnessTest) { |
| 23 | + ctx := context.Background() |
| 24 | + |
| 25 | + // The EncodeCustomRecords RPC is available, as it only does static |
| 26 | + // encoding. |
| 27 | + encodeReq := &tchrpc.EncodeCustomRecordsRequest_RouterSendPayment{ |
| 28 | + RouterSendPayment: &tchrpc.RouterSendPaymentData{ |
| 29 | + RfqId: dummyByteArr[:], |
| 30 | + }, |
| 31 | + } |
| 32 | + encodeResp, err := t.tapd.EncodeCustomRecords( |
| 33 | + ctx, &tchrpc.EncodeCustomRecordsRequest{ |
| 34 | + Input: encodeReq, |
| 35 | + }, |
| 36 | + ) |
| 37 | + require.NoError(t.t, err) |
| 38 | + require.Len(t.t, encodeResp.CustomRecords, 2) |
| 39 | + |
| 40 | + var rfqIdType rfqmsg.HtlcRfqIDType |
| 41 | + rfqIdTlvTypeNumber := uint64(rfqIdType.TypeVal()) |
| 42 | + require.Len(t.t, encodeResp.CustomRecords[rfqIdTlvTypeNumber], 32) |
| 43 | + |
| 44 | + // All the following calls can't go fully through, and we'll encounter |
| 45 | + // an error at some point. |
| 46 | + _, err = t.tapd.FundChannel(ctx, &tchrpc.FundChannelRequest{}) |
| 47 | + require.ErrorContains(t.t, err, "only available when running inside") |
| 48 | + |
| 49 | + // Try the keysend path first, which should go all the way through to |
| 50 | + // lnd, where it should fail because we didn't set a timeout. |
| 51 | + stream, err := t.tapd.SendPayment(ctx, &tchrpc.SendPaymentRequest{ |
| 52 | + AssetAmount: 123, |
| 53 | + AssetId: dummyByteArr[:], |
| 54 | + PaymentRequest: &routerrpc.SendPaymentRequest{ |
| 55 | + DestCustomRecords: map[uint64][]byte{ |
| 56 | + record.KeySendType: dummyByteArr[:], |
| 57 | + }, |
| 58 | + }, |
| 59 | + }) |
| 60 | + require.NoError(t.t, err) |
| 61 | + |
| 62 | + _, err = stream.Recv() |
| 63 | + require.ErrorContains(t.t, err, "timeout_seconds") |
| 64 | + |
| 65 | + // Now let's also try the invoice path, which should fail because we |
| 66 | + // don't have any asset channels with peers that we could ask for a |
| 67 | + // quote. |
| 68 | + invoiceResp := t.lndHarness.Alice.RPC.AddInvoice(&lnrpc.Invoice{ |
| 69 | + AmtPaidSat: 1234, |
| 70 | + }) |
| 71 | + stream, err = t.tapd.SendPayment(ctx, &tchrpc.SendPaymentRequest{ |
| 72 | + AssetId: dummyByteArr[:], |
| 73 | + PaymentRequest: &routerrpc.SendPaymentRequest{ |
| 74 | + PaymentRequest: invoiceResp.PaymentRequest, |
| 75 | + }, |
| 76 | + }) |
| 77 | + require.NoError(t.t, err) |
| 78 | + |
| 79 | + _, err = stream.Recv() |
| 80 | + require.ErrorContains(t.t, err, "no asset channel balance found") |
| 81 | + |
| 82 | + // We can't add an invoice either, because we have no peers to do RFQ |
| 83 | + // negotiation with. |
| 84 | + _, err = t.tapd.AddInvoice(ctx, &tchrpc.AddInvoiceRequest{ |
| 85 | + AssetAmount: 123, |
| 86 | + AssetId: dummyByteArr[:], |
| 87 | + InvoiceRequest: &lnrpc.Invoice{ |
| 88 | + Private: false, |
| 89 | + }, |
| 90 | + }) |
| 91 | + require.ErrorContains(t.t, err, "no asset channel balance found") |
| 92 | +} |
0 commit comments