Skip to content

Commit 2b04c29

Browse files
committed
tapgarden: add batch funding support to RandMintingBatch
The funding routine now uses the refactored fundGenesisPsbt function, introduced in a previous commit. Which adds test coverage for the batch funding logic. An optional argument is also added to allow skipping funding.
1 parent 3164451 commit 2b04c29

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

tapgarden/batch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ func TestValidateUniCommitment(t *testing.T) {
110110
// Ensures that a group anchor candidate seedling
111111
// with universe commitments can be added to an empty
112112
// batch.
113-
name: "empty batch; candidate seedling is group " +
114-
"anchor; is valid",
113+
name: "empty unfunded batch; candidate seedling is " +
114+
"group anchor; is valid",
115115

116116
candidateSeedling: RandGroupAnchorSeedling(
117117
t, "some-anchor-name", true,
118118
),
119-
batch: RandMintingBatch(t),
119+
batch: RandMintingBatch(t, WithSkipFunding()),
120120
expectErr: false,
121121
},
122122
}

tapgarden/mock.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/btcsuite/btcd/wire"
2323
"github.com/btcsuite/btcwallet/waddrmgr"
2424
"github.com/lightninglabs/lndclient"
25+
"github.com/lightninglabs/taproot-assets/address"
2526
"github.com/lightninglabs/taproot-assets/asset"
2627
"github.com/lightninglabs/taproot-assets/fn"
2728
"github.com/lightninglabs/taproot-assets/internal/test"
@@ -163,6 +164,9 @@ type MintBatchOptions struct {
163164
// universeCommitments specifies whether to generate universe
164165
// commitments for the asset groups in this minting batch.
165166
universeCommitments bool
167+
168+
// skipFunding specifies whether to skip funding the genesis PSBT.
169+
skipFunding bool
166170
}
167171

168172
// MintBatchOption is a functional option for creating a new minting batch.
@@ -198,6 +202,13 @@ func WithUniverseCommitments(enabled bool) MintBatchOption {
198202
}
199203
}
200204

205+
// WithSkipFunding specifies whether to skip funding the genesis PSBT.
206+
func WithSkipFunding() MintBatchOption {
207+
return func(options *MintBatchOptions) {
208+
options.skipFunding = true
209+
}
210+
}
211+
201212
// RandMintingBatch creates a new minting batch with only random seedlings
202213
// populated for testing.
203214
func RandMintingBatch(t testing.TB, opts ...MintBatchOption) *MintingBatch {
@@ -259,6 +270,32 @@ func RandMintingBatch(t testing.TB, opts ...MintBatchOption) *MintingBatch {
259270
// requested amount. This check might help debug flakes in tests.
260271
require.Equal(t, options.totalSeedlings, len(batch.Seedlings))
261272

273+
// Return early if funding is to be skipped.
274+
if options.skipFunding {
275+
return batch
276+
}
277+
278+
walletFundPsbt := func(ctx context.Context,
279+
anchorPkt psbt.Packet) (tapsend.FundedPsbt, error) {
280+
281+
changeOutputIdx := FundGenesisTx(
282+
&anchorPkt, chainfee.FeePerKwFloor,
283+
)
284+
285+
return tapsend.FundedPsbt{
286+
Pkt: &anchorPkt,
287+
ChangeOutputIndex: int32(changeOutputIdx),
288+
}, nil
289+
}
290+
291+
// Fund genesis packet.
292+
ctx := context.Background()
293+
fundedPsbt, err := fundGenesisPsbt(
294+
ctx, address.TestNet3Tap, batch, walletFundPsbt,
295+
)
296+
require.NoError(t, err)
297+
batch.GenesisPacket = &fundedPsbt
298+
262299
return batch
263300
}
264301

0 commit comments

Comments
 (0)