11import { ChainID } from '@stacks/transactions' ;
22import * as fs from 'fs' ;
3+ import * as path from 'path' ;
34import { getRawEventRequests } from '../event-replay/event-requests' ;
45import { PgWriteStore } from '../datastore/pg-write-store' ;
56import { exportEventsAsTsv , importEventsFromTsv } from '../event-replay/event-replay' ;
@@ -25,7 +26,7 @@ describe('import/export tests', () => {
2526 await db ?. close ( ) ;
2627 } ) ;
2728
28- test ( 'event import and export cycle' , async ( ) => {
29+ test ( 'event import and export cycle - remote ' , async ( ) => {
2930 // Import from mocknet TSV
3031 await importEventsFromTsv ( 'src/tests-event-replay/tsv/mocknet.tsv' , 'archival' , true , true ) ;
3132 const chainTip = await db . getChainTip ( db . sql ) ;
@@ -38,14 +39,42 @@ describe('import/export tests', () => {
3839 ) ;
3940
4041 // Export into temp TSV
41- const tmpDir = 'src/tests-event-replay/.tmp' ;
42+ const tmpDir = 'src/tests-event-replay/.tmp/remote' ;
43+ fs . mkdirSync ( tmpDir , { recursive : true } ) ;
44+ await exportEventsAsTsv ( `${ tmpDir } /export.tsv` ) ;
45+
46+ // Re-import with exported TSV and check that chain tip matches.
4247 try {
43- fs . mkdirSync ( tmpDir ) ;
44- } catch ( error : any ) {
45- if ( error . code != 'EEXIST' ) throw error ;
48+ await importEventsFromTsv ( `${ tmpDir } /export.tsv` , 'archival' , true , true ) ;
49+ const newChainTip = await db . getChainTip ( db . sql ) ;
50+ expect ( newChainTip . block_height ) . toBe ( 28 ) ;
51+ expect ( newChainTip . index_block_hash ) . toBe (
52+ '0x76cd67a65c0dfd5ea450bb9efe30da89fa125bfc077c953802f718353283a533'
53+ ) ;
54+ expect ( newChainTip . block_hash ) . toBe (
55+ '0x7682af212d3c1ef62613412f9b5a727269b4548f14eca2e3f941f7ad8b3c11b2'
56+ ) ;
57+ } finally {
58+ fs . rmSync ( `${ tmpDir } /export.tsv` ) ;
4659 }
47- const tmpTsvPath = `${ tmpDir } /export.tsv` ;
48- await exportEventsAsTsv ( tmpTsvPath , true ) ;
60+ } ) ;
61+
62+ test ( 'event import and export cycle - local' , async ( ) => {
63+ // Import from mocknet TSV
64+ await importEventsFromTsv ( 'src/tests-event-replay/tsv/mocknet.tsv' , 'archival' , true , true ) ;
65+ const chainTip = await db . getChainTip ( db . sql ) ;
66+ expect ( chainTip . block_height ) . toBe ( 28 ) ;
67+ expect ( chainTip . index_block_hash ) . toBe (
68+ '0x76cd67a65c0dfd5ea450bb9efe30da89fa125bfc077c953802f718353283a533'
69+ ) ;
70+ expect ( chainTip . block_hash ) . toBe (
71+ '0x7682af212d3c1ef62613412f9b5a727269b4548f14eca2e3f941f7ad8b3c11b2'
72+ ) ;
73+
74+ // Export into temp TSV
75+ const tmpDir = 'src/tests-event-replay/.tmp/local' ;
76+ fs . mkdirSync ( tmpDir , { recursive : true } ) ;
77+ await exportEventsAsTsv ( 'local:/root/export.tsv' ) ;
4978
5079 // Re-import with exported TSV and check that chain tip matches.
5180 try {
@@ -59,7 +88,7 @@ describe('import/export tests', () => {
5988 '0x7682af212d3c1ef62613412f9b5a727269b4548f14eca2e3f941f7ad8b3c11b2'
6089 ) ;
6190 } finally {
62- fs . rmSync ( tmpDir , { force : true , recursive : true } ) ;
91+ fs . rmSync ( ` ${ tmpDir } /export.tsv` ) ;
6392 }
6493 } ) ;
6594
0 commit comments