@@ -54,6 +54,60 @@ describe("Snapshot", async function() {
54
54
) . to . satisfies ( fs . existsSync ) ;
55
55
} ) ;
56
56
57
+ it ( "can restore from snapshot" , async function ( ) {
58
+ for ( let i = 0 ; i < 10 ; i ++ ) {
59
+ const tx = await node . sendPayTx ( {
60
+ quantity : 100 ,
61
+ recipient : aliceAddress
62
+ } ) ;
63
+ await node . waitForTx ( tx . hash ( ) ) ;
64
+ }
65
+
66
+ const pay = await node . sendPayTx ( {
67
+ quantity : 100 ,
68
+ recipient : aliceAddress
69
+ } ) ;
70
+
71
+ const blockHash = ( await node . sdk . rpc . chain . getTransaction ( pay . hash ( ) ) ) !
72
+ . blockHash ! ;
73
+
74
+ const block = ( await node . sdk . rpc . chain . getBlock ( blockHash ) ) ! ;
75
+ await node . sdk . rpc . sendRpcRequest ( "devel_snapshot" , [
76
+ blockHash . toJSON ( )
77
+ ] ) ;
78
+ // Wait for 1 secs
79
+ await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
80
+
81
+ const newNode = new CodeChain ( {
82
+ argv : [
83
+ "--snapshot-hash" ,
84
+ block . hash . toString ( ) ,
85
+ "--snapshot-number" ,
86
+ block . number . toString ( )
87
+ ]
88
+ } ) ;
89
+
90
+ try {
91
+ await newNode . start ( ) ;
92
+ await newNode . connect ( node ) ;
93
+ await newNode . waitBlockNumber ( block . number ) ;
94
+ await node . sdk . rpc . devel . stopSealing ( ) ;
95
+ // New node creates block
96
+ const newPay = await newNode . sendPayTx ( {
97
+ quantity : 100 ,
98
+ recipient : aliceAddress
99
+ } ) ;
100
+ await newNode . waitForTx ( newPay . hash ( ) ) ;
101
+ await node . sdk . rpc . devel . startSealing ( ) ;
102
+ await node . waitForTx ( newPay . hash ( ) ) ;
103
+ } catch ( e ) {
104
+ newNode . keepLogs ( ) ;
105
+ throw e ;
106
+ } finally {
107
+ await newNode . clean ( ) ;
108
+ }
109
+ } ) ;
110
+
57
111
afterEach ( function ( ) {
58
112
if ( this . currentTest ! . state === "failed" ) {
59
113
node . keepLogs ( ) ;
0 commit comments