@@ -1835,10 +1835,12 @@ func TestTapscriptTreeManager(t *testing.T) {
18351835 loadTapscriptTreeChecked (t , ctx , assetStore , tree5 , tree5Hash )
18361836}
18371837
1838- // storeMintAnchorUniCommitment stores a mint anchor commitment in the DB.
1839- func storeMintAnchorUniCommitment (t * testing.T , assetStore AssetMintingStore ,
1838+ // storeMintSupplyPreCommit stores a mint anchor supply pre-commitment in the
1839+ // DB.
1840+ func storeMintSupplyPreCommit (t * testing.T , assetStore AssetMintingStore ,
18401841 batchKey []byte , txOutputIndex int32 ,
1841- taprootInternalKey keychain.KeyDescriptor , groupKey []byte ) {
1842+ taprootInternalKey keychain.KeyDescriptor , groupKey []byte ,
1843+ outpoint wire.OutPoint ) {
18421844
18431845 ctx := context .Background ()
18441846
@@ -1854,12 +1856,16 @@ func storeMintAnchorUniCommitment(t *testing.T, assetStore AssetMintingStore,
18541856 })
18551857 require .NoError (t , err )
18561858
1857- _ , err = q .UpsertMintAnchorUniCommitment (
1858- ctx , sqlc.UpsertMintAnchorUniCommitmentParams {
1859+ opBytes , err := encodeOutpoint (outpoint )
1860+ require .NoError (t , err )
1861+
1862+ _ , err = q .UpsertMintSupplyPreCommit (
1863+ ctx , UpsertBatchPreCommitParams {
18591864 BatchKey : batchKey ,
18601865 TxOutputIndex : txOutputIndex ,
18611866 TaprootInternalKeyID : internalKeyID ,
18621867 GroupKey : groupKey ,
1868+ Outpoint : opBytes ,
18631869 },
18641870 )
18651871 require .NoError (t , err )
@@ -1869,19 +1875,21 @@ func storeMintAnchorUniCommitment(t *testing.T, assetStore AssetMintingStore,
18691875 _ = assetStore .db .ExecTx (ctx , & writeTxOpts , upsertMintAnchorPreCommit )
18701876}
18711877
1872- // assertMintAnchorUniCommitment is a helper function that reads a mint anchor
1873- // commitment from the DB and asserts that it matches the expected values.
1874- func assertMintAnchorUniCommitment (t * testing.T , assetStore AssetMintingStore ,
1878+ // assertMintSupplyPreCommit is a helper function that reads a mint anchor
1879+ // supply pre-commitment from the DB and asserts that it matches the expected
1880+ // values.
1881+ func assertMintSupplyPreCommit (t * testing.T , assetStore AssetMintingStore ,
18751882 batchKey []byte , txOutputIndex int32 ,
1876- preCommitInternalKey keychain.KeyDescriptor , groupPubKeyBytes []byte ) {
1883+ preCommitInternalKey keychain.KeyDescriptor , groupPubKeyBytes []byte ,
1884+ outpoint wire.OutPoint ) {
18771885
18781886 ctx := context .Background ()
18791887 readOpts := NewAssetStoreReadTx ()
18801888
1881- var preCommit * sqlc.FetchMintAnchorUniCommitmentRow
1889+ var preCommit * sqlc.FetchMintSupplyPreCommitsRow
18821890 readMintAnchorCommitment := func (q PendingAssetStore ) error {
1883- fetchRes , err := q .FetchMintAnchorUniCommitment (
1884- ctx , FetchPreCommitParams {
1891+ fetchRes , err := q .FetchMintSupplyPreCommits (
1892+ ctx , FetchMintPreCommitsParams {
18851893 BatchKey : batchKey ,
18861894 },
18871895 )
@@ -1912,12 +1920,16 @@ func assertMintAnchorUniCommitment(t *testing.T, assetStore AssetMintingStore,
19121920 preCommit .InternalKey .KeyFamily ,
19131921 )
19141922 require .Equal (t , groupPubKeyBytes , preCommit .GroupKey )
1923+
1924+ opBytes , err := encodeOutpoint (outpoint )
1925+ require .NoError (t , err )
1926+ require .Equal (t , opBytes , preCommit .Outpoint )
19151927}
19161928
1917- // TestUpsertMintAnchorUniCommitment tests the UpsertMintAnchorUniCommitment
1918- // FetchMintAnchorUniCommitment and SQL queries. In particular, it tests that
1919- // upsert works correctly.
1920- func TestUpsertMintAnchorUniCommitment (t * testing.T ) {
1929+ // TestUpsertMintSupplyPreCommit tests the UpsertMintSupplyPreCommit and
1930+ // FetchSupplyPreCommits SQL queries. In particular, it tests that upsert works
1931+ // correctly.
1932+ func TestUpsertMintSupplyPreCommit (t * testing.T ) {
19211933 t .Parallel ()
19221934
19231935 ctx := context .Background ()
@@ -1948,51 +1960,62 @@ func TestUpsertMintAnchorUniCommitment(t *testing.T) {
19481960 },
19491961 )
19501962
1963+ // Define pre-commit outpoint for the batch mint anchor tx.
1964+ txOutputIndex := int32 (2 )
1965+ txidStr := mintingBatch .GenesisPacket .FundedPsbt .Pkt .UnsignedTx .TxID ()
1966+
1967+ txid , err := chainhash .NewHashFromStr (txidStr )
1968+ require .NoError (t , err )
1969+
1970+ preCommitOutpoint := wire.OutPoint {
1971+ Hash : * txid ,
1972+ Index : uint32 (txOutputIndex ),
1973+ }
1974+
19511975 // Serialize keys into bytes for easier handling.
19521976 preCommitInternalKey , _ := test .RandKeyDesc (t )
19531977
19541978 groupPubKeyBytes := group .GroupPubKey .SerializeCompressed ()
19551979
19561980 // Upsert a mint anchor commitment for the batch.
1957- txOutputIndex := int32 (2 )
1958- storeMintAnchorUniCommitment (
1981+ storeMintSupplyPreCommit (
19591982 t , * assetStore , batchKey , txOutputIndex ,
1960- preCommitInternalKey , groupPubKeyBytes ,
1983+ preCommitInternalKey , groupPubKeyBytes , preCommitOutpoint ,
19611984 )
19621985
19631986 // Retrieve and inspect the mint anchor commitment we just inserted.
1964- assertMintAnchorUniCommitment (
1987+ assertMintSupplyPreCommit (
19651988 t , * assetStore , batchKey , txOutputIndex ,
1966- preCommitInternalKey , groupPubKeyBytes ,
1989+ preCommitInternalKey , groupPubKeyBytes , preCommitOutpoint ,
19671990 )
19681991
1969- // Upsert-ing a new taproot internal key for the same batch should
1970- // overwrite the existing one.
1992+ // Upsert-ing a new taproot internal key for the same pre-commit
1993+ // outpoint should overwrite the existing one.
19711994 internalKey2 , _ := test .RandKeyDesc (t )
19721995
1973- storeMintAnchorUniCommitment (
1996+ storeMintSupplyPreCommit (
19741997 t , * assetStore , batchKey , txOutputIndex , internalKey2 ,
1975- groupPubKeyBytes ,
1998+ groupPubKeyBytes , preCommitOutpoint ,
19761999 )
19772000
1978- assertMintAnchorUniCommitment (
2001+ assertMintSupplyPreCommit (
19792002 t , * assetStore , batchKey , txOutputIndex , internalKey2 ,
1980- groupPubKeyBytes ,
2003+ groupPubKeyBytes , preCommitOutpoint ,
19812004 )
19822005
1983- // Upsert-ing a new group key for the same batch should overwrite the
1984- // existing one.
2006+ // Upsert-ing a new group key for the same pre-commit outpoint should
2007+ // overwrite the existing one.
19852008 groupPubKey2 := test .RandPubKey (t )
19862009 groupPubKey2Bytes := groupPubKey2 .SerializeCompressed ()
19872010
1988- storeMintAnchorUniCommitment (
2011+ storeMintSupplyPreCommit (
19892012 t , * assetStore , batchKey , txOutputIndex , internalKey2 ,
1990- groupPubKey2Bytes ,
2013+ groupPubKey2Bytes , preCommitOutpoint ,
19912014 )
19922015
1993- assertMintAnchorUniCommitment (
2016+ assertMintSupplyPreCommit (
19942017 t , * assetStore , batchKey , txOutputIndex , internalKey2 ,
1995- groupPubKey2Bytes ,
2018+ groupPubKey2Bytes , preCommitOutpoint ,
19962019 )
19972020}
19982021
0 commit comments