Skip to content

Commit

Permalink
itest: allow minting an unconfirmed batch
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Aug 10, 2023
1 parent ebf0299 commit 14ed4a1
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@ func withMintingTimeout(timeout time.Duration) mintOption {
}
}

// mintAssetsConfirmBatch mints all given assets in the same batch, confirms the
// batch and verifies all asset proofs of the minted assets.
func mintAssetsConfirmBatch(t *harnessTest, tapd *tapdHarness,
// mintAssetUnconfirmed is a helper function that mints a batch of assets and
// waits until the minting transaction is in the mempool but does not mine a
// block.
func mintAssetUnconfirmed(t *harnessTest, tapd *tapdHarness,
assetRequests []*mintrpc.MintAssetRequest,
opts ...mintOption) []*taprpc.Asset {
opts ...mintOption) chainhash.Hash {

options := defaultMintOptions()
for _, opt := range opts {
Expand Down Expand Up @@ -210,6 +211,26 @@ func mintAssetsConfirmBatch(t *harnessTest, tapd *tapdHarness,
)
}

return *hashes[0]
}

// mintAssetsConfirmBatch mints all given assets in the same batch, confirms the
// batch and verifies all asset proofs of the minted assets.
func mintAssetsConfirmBatch(t *harnessTest, tapd *tapdHarness,
assetRequests []*mintrpc.MintAssetRequest,
opts ...mintOption) []*taprpc.Asset {

mintTXID := mintAssetUnconfirmed(t, tapd, assetRequests, opts...)

options := defaultMintOptions()
for _, opt := range opts {
opt(options)
}

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, options.mintingTimeout)
defer cancel()

// Mine a block to confirm the assets.
block := mineBlocks(t, t.lndHarness, 1, 1)[0]
blockHash := block.BlockHash()
Expand All @@ -218,6 +239,20 @@ func mintAssetsConfirmBatch(t *harnessTest, tapd *tapdHarness,
mintrpc.BatchState_BATCH_STATE_FINALIZED,
)

return assertAssetsMinted(t, tapd, assetRequests, mintTXID, blockHash)
}

// assertAssetsMinted makes sure all assets in the minting request were in fact
// minted in the given anchor TX and block. The function returns the list of
// minted assets.
func assertAssetsMinted(t *harnessTest, tapd *tapdHarness,
assetRequests []*mintrpc.MintAssetRequest, mintTXID,
blockHash chainhash.Hash) []*taprpc.Asset {

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
defer cancel()

// The rest of the anchor information should now be populated as well.
// We also check that the anchor outpoint of all assets is the same,
// since they were all minted in the same batch.
Expand All @@ -238,7 +273,7 @@ func mintAssetsConfirmBatch(t *harnessTest, tapd *tapdHarness,
}).MetaHash()
mintedAsset := assertAssetState(
t, confirmedAssets, assetRequest.Asset.Name,
metaHash[:], assetAnchorCheck(*hashes[0], blockHash),
metaHash[:], assetAnchorCheck(mintTXID, blockHash),
assetScriptKeyIsLocalCheck(true),
func(a *taprpc.Asset) error {
anchor := a.ChainAnchor
Expand Down

0 comments on commit 14ed4a1

Please sign in to comment.