@@ -1835,10 +1835,12 @@ func TestTapscriptTreeManager(t *testing.T) {
1835
1835
loadTapscriptTreeChecked (t , ctx , assetStore , tree5 , tree5Hash )
1836
1836
}
1837
1837
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 ,
1840
1841
batchKey []byte , txOutputIndex int32 ,
1841
- taprootInternalKey keychain.KeyDescriptor , groupKey []byte ) {
1842
+ taprootInternalKey keychain.KeyDescriptor , groupKey []byte ,
1843
+ outpoint wire.OutPoint ) {
1842
1844
1843
1845
ctx := context .Background ()
1844
1846
@@ -1854,12 +1856,16 @@ func storeMintAnchorUniCommitment(t *testing.T, assetStore AssetMintingStore,
1854
1856
})
1855
1857
require .NoError (t , err )
1856
1858
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 {
1859
1864
BatchKey : batchKey ,
1860
1865
TxOutputIndex : txOutputIndex ,
1861
1866
TaprootInternalKeyID : internalKeyID ,
1862
1867
GroupKey : groupKey ,
1868
+ Outpoint : opBytes ,
1863
1869
},
1864
1870
)
1865
1871
require .NoError (t , err )
@@ -1869,19 +1875,21 @@ func storeMintAnchorUniCommitment(t *testing.T, assetStore AssetMintingStore,
1869
1875
_ = assetStore .db .ExecTx (ctx , & writeTxOpts , upsertMintAnchorPreCommit )
1870
1876
}
1871
1877
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 ,
1875
1882
batchKey []byte , txOutputIndex int32 ,
1876
- preCommitInternalKey keychain.KeyDescriptor , groupPubKeyBytes []byte ) {
1883
+ preCommitInternalKey keychain.KeyDescriptor , groupPubKeyBytes []byte ,
1884
+ outpoint wire.OutPoint ) {
1877
1885
1878
1886
ctx := context .Background ()
1879
1887
readOpts := NewAssetStoreReadTx ()
1880
1888
1881
- var preCommit * sqlc.FetchMintAnchorUniCommitmentRow
1889
+ var preCommit * sqlc.FetchMintSupplyPreCommitsRow
1882
1890
readMintAnchorCommitment := func (q PendingAssetStore ) error {
1883
- fetchRes , err := q .FetchMintAnchorUniCommitment (
1884
- ctx , FetchPreCommitParams {
1891
+ fetchRes , err := q .FetchMintSupplyPreCommits (
1892
+ ctx , FetchMintPreCommitsParams {
1885
1893
BatchKey : batchKey ,
1886
1894
},
1887
1895
)
@@ -1912,12 +1920,16 @@ func assertMintAnchorUniCommitment(t *testing.T, assetStore AssetMintingStore,
1912
1920
preCommit .InternalKey .KeyFamily ,
1913
1921
)
1914
1922
require .Equal (t , groupPubKeyBytes , preCommit .GroupKey )
1923
+
1924
+ opBytes , err := encodeOutpoint (outpoint )
1925
+ require .NoError (t , err )
1926
+ require .Equal (t , opBytes , preCommit .Outpoint )
1915
1927
}
1916
1928
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 ) {
1921
1933
t .Parallel ()
1922
1934
1923
1935
ctx := context .Background ()
@@ -1948,51 +1960,62 @@ func TestUpsertMintAnchorUniCommitment(t *testing.T) {
1948
1960
},
1949
1961
)
1950
1962
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
+
1951
1975
// Serialize keys into bytes for easier handling.
1952
1976
preCommitInternalKey , _ := test .RandKeyDesc (t )
1953
1977
1954
1978
groupPubKeyBytes := group .GroupPubKey .SerializeCompressed ()
1955
1979
1956
1980
// Upsert a mint anchor commitment for the batch.
1957
- txOutputIndex := int32 (2 )
1958
- storeMintAnchorUniCommitment (
1981
+ storeMintSupplyPreCommit (
1959
1982
t , * assetStore , batchKey , txOutputIndex ,
1960
- preCommitInternalKey , groupPubKeyBytes ,
1983
+ preCommitInternalKey , groupPubKeyBytes , preCommitOutpoint ,
1961
1984
)
1962
1985
1963
1986
// Retrieve and inspect the mint anchor commitment we just inserted.
1964
- assertMintAnchorUniCommitment (
1987
+ assertMintSupplyPreCommit (
1965
1988
t , * assetStore , batchKey , txOutputIndex ,
1966
- preCommitInternalKey , groupPubKeyBytes ,
1989
+ preCommitInternalKey , groupPubKeyBytes , preCommitOutpoint ,
1967
1990
)
1968
1991
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.
1971
1994
internalKey2 , _ := test .RandKeyDesc (t )
1972
1995
1973
- storeMintAnchorUniCommitment (
1996
+ storeMintSupplyPreCommit (
1974
1997
t , * assetStore , batchKey , txOutputIndex , internalKey2 ,
1975
- groupPubKeyBytes ,
1998
+ groupPubKeyBytes , preCommitOutpoint ,
1976
1999
)
1977
2000
1978
- assertMintAnchorUniCommitment (
2001
+ assertMintSupplyPreCommit (
1979
2002
t , * assetStore , batchKey , txOutputIndex , internalKey2 ,
1980
- groupPubKeyBytes ,
2003
+ groupPubKeyBytes , preCommitOutpoint ,
1981
2004
)
1982
2005
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.
1985
2008
groupPubKey2 := test .RandPubKey (t )
1986
2009
groupPubKey2Bytes := groupPubKey2 .SerializeCompressed ()
1987
2010
1988
- storeMintAnchorUniCommitment (
2011
+ storeMintSupplyPreCommit (
1989
2012
t , * assetStore , batchKey , txOutputIndex , internalKey2 ,
1990
- groupPubKey2Bytes ,
2013
+ groupPubKey2Bytes , preCommitOutpoint ,
1991
2014
)
1992
2015
1993
- assertMintAnchorUniCommitment (
2016
+ assertMintSupplyPreCommit (
1994
2017
t , * assetStore , batchKey , txOutputIndex , internalKey2 ,
1995
- groupPubKey2Bytes ,
2018
+ groupPubKey2Bytes , preCommitOutpoint ,
1996
2019
)
1997
2020
}
1998
2021
0 commit comments