mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-01 02:51:37 +02:00
itest: add gettransactiondetails
This commit is contained in:
@ -829,32 +829,22 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
|
|||||||
// assertTxLabel is a helper function which finds a target tx in our
|
// assertTxLabel is a helper function which finds a target tx in our
|
||||||
// set of transactions and checks that it has the desired label.
|
// set of transactions and checks that it has the desired label.
|
||||||
assertTxLabel := func(targetTx, label string) error {
|
assertTxLabel := func(targetTx, label string) error {
|
||||||
// List all transactions relevant to our wallet, and find the
|
// Get the transaction from our wallet so that we can check
|
||||||
// tx so that we can check the correct label has been set.
|
// that the correct label has been set.
|
||||||
txResp := ainz.RPC.GetTransactions(nil)
|
txResp := ainz.RPC.GetTransaction(
|
||||||
|
&walletrpc.GetTransactionRequest{
|
||||||
|
Txid: targetTx,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
require.NotNilf(ht, txResp, "target tx %v not found", targetTx)
|
||||||
|
|
||||||
var target *lnrpc.Transaction
|
// Make sure the labels match.
|
||||||
|
if txResp.Label == label {
|
||||||
// First we need to find the target tx.
|
|
||||||
for _, txn := range txResp.Transactions {
|
|
||||||
if txn.TxHash == targetTx {
|
|
||||||
target = txn
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we cannot find it, return an error.
|
|
||||||
if target == nil {
|
|
||||||
return fmt.Errorf("target tx %v not found", targetTx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, check the labels are matched.
|
|
||||||
if target.Label == label {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("labels not match, want: "+
|
return fmt.Errorf("labels not match, want: "+
|
||||||
"%v, got %v", label, target.Label)
|
"%v, got %v", label, txResp.Label)
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitTxLabel waits until the desired tx label is found or timeout.
|
// waitTxLabel waits until the desired tx label is found or timeout.
|
||||||
|
@ -3,6 +3,7 @@ package rpc
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -196,6 +197,19 @@ func (h *HarnessRPC) PublishTransaction(
|
|||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTransaction makes a RPC call to the node's WalletKitClient and asserts.
|
||||||
|
func (h *HarnessRPC) GetTransaction(
|
||||||
|
req *walletrpc.GetTransactionRequest) *lnrpc.Transaction {
|
||||||
|
|
||||||
|
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
resp, err := h.WalletKit.GetTransaction(ctxt, req)
|
||||||
|
h.NoError(err, "GetTransaction")
|
||||||
|
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
// BumpFee makes a RPC call to the node's WalletKitClient and asserts.
|
// BumpFee makes a RPC call to the node's WalletKitClient and asserts.
|
||||||
func (h *HarnessRPC) BumpFee(
|
func (h *HarnessRPC) BumpFee(
|
||||||
req *walletrpc.BumpFeeRequest) *walletrpc.BumpFeeResponse {
|
req *walletrpc.BumpFeeRequest) *walletrpc.BumpFeeResponse {
|
||||||
|
@ -1685,6 +1685,30 @@ func newTx(t *testing.T, r *rpctest.Harness, pubKey *btcec.PublicKey,
|
|||||||
return tx1
|
return tx1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// testGetTransactionDetails checks that GetTransactionDetails returns the
|
||||||
|
// correct amount after a transaction has been sent from alice to bob.
|
||||||
|
func testGetTransactionDetails(r *rpctest.Harness,
|
||||||
|
alice, bob *lnwallet.LightningWallet, t *testing.T) {
|
||||||
|
|
||||||
|
const txFee = int64(14500)
|
||||||
|
|
||||||
|
bobPkScript := newPkScript(t, bob, lnwallet.WitnessPubKey)
|
||||||
|
txFeeRate := chainfee.SatPerKWeight(2500)
|
||||||
|
amountSats := btcutil.Amount(btcutil.SatoshiPerBitcoin - txFee)
|
||||||
|
output := &wire.TxOut{
|
||||||
|
Value: int64(amountSats),
|
||||||
|
PkScript: bobPkScript,
|
||||||
|
}
|
||||||
|
tx := sendCoins(t, r, alice, bob, output, txFeeRate, true, 1)
|
||||||
|
txHash := tx.TxHash()
|
||||||
|
assertTxInWallet(t, alice, txHash, true)
|
||||||
|
assertTxInWallet(t, bob, txHash, true)
|
||||||
|
|
||||||
|
txDetails, err := bob.GetTransactionDetails(&txHash)
|
||||||
|
require.NoError(t, err, "unable to receive transaction details")
|
||||||
|
require.Equal(t, txDetails.Value, amountSats, "tx value")
|
||||||
|
}
|
||||||
|
|
||||||
// testPublishTransaction checks that PublishTransaction returns the expected
|
// testPublishTransaction checks that PublishTransaction returns the expected
|
||||||
// error types in case the transaction being published conflicts with the
|
// error types in case the transaction being published conflicts with the
|
||||||
// current mempool or chain.
|
// current mempool or chain.
|
||||||
@ -2794,6 +2818,10 @@ var walletTests = []walletTestCase{
|
|||||||
name: "transaction details",
|
name: "transaction details",
|
||||||
test: testListTransactionDetails,
|
test: testListTransactionDetails,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "get transaction details",
|
||||||
|
test: testGetTransactionDetails,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "publish transaction",
|
name: "publish transaction",
|
||||||
test: testPublishTransaction,
|
test: testPublishTransaction,
|
||||||
|
Reference in New Issue
Block a user