@@ -246,105 +246,17 @@ func assertAssetEqual(t *testing.T, a, b *asset.Asset) {
246246func TestImportAssetProof (t * testing.T ) {
247247 t .Parallel ()
248248
249- // First, we'll create a new instance of the database.
250- _ , assetStore , db := newAssetStore (t )
251-
252- // Next, we'll make a new random asset that also has a few inputs with
253- // dummy witness information.
254- testAsset := randAsset (t )
255-
256- assetRoot , err := commitment .NewAssetCommitment (testAsset )
257- require .NoError (t , err )
258-
259- taprootAssetRoot , err := commitment .NewTapCommitment (assetRoot )
260- require .NoError (t , err )
261-
262- // With our asset created, we can now create the AnnotatedProof we use
263- // to import assets into the database.
264- var blockHash chainhash.Hash
265- _ , err = rand .Read (blockHash [:])
266- require .NoError (t , err )
249+ var (
250+ ctxb = context .Background ()
267251
268- anchorTx := wire .NewMsgTx (2 )
269- anchorTx .AddTxIn (& wire.TxIn {})
270- anchorTx .AddTxOut (& wire.TxOut {
271- PkScript : bytes .Repeat ([]byte {0x01 }, 34 ),
272- Value : 10 ,
273- })
252+ dbHandle = NewDbHandle (t )
253+ assetStore = dbHandle .AssetStore
254+ )
274255
256+ // Add a random asset and corresponding proof into the database.
257+ testAsset , testProof := dbHandle .AddRandomAssetProof (t )
275258 assetID := testAsset .ID ()
276- anchorPoint := wire.OutPoint {
277- Hash : anchorTx .TxHash (),
278- Index : 0 ,
279- }
280- initialBlob := bytes .Repeat ([]byte {0x0 }, 100 )
281- updatedBlob := bytes .Repeat ([]byte {0x77 }, 100 )
282- testProof := & proof.AnnotatedProof {
283- Locator : proof.Locator {
284- AssetID : & assetID ,
285- ScriptKey : * testAsset .ScriptKey .PubKey ,
286- },
287- Blob : initialBlob ,
288- AssetSnapshot : & proof.AssetSnapshot {
289- Asset : testAsset ,
290- OutPoint : anchorPoint ,
291- AnchorBlockHash : blockHash ,
292- AnchorBlockHeight : test .RandInt [uint32 ](),
293- AnchorTxIndex : test .RandInt [uint32 ](),
294- AnchorTx : anchorTx ,
295- OutputIndex : 0 ,
296- InternalKey : test .RandPubKey (t ),
297- ScriptRoot : taprootAssetRoot ,
298- },
299- }
300- if testAsset .GroupKey != nil {
301- testProof .GroupKey = & testAsset .GroupKey .GroupPubKey
302- }
303-
304- // We'll now insert the internal key information as well as the script
305- // key ahead of time to reflect the address creation that happens
306- // elsewhere.
307- ctxb := context .Background ()
308- _ , err = db .UpsertInternalKey (ctxb , InternalKey {
309- RawKey : testProof .InternalKey .SerializeCompressed (),
310- KeyFamily : test .RandInt [int32 ](),
311- KeyIndex : test .RandInt [int32 ](),
312- })
313- require .NoError (t , err )
314- rawScriptKeyID , err := db .UpsertInternalKey (ctxb , InternalKey {
315- RawKey : testAsset .ScriptKey .RawKey .PubKey .SerializeCompressed (),
316- KeyFamily : int32 (testAsset .ScriptKey .RawKey .Family ),
317- KeyIndex : int32 (testAsset .ScriptKey .RawKey .Index ),
318- })
319- require .NoError (t , err )
320- _ , err = db .UpsertScriptKey (ctxb , NewScriptKey {
321- InternalKeyID : rawScriptKeyID ,
322- TweakedScriptKey : testAsset .ScriptKey .PubKey .SerializeCompressed (),
323- Tweak : nil ,
324- })
325- require .NoError (t , err )
326-
327- // We'll add the chain transaction of the proof now to simulate a
328- // batched transfer on a higher layer.
329- var anchorTxBuf bytes.Buffer
330- err = testProof .AnchorTx .Serialize (& anchorTxBuf )
331- require .NoError (t , err )
332- anchorTXID := testProof .AnchorTx .TxHash ()
333- _ , err = db .UpsertChainTx (ctxb , ChainTxParams {
334- Txid : anchorTXID [:],
335- RawTx : anchorTxBuf .Bytes (),
336- BlockHeight : sqlInt32 (testProof .AnchorBlockHeight ),
337- BlockHash : testProof .AnchorBlockHash [:],
338- TxIndex : sqlInt32 (testProof .AnchorTxIndex ),
339- })
340- require .NoError (t , err , "unable to insert chain tx: %w" , err )
341-
342- // With all our test data constructed, we'll now attempt to import the
343- // asset into the database.
344- require .NoError (t , assetStore .ImportProofs (
345- ctxb , proof .MockHeaderVerifier , proof .MockGroupVerifier , false ,
346- testProof ,
347- ))
259+ initialBlob := testProof .Blob
348260
349261 // We should now be able to retrieve the set of all assets inserted on
350262 // disk.
@@ -371,7 +283,7 @@ func TestImportAssetProof(t *testing.T) {
371283 ScriptKey : * testAsset .ScriptKey .PubKey ,
372284 })
373285 require .NoError (t , err )
374- require .Equal (t , initialBlob , [] byte ( currentBlob ) )
286+ require .Equal (t , initialBlob , currentBlob )
375287
376288 // We should also be able to fetch the created asset above based on
377289 // either the asset ID, or key group via the main coin selection
@@ -391,6 +303,8 @@ func TestImportAssetProof(t *testing.T) {
391303
392304 // We'll now attempt to overwrite the proof with one that has different
393305 // block information (simulating a re-org).
306+ updatedBlob := bytes .Repeat ([]byte {0x77 }, 100 )
307+
394308 testProof .AnchorBlockHash = chainhash.Hash {12 , 34 , 56 }
395309 testProof .AnchorBlockHeight = 1234
396310 testProof .AnchorTxIndex = 5678
0 commit comments