@@ -4600,7 +4600,11 @@ describe('api tests', () => {
4600
4600
const searchResult = await supertest ( api . server ) . get ( `/extended/v1/tx/0x1234/raw` ) ;
4601
4601
expect ( searchResult . status ) . toBe ( 404 ) ;
4602
4602
} ) ;
4603
+
4603
4604
test ( 'Success: nft events for address' , async ( ) => {
4605
+ const addr1 = 'ST3J8EVYHVKH6XXPD61EE8XEHW4Y2K83861225AB1' ;
4606
+ const addr2 = 'ST1HB64MAJ1MBV4CQ80GF01DZS4T1DSMX20ADCRA4' ;
4607
+
4604
4608
const dbBlock : DbBlock = {
4605
4609
block_hash : '0xff' ,
4606
4610
index_block_hash : '0x1234' ,
@@ -4620,11 +4624,6 @@ describe('api tests', () => {
4620
4624
execution_cost_write_count : 0 ,
4621
4625
execution_cost_write_length : 0 ,
4622
4626
} ;
4623
- await db . updateBlock ( client , dbBlock ) ;
4624
-
4625
- const addr1 = 'ST3J8EVYHVKH6XXPD61EE8XEHW4Y2K83861225AB1' ;
4626
- const addr2 = 'ST1HB64MAJ1MBV4CQ80GF01DZS4T1DSMX20ADCRA4' ;
4627
-
4628
4627
const stxTx : DbTx = {
4629
4628
tx_id : '0x1111000000000000000000000000000000000000000000000000000000000000' ,
4630
4629
tx_index : 0 ,
@@ -4661,27 +4660,44 @@ describe('api tests', () => {
4661
4660
execution_cost_write_count : 0 ,
4662
4661
execution_cost_write_length : 0 ,
4663
4662
} ;
4664
- await db . updateTx ( client , stxTx ) ;
4665
-
4666
- const nftEvent1 : DbNftEvent = {
4667
- canonical : true ,
4668
- event_type : DbEventTypeId . NonFungibleTokenAsset ,
4669
- asset_event_type_id : DbAssetEventTypeId . Transfer ,
4670
- event_index : 0 ,
4671
- tx_id : '0x1111000000000000000000000000000000000000000000000000000000000000' ,
4672
- tx_index : 1 ,
4673
- block_height : dbBlock . block_height ,
4674
- asset_identifier : 'some-asset' ,
4675
- value : serializeCV ( intCV ( 0 ) ) ,
4676
- recipient : addr1 ,
4677
- sender : 'none' ,
4678
- } ;
4663
+ const nftEvents : DbNftEvent [ ] = [ ] ;
4679
4664
for ( let i = 0 ; i < 10 ; i ++ ) {
4680
- await db . updateNftEvent ( client , stxTx , nftEvent1 ) ;
4665
+ nftEvents . push ( {
4666
+ canonical : true ,
4667
+ event_type : DbEventTypeId . NonFungibleTokenAsset ,
4668
+ asset_event_type_id : DbAssetEventTypeId . Transfer ,
4669
+ event_index : 0 ,
4670
+ tx_id : stxTx . tx_id ,
4671
+ tx_index : 1 ,
4672
+ block_height : dbBlock . block_height ,
4673
+ asset_identifier : 'some-asset' ,
4674
+ value : serializeCV ( intCV ( 0 ) ) ,
4675
+ recipient : addr1 ,
4676
+ sender : 'none' ,
4677
+ } ) ;
4681
4678
}
4679
+
4680
+ await db . update ( {
4681
+ block : dbBlock ,
4682
+ microblocks : [ ] ,
4683
+ minerRewards : [ ] ,
4684
+ txs : [
4685
+ {
4686
+ tx : stxTx ,
4687
+ stxLockEvents : [ ] ,
4688
+ stxEvents : [ ] ,
4689
+ ftEvents : [ ] ,
4690
+ nftEvents : nftEvents ,
4691
+ contractLogEvents : [ ] ,
4692
+ smartContracts : [ ] ,
4693
+ names : [ ] ,
4694
+ namespaces : [ ] ,
4695
+ } ,
4696
+ ] ,
4697
+ } ) ;
4698
+
4682
4699
const limit = 2 ;
4683
4700
const offset = 0 ;
4684
-
4685
4701
// test nft for given addresses
4686
4702
const result = await supertest ( api . server ) . get (
4687
4703
`/extended/v1/address/${ addr1 } /nft_events?limit=${ limit } &offset=${ offset } `
@@ -4697,17 +4713,36 @@ describe('api tests', () => {
4697
4713
expect ( result . body . nft_events [ 0 ] . block_height ) . toBe ( 1 ) ;
4698
4714
expect ( result . body . nft_events [ 0 ] . value . repr ) . toBe ( '0' ) ;
4699
4715
4716
+ const dbBlock2 : DbBlock = {
4717
+ block_hash : '0xffff' ,
4718
+ index_block_hash : '0x123466' ,
4719
+ parent_index_block_hash : '0x1234' ,
4720
+ parent_block_hash : '0xff' ,
4721
+ parent_microblock_hash : '' ,
4722
+ parent_microblock_sequence : 0 ,
4723
+ block_height : 2 ,
4724
+ burn_block_time : 1594649995 ,
4725
+ burn_block_hash : '0x123456' ,
4726
+ burn_block_height : 124 ,
4727
+ miner_txid : '0x4321' ,
4728
+ canonical : true ,
4729
+ execution_cost_read_count : 0 ,
4730
+ execution_cost_read_length : 0 ,
4731
+ execution_cost_runtime : 0 ,
4732
+ execution_cost_write_count : 0 ,
4733
+ execution_cost_write_length : 0 ,
4734
+ } ;
4700
4735
const stxTx1 : DbTx = {
4701
- tx_id : '0x1111100000000000000000000000000000000000000000000000000000000000 ' ,
4736
+ tx_id : '0x1111100000000000000000000000000000000000000000000000000000000001 ' ,
4702
4737
tx_index : 0 ,
4703
4738
anchor_mode : 3 ,
4704
4739
nonce : 0 ,
4705
4740
raw_tx : Buffer . alloc ( 0 ) ,
4706
- index_block_hash : dbBlock . index_block_hash ,
4707
- block_hash : dbBlock . block_hash ,
4708
- block_height : dbBlock . block_height ,
4709
- burn_block_time : dbBlock . burn_block_time ,
4710
- parent_burn_block_time : 1626122935 ,
4741
+ index_block_hash : dbBlock2 . index_block_hash ,
4742
+ block_hash : dbBlock2 . block_hash ,
4743
+ block_height : dbBlock2 . block_height ,
4744
+ burn_block_time : dbBlock2 . burn_block_time ,
4745
+ parent_burn_block_time : 1626124935 ,
4711
4746
type_id : DbTxTypeId . TokenTransfer ,
4712
4747
token_transfer_amount : 1n ,
4713
4748
token_transfer_memo : Buffer . from ( 'hi' ) ,
@@ -4718,8 +4753,8 @@ describe('api tests', () => {
4718
4753
microblock_canonical : true ,
4719
4754
microblock_sequence : I32_MAX ,
4720
4755
microblock_hash : '' ,
4721
- parent_index_block_hash : dbBlock . parent_index_block_hash ,
4722
- parent_block_hash : dbBlock . parent_block_hash ,
4756
+ parent_index_block_hash : dbBlock2 . parent_index_block_hash ,
4757
+ parent_block_hash : dbBlock2 . parent_block_hash ,
4723
4758
post_conditions : Buffer . from ( [ 0x01 , 0xf5 ] ) ,
4724
4759
fee_rate : 1234n ,
4725
4760
sponsored : false ,
@@ -4733,22 +4768,37 @@ describe('api tests', () => {
4733
4768
execution_cost_write_count : 0 ,
4734
4769
execution_cost_write_length : 0 ,
4735
4770
} ;
4736
- await db . updateTx ( client , stxTx1 ) ;
4737
-
4738
4771
const nftEvent2 : DbNftEvent = {
4739
4772
canonical : true ,
4740
4773
event_type : DbEventTypeId . NonFungibleTokenAsset ,
4741
4774
asset_event_type_id : DbAssetEventTypeId . Transfer ,
4742
4775
event_index : 1 ,
4743
- tx_id : '0x1111100000000000000000000000000000000000000000000000000000000000' ,
4776
+ tx_id : stxTx1 . tx_id ,
4744
4777
tx_index : 2 ,
4745
- block_height : dbBlock . block_height ,
4778
+ block_height : dbBlock2 . block_height ,
4746
4779
asset_identifier : 'some-asset' ,
4747
4780
value : serializeCV ( intCV ( 0 ) ) ,
4748
4781
recipient : addr2 ,
4749
4782
sender : 'none' ,
4750
4783
} ;
4751
- await db . updateNftEvent ( client , stxTx , nftEvent2 ) ;
4784
+ await db . update ( {
4785
+ block : dbBlock2 ,
4786
+ microblocks : [ ] ,
4787
+ minerRewards : [ ] ,
4788
+ txs : [
4789
+ {
4790
+ tx : stxTx1 ,
4791
+ stxLockEvents : [ ] ,
4792
+ stxEvents : [ ] ,
4793
+ ftEvents : [ ] ,
4794
+ nftEvents : [ nftEvent2 ] ,
4795
+ contractLogEvents : [ ] ,
4796
+ smartContracts : [ ] ,
4797
+ names : [ ] ,
4798
+ namespaces : [ ] ,
4799
+ } ,
4800
+ ] ,
4801
+ } ) ;
4752
4802
4753
4803
const result1 = await supertest ( api . server ) . get ( `/extended/v1/address/${ addr2 } /nft_events` ) ;
4754
4804
expect ( result1 . status ) . toBe ( 200 ) ;
@@ -4757,9 +4807,9 @@ describe('api tests', () => {
4757
4807
expect ( result1 . body . nft_events . length ) . toEqual ( 1 ) ;
4758
4808
expect ( result1 . body . nft_events [ 0 ] . recipient ) . toBe ( addr2 ) ;
4759
4809
expect ( result1 . body . nft_events [ 0 ] . tx_id ) . toBe (
4760
- '0x1111100000000000000000000000000000000000000000000000000000000000 '
4810
+ '0x1111100000000000000000000000000000000000000000000000000000000001 '
4761
4811
) ;
4762
- expect ( result1 . body . nft_events [ 0 ] . block_height ) . toBe ( 1 ) ;
4812
+ expect ( result1 . body . nft_events [ 0 ] . block_height ) . toBe ( 2 ) ;
4763
4813
expect ( result . body . nft_events [ 0 ] . value . repr ) . toBe ( '0' ) ;
4764
4814
4765
4815
//check ownership for addr
0 commit comments