Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for mint anchor transaction pre-commitment output #1418

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

ffranr
Copy link
Contributor

@ffranr ffranr commented Mar 3, 2025

Add unit tests to provide coverage for the changes made in #1325

Depends on #1325 which should be merged first.

Introduce MintingBatch.AddSeedling, a method for attempting
to add seedlings to a batch.

Future commits will extend this method with validation logic
to ensure compatibility of the seedling with others already
in the batch.
Add the UniverseCommitments field to the MintingBatch structure,
populating it when a seedling is added to the batch. Include
validation logic to ensure that for a batch with uni commitment
enabled, all seedlings share the same asset group key.
Set the seedling's delegation key as part of the preparation process
before batch inclusion.
Modify `prepAssetSeedling` to set the seedling metadata fields
`UniverseCommitments` and `DelegationKey`. This is handled here
instead of in rpcserver.
Ensure that all candidate seedlings in a batch comply with universe
commitment feature restrictions. If the feature is enabled, all
seedlings must have a delegation key, and the key must be identical
across the batch.
Modified seedling validation to permit enabling the universe
commitments feature for new minting tranches.
Clarified that the group internal key is not used as the
delegation key by default.
Improve code health/readability.
Seedling metadata validation is now handled in
ChainPlanter.prepAssetSeedling, so it is no longer needed in
rpcserver.
This allows deriving a pre-commitment output script key when the
universe commitment feature is enabled.
Add a check to verify that the change output index is defined after
anchor funding. Since the funding request guarantees a change output,
the index should be known.

Modify the `MockWalletAnchor.FundPsbt` method to compute a reasonable
change output index.
Modify anchor transaction construction to include a pre-commitment
output when the universe commitments feature is enabled.

Add a new type to encapsulate the pre-commitment output metadata
along with the funded mint anchor transaction. This allows us to
store and retrieve pre-commitment-related information from the
database when storing or retrieving the batch mint transaction.
Update the SQL query in BindMintingBatchWithTx to return the batch ID.
This ID will be used for populating the universe commitment anchor rows
in the database.
Add a new `assets_output_index` column to the
`asset_minting_batches` table to store the output index of the
asset anchor transaction. Populate this column for existing
entries based on the `change_output_index`.

Introduce a `universe_commitments` flag column to indicate
whether universe commitments are enabled for a minting batch,
defaulting to `FALSE`.

Create the `mint_anchor_uni_commitments` table to associate a
mint batch anchor transaction with its universe commitments,
storing the pre-commitment output index, Taproot internal key,
and asset group pub key.
Update the MintingBatch.GenesisPacket field to use the
FundedMintAnchorPsbt type to include pre-commitment output information.
Refactor BindMintingBatchWithTx into insertMintAnchorTx, which
will also handle inserting pre-commitment information into the
database.

insertMintAnchorTx will also ensure that the genesis point is in the
database.
Add unit tests for the SQL queries `UpsertMintAnchorUniCommitment` and
`FetchMintAnchorUniCommitment`.
Separate the mint anchor transaction fee rate calculation from
fundGenesisPsbt into anchorTxFeeRate.

This refactor is part of a broader effort to simplify calling
fundGenesisPsbt from unit tests.
Extract the wallet funding call into a closure that is passed as an
argument. This prepares fundGenesisPsbt to become a standalone
function, making it easier to call in unit tests.
Pass the pending batch into fundGenesisPsbt and convert it into a
standalone function rather than a method on ChainPlanter. This change
makes it easier to call fundGenesisPsbt from unit tests.
The batch key was only used for logging. This commit moves the log
messages outside fundGenesisPsbt, simplifying the function for
better code health.
Use the standalone function fundGenesisPsbt when generating a mock
batch genesis (mint anchor tx) funded PSBT. This change will allow us
to seamlessly include pre-commitment outputs in the mock process later.
@ffranr ffranr self-assigned this Mar 3, 2025
@ffranr ffranr changed the base branch from main to unit-commitment-mint-output March 3, 2025 14:45
@coveralls
Copy link

Pull Request Test Coverage Report for Build 13633528219

Details

  • 62 of 93 (66.67%) changed or added relevant lines in 2 files are covered.
  • 24015 unchanged lines in 164 files lost coverage.
  • Overall coverage decreased (-26.6%) to 27.892%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tapgarden/planter.go 62 74 83.78%
tapgarden/mock.go 0 19 0.0%
Files with Coverage Reduction New Missed Lines %
asset/witness.go 2 91.38%
mssmt/compacted_tree.go 2 83.27%
proof/util.go 2 81.63%
tapdb/mssmt.go 2 88.64%
address/log.go 3 0.0%
commitment/log.go 3 0.0%
internal/pedersen/commitment.go 3 95.31%
rfq/log.go 3 0.0%
tapchannel/aux_leaf_signer.go 3 43.08%
tapchannel/log.go 3 0.0%
Totals Coverage Status
Change from base Build 13591368204: -26.6%
Covered Lines: 25169
Relevant Lines: 90237

💛 - Coveralls

Refactor RandSeedlingMintingBatch for generalization:
- Rename to RandMintingBatch.
- Change argument to `options...` pattern for extendability.

The next commit will introduce additional options, enabling the
creation of more specific mint batches.
@ffranr ffranr force-pushed the unit-tests-mint-pre-commit branch from d41d194 to 83ba31c Compare March 5, 2025 11:42
@ffranr ffranr force-pushed the unit-commitment-mint-output branch 2 times, most recently from a2263f6 to cef2567 Compare March 6, 2025 00:59
@ffranr
Copy link
Contributor Author

ffranr commented Mar 6, 2025

Needs rebase.

@guggero guggero changed the base branch from unit-commitment-mint-output to main March 8, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

2 participants