Skip to content

Commit 0c4e418

Browse files
committed
itest: fix output order
1 parent 900d2a7 commit 0c4e418

File tree

3 files changed

+74
-48
lines changed

3 files changed

+74
-48
lines changed

itest/assertions.go

+30
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,36 @@ func AssertNumGroups(t *testing.T, client taprpc.TaprootAssetsClient,
14121412
require.Equal(t, num, NumGroups(t, client))
14131413
}
14141414

1415+
// AssertNumBurns makes sure a given number of burns exists, then returns them.
1416+
func AssertNumBurns(t *testing.T, client taprpc.TaprootAssetsClient,
1417+
num int, req *taprpc.ListBurnsRequest) []*taprpc.AssetBurn {
1418+
1419+
ctxb := context.Background()
1420+
if req == nil {
1421+
req = &taprpc.ListBurnsRequest{}
1422+
}
1423+
1424+
var result []*taprpc.AssetBurn
1425+
err := wait.NoError(func() error {
1426+
burns, err := client.ListBurns(ctxb, req)
1427+
if err != nil {
1428+
return err
1429+
}
1430+
1431+
if err != nil {
1432+
return fmt.Errorf("wanted %d burns, got %d", num,
1433+
len(burns.Burns))
1434+
}
1435+
1436+
result = burns.Burns
1437+
1438+
return nil
1439+
}, defaultTimeout)
1440+
require.NoError(t, err)
1441+
1442+
return result
1443+
}
1444+
14151445
// NumGroups returns the current number of asset groups present.
14161446
func NumGroups(t *testing.T, client taprpc.TaprootAssetsClient) int {
14171447
ctxb := context.Background()

itest/burn_test.go

+19-34
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ func testBurnAssets(t *harnessTest) {
6464
// - 800 units to scriptKey4
6565
// anchor index 3 (automatic change output):
6666
// - 300 units to new script key
67-
outputAmounts := []uint64{1100, 1200, 1600, 800, 300}
67+
outputAmounts := []uint64{300, 1100, 1200, 1600, 800}
6868
vPkt := tappsbt.ForInteractiveSend(
69-
simpleAssetID, outputAmounts[0], scriptKey1, 0, 0, 0,
69+
simpleAssetID, outputAmounts[1], scriptKey1, 0, 0, 0,
7070
anchorInternalKeyDesc1, asset.V0, chainParams,
7171
)
7272
tappsbt.AddOutput(
73-
vPkt, outputAmounts[1], scriptKey2, 0, anchorInternalKeyDesc1,
73+
vPkt, outputAmounts[2], scriptKey2, 0, anchorInternalKeyDesc1,
7474
asset.V0,
7575
)
7676
tappsbt.AddOutput(
77-
vPkt, outputAmounts[2], scriptKey3, 1, anchorInternalKeyDesc2,
77+
vPkt, outputAmounts[3], scriptKey3, 1, anchorInternalKeyDesc2,
7878
asset.V0,
7979
)
8080
tappsbt.AddOutput(
81-
vPkt, outputAmounts[3], scriptKey4, 2, anchorInternalKeyDesc3,
81+
vPkt, outputAmounts[4], scriptKey4, 2, anchorInternalKeyDesc3,
8282
asset.V0,
8383
)
8484

@@ -120,7 +120,7 @@ func testBurnAssets(t *harnessTest) {
120120
Asset: &taprpc.BurnAssetRequest_AssetId{
121121
AssetId: simpleAssetID[:],
122122
},
123-
AmountToBurn: outputAmounts[2],
123+
AmountToBurn: outputAmounts[3],
124124
ConfirmationText: taprootassets.AssetBurnConfirmationText,
125125
})
126126
require.ErrorContains(
@@ -152,7 +152,7 @@ func testBurnAssets(t *harnessTest) {
152152
AssertAssetOutboundTransferWithOutputs(
153153
t.t, minerClient, t.tapd, burnResp.BurnTransfer,
154154
simpleAssetGen.AssetId,
155-
[]uint64{burnAmt, outputAmounts[2] - burnAmt}, 1, 2, 2, true,
155+
[]uint64{outputAmounts[3] - burnAmt, burnAmt}, 1, 2, 2, true,
156156
)
157157

158158
// We'll now assert that the burned asset has the correct state.
@@ -175,11 +175,8 @@ func testBurnAssets(t *harnessTest) {
175175
t.t, t.tapd, simpleAssetGen.AssetId, simpleAsset.Amount-burnAmt,
176176
)
177177

178-
burns, err := t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{})
179-
require.NoError(t.t, err)
180-
181-
require.Len(t.t, burns.Burns, 1)
182-
burn := burns.Burns[0]
178+
burns := AssertNumBurns(t.t, t.tapd, 1, nil)
179+
burn := burns[0]
183180
require.Equal(t.t, uint64(burnAmt), burn.Amount)
184181
require.Equal(t.t, burnResp.BurnTransfer.AnchorTxHash, burn.AnchorTxid)
185182
require.Equal(t.t, burn.AssetId, simpleAssetID[:])
@@ -188,7 +185,7 @@ func testBurnAssets(t *harnessTest) {
188185
// The burned asset should be pruned from the tree when we next spend
189186
// the anchor output it was in (together with the change). So let's test
190187
// that we can successfully spend the change output.
191-
secondSendAmt := outputAmounts[2] - burnAmt
188+
secondSendAmt := outputAmounts[3] - burnAmt
192189
fullSendAddr, stream := NewAddrWithEventStream(
193190
t.t, t.tapd, &taprpc.NewAddrRequest{
194191
AssetId: simpleAssetGen.AssetId,
@@ -232,7 +229,7 @@ func testBurnAssets(t *harnessTest) {
232229
// two largest inputs we have, the one over 1500 we sent above and the
233230
// 1200 from the initial fan out transfer.
234231
const changeAmt = 300
235-
multiBurnAmt := outputAmounts[1] + secondSendAmt - changeAmt
232+
multiBurnAmt := outputAmounts[2] + secondSendAmt - changeAmt
236233
burnResp, err = t.tapd.BurnAsset(ctxt, &taprpc.BurnAssetRequest{
237234
Asset: &taprpc.BurnAssetRequest_AssetId{
238235
AssetId: simpleAssetGen.AssetId,
@@ -250,7 +247,7 @@ func testBurnAssets(t *harnessTest) {
250247
AssertAssetOutboundTransferWithOutputs(
251248
t.t, minerClient, t.tapd, burnResp.BurnTransfer,
252249
simpleAssetGen.AssetId,
253-
[]uint64{multiBurnAmt, changeAmt}, 4, 5, 2, true,
250+
[]uint64{changeAmt, multiBurnAmt}, 4, 5, 2, true,
254251
)
255252

256253
// Our final asset balance should be reduced by both successful burn
@@ -290,18 +287,15 @@ func testBurnAssets(t *harnessTest) {
290287
AssertAssetOutboundTransferWithOutputs(
291288
t.t, minerClient, t.tapd, burnResp.BurnTransfer,
292289
simpleGroupGen.AssetId,
293-
[]uint64{burnAmt, simpleGroup.Amount - burnAmt}, 5, 6, 2, true,
290+
[]uint64{simpleGroup.Amount - burnAmt, burnAmt}, 5, 6, 2, true,
294291
)
295292
AssertBalanceByID(
296293
t.t, t.tapd, simpleGroupGen.AssetId, simpleGroup.Amount-burnAmt,
297294
)
298295

299-
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{})
300-
require.NoError(t.t, err)
301-
302-
require.Len(t.t, burns.Burns, 4)
296+
burns = AssertNumBurns(t.t, t.tapd, 4, nil)
303297
var groupBurn *taprpc.AssetBurn
304-
for _, b := range burns.Burns {
298+
for _, b := range burns {
305299
if bytes.Equal(b.AssetId, simpleGroupGen.AssetId) {
306300
groupBurn = b
307301
}
@@ -356,30 +350,21 @@ func testBurnAssets(t *harnessTest) {
356350

357351
// Fetch the burns related to the simple asset id, which should have a
358352
// total of 2 burns (tc1 & tc4).
359-
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{
353+
AssertNumBurns(t.t, t.tapd, 2, &taprpc.ListBurnsRequest{
360354
AssetId: simpleAssetGen.AssetId,
361355
})
362-
require.NoError(t.t, err)
363-
364-
require.Len(t.t, burns.Burns, 2)
365356

366357
// Fetch the burns related to the group key of the grouped asset in tc5.
367358
// There should be 1 burn.
368-
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{
359+
AssertNumBurns(t.t, t.tapd, 1, &taprpc.ListBurnsRequest{
369360
TweakedGroupKey: simpleGroup.AssetGroup.TweakedGroupKey,
370361
})
371-
require.NoError(t.t, err)
372-
373-
require.Len(t.t, burns.Burns, 1)
374362

375363
// Fetch the burns associated with the txhash of the burn in tc5. There
376364
// should be 1 burn returned.
377-
burns, err = t.tapd.ListBurns(ctxt, &taprpc.ListBurnsRequest{
365+
AssertNumBurns(t.t, t.tapd, 1, &taprpc.ListBurnsRequest{
378366
AnchorTxid: groupBurnTxHash,
379367
})
380-
require.NoError(t.t, err)
381-
382-
require.Len(t.t, burns.Burns, 1)
383368
}
384369

385370
// testBurnGroupedAssets tests that some amount of an asset from an asset group
@@ -464,7 +449,7 @@ func testBurnGroupedAssets(t *harnessTest) {
464449
// Assert that the asset burn transfer occurred correctly.
465450
AssertAssetOutboundTransferWithOutputs(
466451
t.t, miner, t.tapd, burnResp.BurnTransfer,
467-
burnAssetID, []uint64{burnAmt, postBurnAmt}, 0, 1, 2, true,
452+
burnAssetID, []uint64{postBurnAmt, burnAmt}, 0, 1, 2, true,
468453
)
469454

470455
// Ensure that the burnt asset has the correct state.

itest/psbt_test.go

+25-14
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ func runPsbtInteractiveSplitSendTest(ctxt context.Context, t *harnessTest,
871871
ConfirmAndAssertOutboundTransferWithOutputs(
872872
t.t, t.lndHarness.Miner().Client, sender,
873873
sendResp, genInfo.AssetId,
874-
[]uint64{sendAmt, changeAmt}, i/2, (i/2)+1,
874+
[]uint64{changeAmt, sendAmt}, i/2, (i/2)+1,
875875
numOutputs,
876876
)
877877

@@ -1015,6 +1015,17 @@ func testPsbtInteractiveAltLeafAnchoring(t *harnessTest) {
10151015
vPkt.Outputs[1].AltLeaves = nil
10161016

10171017
fundResp := fundPacket(t, sender, vPkt)
1018+
1019+
// The funding added a change output at the first index. So all the
1020+
// indexes will be shifted below. The output with index 1 becomes index
1021+
// 2 (where we cleared the alt leaves).
1022+
fundedvPkt, err := tappsbt.Decode(fundResp.FundedPsbt)
1023+
require.NoError(t.t, err)
1024+
require.Len(t.t, fundedvPkt.Outputs, 3)
1025+
require.Nil(t.t, fundedvPkt.Outputs[0].AltLeaves)
1026+
require.NotNil(t.t, fundedvPkt.Outputs[1].AltLeaves)
1027+
require.Nil(t.t, fundedvPkt.Outputs[2].AltLeaves)
1028+
10181029
signActiveResp, err := sender.SignVirtualPsbt(
10191030
ctxt, &wrpc.SignVirtualPsbtRequest{
10201031
FundedPsbt: fundResp.FundedPsbt,
@@ -1037,7 +1048,7 @@ func testPsbtInteractiveAltLeafAnchoring(t *harnessTest) {
10371048
require.NoError(t.t, err)
10381049

10391050
signedvPktCopy := signedvPkt.Copy()
1040-
require.NoError(t.t, signedvPkt.Outputs[1].SetAltLeaves(altLeaves3))
1051+
require.NoError(t.t, signedvPkt.Outputs[2].SetAltLeaves(altLeaves3))
10411052
signedvPktBytes, err := tappsbt.Encode(signedvPkt)
10421053
require.NoError(t.t, err)
10431054

@@ -1075,7 +1086,7 @@ func testPsbtInteractiveAltLeafAnchoring(t *harnessTest) {
10751086

10761087
// Now, let's set non-conflicting altLeaves for the second vOutput, and
10771088
// complete the transfer via the PSBT flow. This should succeed.
1078-
require.NoError(t.t, signedvPktCopy.Outputs[1].SetAltLeaves(altLeaves2))
1089+
require.NoError(t.t, signedvPktCopy.Outputs[2].SetAltLeaves(altLeaves2))
10791090
signedvPktBytes, err = tappsbt.Encode(signedvPktCopy)
10801091

10811092
require.NoError(t.t, err)
@@ -1105,7 +1116,7 @@ func testPsbtInteractiveAltLeafAnchoring(t *harnessTest) {
11051116
)
11061117

11071118
expectedAmounts := []uint64{
1108-
partialAmt, partialAmt * 2, partialAmt,
1119+
partialAmt, partialAmt, partialAmt * 2,
11091120
}
11101121
ConfirmAndAssertOutboundTransferWithOutputs(
11111122
t.t, t.lndHarness.Miner().Client, sender, publishResp,
@@ -1136,8 +1147,8 @@ func testPsbtInteractiveAltLeafAnchoring(t *harnessTest) {
11361147
string(receiverScriptKey2Bytes): allAltLeaves,
11371148
}
11381149

1139-
for _, asset := range receiverAssets.Assets {
1140-
AssertProofAltLeaves(t.t, receiver, asset, leafMap)
1150+
for _, receiverAsset := range receiverAssets.Assets {
1151+
AssertProofAltLeaves(t.t, receiver, receiverAsset, leafMap)
11411152
}
11421153
}
11431154

@@ -1215,7 +1226,7 @@ func testPsbtInteractiveTapscriptSibling(t *harnessTest) {
12151226

12161227
ConfirmAndAssertOutboundTransferWithOutputs(
12171228
t.t, t.lndHarness.Miner().Client, alice, sendResp,
1218-
genInfo.AssetId, []uint64{sendAmt, changeAmt}, 0, 1, 2,
1229+
genInfo.AssetId, []uint64{changeAmt, sendAmt}, 0, 1, 2,
12191230
)
12201231

12211232
// This is an interactive transfer, so we do need to manually send the
@@ -1314,9 +1325,9 @@ func testPsbtMultiSend(t *harnessTest) {
13141325
senderScriptKey2, _ := DeriveKeys(t.t, sender)
13151326

13161327
// We create the output at anchor index 0 for the first address.
1317-
outputAmounts := []uint64{1200, 1300, 1400, 800, 300}
1328+
outputAmounts := []uint64{300, 1200, 1300, 1400, 800}
13181329
vPkt := tappsbt.ForInteractiveSend(
1319-
id, outputAmounts[0], receiverScriptKey1, 0, 0, 0,
1330+
id, outputAmounts[1], receiverScriptKey1, 0, 0, 0,
13201331
receiverAnchorIntKeyDesc1, asset.V0, chainParams,
13211332
)
13221333

@@ -1325,15 +1336,15 @@ func testPsbtMultiSend(t *harnessTest) {
13251336
// still leave 300 units as change which we expect to end up at anchor
13261337
// index 3.
13271338
tappsbt.AddOutput(
1328-
vPkt, outputAmounts[1], receiverScriptKey2, 1,
1339+
vPkt, outputAmounts[2], receiverScriptKey2, 1,
13291340
receiverAnchorIntKeyDesc2, asset.V0,
13301341
)
13311342
tappsbt.AddOutput(
1332-
vPkt, outputAmounts[2], senderScriptKey1, 2,
1343+
vPkt, outputAmounts[3], senderScriptKey1, 2,
13331344
senderAnchorIntKeyDesc1, asset.V0,
13341345
)
13351346
tappsbt.AddOutput(
1336-
vPkt, outputAmounts[3], senderScriptKey2, 2,
1347+
vPkt, outputAmounts[4], senderScriptKey2, 2,
13371348
senderAnchorIntKeyDesc1, asset.V0,
13381349
)
13391350

@@ -1426,7 +1437,7 @@ func testPsbtMultiSend(t *harnessTest) {
14261437
// that shared the anchor output and the other one is treated as a
14271438
// passive asset.
14281439
sendAssetAndAssert(
1429-
ctxt, t, t.tapd, secondTapd, outputAmounts[2], 0,
1440+
ctxt, t, t.tapd, secondTapd, outputAmounts[3], 0,
14301441
genInfo, rpcAssets[0], 2, 3, 2,
14311442
)
14321443
}
@@ -1632,7 +1643,7 @@ func testMultiInputPsbtSingleAssetID(t *harnessTest) {
16321643
ConfirmAndAssertOutboundTransferWithOutputs(
16331644
t.t, t.lndHarness.Miner().Client, secondaryTapd,
16341645
sendResp, genInfo.AssetId,
1635-
[]uint64{sendAmt, changeAmt}, currentTransferIdx, numTransfers,
1646+
[]uint64{changeAmt, sendAmt}, currentTransferIdx, numTransfers,
16361647
numOutputs,
16371648
)
16381649

0 commit comments

Comments
 (0)