Skip to content

Commit

Permalink
itest: fix fee estimation test
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Nov 8, 2024
1 parent a5b8c98 commit 6a69824
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 4 additions & 1 deletion itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,10 @@ func AssertAssetOutboundTransferWithOutputs(t *testing.T,
out := transfer.Outputs[idx]
require.Contains(t, outpoints, out.Anchor.Outpoint)
require.Contains(t, scripts, string(out.ScriptKey))
require.Equal(t, expectedAmounts[idx], out.Amount)
require.Equalf(
t, expectedAmounts[idx], out.Amount,
"expected amounts: %v, transfer: %v",
expectedAmounts, toJSON(t, transfer))
}

firstIn := transfer.Inputs[0]
Expand Down
24 changes: 13 additions & 11 deletions itest/fee_estimation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ func testFeeEstimation(t *harnessTest) {
rpcAssets := MintAssetsConfirmBatch(
t.t, t.lndHarness.Miner().Client, t.tapd, simpleAssets,
)
normalAsset := rpcAssets[0]
normalAssetId := normalAsset.AssetGenesis.AssetId

// Check the final fee rate of the mint TX.
rpcMintOutpoint := rpcAssets[0].ChainAnchor.AnchorOutpoint
rpcMintOutpoint := normalAsset.ChainAnchor.AnchorOutpoint
mintOutpoint, err := wire.NewOutPointFromString(rpcMintOutpoint)
require.NoError(t.t, err)

Expand All @@ -81,16 +83,15 @@ func testFeeEstimation(t *harnessTest) {
)

// Split the normal asset to create a transfer with two anchor outputs.
normalAssetId := rpcAssets[0].AssetGenesis.AssetId
splitAmount := rpcAssets[0].Amount / 2
splitAmount := normalAsset.Amount / 2
addr, stream := NewAddrWithEventStream(
t.t, t.tapd, &taprpc.NewAddrRequest{
AssetId: normalAssetId,
Amt: splitAmount,
},
)

AssertAddrCreated(t.t, t.tapd, rpcAssets[0], addr)
AssertAddrCreated(t.t, t.tapd, normalAsset, addr)
sendResp, sendEvents := sendAssetsToAddr(t, t.tapd, addr)

transferIdx := 0
Expand Down Expand Up @@ -121,7 +122,7 @@ func testFeeEstimation(t *harnessTest) {
},
)

AssertAddrCreated(t.t, t.tapd, rpcAssets[0], addr2)
AssertAddrCreated(t.t, t.tapd, normalAsset, addr2)
sendResp, sendEvents = sendAssetsToAddr(t, t.tapd, addr2)

ConfirmAndAssertOutboundTransfer(
Expand Down Expand Up @@ -157,7 +158,7 @@ func testFeeEstimation(t *harnessTest) {
[]*UTXORequest{initialUTXOs[3]},
)

AssertAddrCreated(t.t, t.tapd, rpcAssets[0], addr3)
AssertAddrCreated(t.t, t.tapd, normalAsset, addr3)
_, err = t.tapd.SendAsset(ctxt, &taprpc.SendAssetRequest{
TapAddrs: []string{addr3.Encoded},
})
Expand All @@ -166,23 +167,24 @@ func testFeeEstimation(t *harnessTest) {
)

// The transfer should also be rejected if the manually-specified
// feerate fails the sanity check against the fee estimator's fee floor
// fee rate fails the sanity check against the fee estimator's fee floor
// of 253 sat/kw, or 1.012 sat/vB.
_, err = t.tapd.SendAsset(ctxt, &taprpc.SendAssetRequest{
TapAddrs: []string{addr3.Encoded},
FeeRate: uint32(chainfee.FeePerKwFloor) - 1,
})
require.ErrorContains(t.t, err, "manual fee rate below floor")

// After failure at the high feerate, we should still be able to make a
// transfer at a very low feerate.
// After failure at the high fee rate, we should still be able to make a
// transfer at a very low fee rate.
t.lndHarness.SetFeeEstimateWithConf(lowFeeRate, 6)
sendResp, sendEvents = sendAssetsToAddr(t, t.tapd, addr3)

ConfirmAndAssertOutboundTransfer(
t.t, t.lndHarness.Miner().Client, t.tapd, sendResp,
normalAssetId, []uint64{thirdSplitAmount, thirdSplitAmount},
transferIdx, transferIdx+1,
normalAssetId, []uint64{
splitAmount - thirdSplitAmount, thirdSplitAmount,
}, transferIdx, transferIdx+1,
)
transferIdx += 1
AssertNonInteractiveRecvComplete(t.t, t.tapd, transferIdx)
Expand Down

0 comments on commit 6a69824

Please sign in to comment.