1
1
import { ChainID } from '@stacks/transactions' ;
2
2
import * as fs from 'fs' ;
3
+ import * as path from 'path' ;
3
4
import { getRawEventRequests } from '../event-replay/event-requests' ;
4
5
import { PgWriteStore } from '../datastore/pg-write-store' ;
5
6
import { exportEventsAsTsv , importEventsFromTsv } from '../event-replay/event-replay' ;
@@ -25,7 +26,7 @@ describe('import/export tests', () => {
25
26
await db ?. close ( ) ;
26
27
} ) ;
27
28
28
- test ( 'event import and export cycle' , async ( ) => {
29
+ test ( 'event import and export cycle - remote ' , async ( ) => {
29
30
// Import from mocknet TSV
30
31
await importEventsFromTsv ( 'src/tests-event-replay/tsv/mocknet.tsv' , 'archival' , true , true ) ;
31
32
const chainTip = await db . getChainTip ( db . sql ) ;
@@ -38,14 +39,42 @@ describe('import/export tests', () => {
38
39
) ;
39
40
40
41
// 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.
42
47
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` ) ;
46
59
}
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' ) ;
49
78
50
79
// Re-import with exported TSV and check that chain tip matches.
51
80
try {
@@ -59,7 +88,7 @@ describe('import/export tests', () => {
59
88
'0x7682af212d3c1ef62613412f9b5a727269b4548f14eca2e3f941f7ad8b3c11b2'
60
89
) ;
61
90
} finally {
62
- fs . rmSync ( tmpDir , { force : true , recursive : true } ) ;
91
+ fs . rmSync ( ` ${ tmpDir } /export.tsv` ) ;
63
92
}
64
93
} ) ;
65
94
0 commit comments