@@ -24,8 +24,9 @@ import * as path from "path";
24
24
25
25
import mkdirp = require( "mkdirp" ) ;
26
26
import { validators } from "../../../tendermint.dynval/constants" ;
27
+ import { faucetAddress , faucetSecret } from "../../helper/constants" ;
27
28
import { PromiseExpect } from "../../helper/promise" ;
28
- import CodeChain from "../../helper/spawn" ;
29
+ import CodeChain , { Signer } from "../../helper/spawn" ;
29
30
import { setTermTestTimeout , withNodes } from "../setup" ;
30
31
31
32
chai . use ( chaiAsPromised ) ;
@@ -36,6 +37,7 @@ const SNAPSHOT_PATH = `${__dirname}/../../../../snapshot/`;
36
37
describe ( "Snapshot for Tendermint with Dynamic Validator" , function ( ) {
37
38
const promiseExpect = new PromiseExpect ( ) ;
38
39
const snapshotValidators = validators . slice ( 0 , 3 ) ;
40
+ const freshNodeValidator = validators [ 3 ] ;
39
41
const { nodes } = withNodes ( this , {
40
42
promiseExpect,
41
43
overrideParams : {
@@ -82,6 +84,53 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
82
84
) . to . satisfy ( fs . existsSync ) ;
83
85
} ) ;
84
86
87
+ it ( "should be able to boot with the snapshot" , async function ( ) {
88
+ const termWaiter = setTermTestTimeout ( this , {
89
+ terms : 3
90
+ } ) ;
91
+ const termMetadata1 = await termWaiter . waitNodeUntilTerm ( nodes [ 0 ] , {
92
+ target : 2 ,
93
+ termPeriods : 1
94
+ } ) ;
95
+ const snapshotBlock = await getSnapshotBlock ( nodes [ 0 ] , termMetadata1 ) ;
96
+ await makeItValidator ( nodes [ 0 ] , freshNodeValidator ) ;
97
+ const snapshotPath = fs . mkdtempSync ( SNAPSHOT_PATH ) ;
98
+ const node = new CodeChain ( {
99
+ chain : `${ __dirname } /../../scheme/tendermint-dynval.json` ,
100
+ argv : [
101
+ "--engine-signer" ,
102
+ freshNodeValidator . platformAddress . toString ( ) ,
103
+ "--password-path" ,
104
+ `test/tendermint.dynval/${ freshNodeValidator . platformAddress . value } /password.json` ,
105
+ "--force-sealing" ,
106
+ "--snapshot-path" ,
107
+ snapshotPath ,
108
+ "--config" ,
109
+ SNAPSHOT_CONFIG ,
110
+ "--snapshot-hash" ,
111
+ snapshotBlock . hash . toString ( ) ,
112
+ "--snapshot-number" ,
113
+ snapshotBlock . number . toString ( )
114
+ ] ,
115
+ additionalKeysPath : `tendermint.dynval/${ freshNodeValidator . platformAddress . value } /keys`
116
+ } ) ;
117
+ try {
118
+ await node . start ( ) ;
119
+ await node . connect ( nodes [ 0 ] ) ;
120
+ await termWaiter . waitNodeUntilTerm ( node , {
121
+ target : 4 ,
122
+ termPeriods : 2
123
+ } ) ;
124
+
125
+ // Check that the freshNodeValidator is still a validator & make sure it doesn't have a block/header before termMetadata1.
126
+ } catch ( e ) {
127
+ node . keepLogs ( ) ;
128
+ throw e ;
129
+ } finally {
130
+ await node . clean ( ) ;
131
+ }
132
+ } ) ;
133
+
85
134
afterEach ( async function ( ) {
86
135
promiseExpect . checkFulfilled ( ) ;
87
136
} ) ;
@@ -95,3 +144,44 @@ async function getSnapshotBlock(
95
144
await node . waitBlockNumber ( blockNumber ) ;
96
145
return ( await node . sdk . rpc . chain . getBlock ( blockNumber ) ) ! ;
97
146
}
147
+
148
+ async function makeItValidator ( node : CodeChain , freshNodeValidator : Signer ) {
149
+ const faucetSeq = await node . sdk . rpc . chain . getSeq ( faucetAddress ) ;
150
+ const payTx = node . sdk . core
151
+ . createPayTransaction ( {
152
+ recipient : freshNodeValidator . platformAddress ,
153
+ quantity : 200000000
154
+ } )
155
+ . sign ( {
156
+ secret : faucetSecret ,
157
+ seq : faucetSeq ,
158
+ fee : 10
159
+ } ) ;
160
+ await node . waitForTx ( await node . sdk . rpc . chain . sendSignedTransaction ( payTx ) ) ;
161
+ const selfNominateTx = stake
162
+ . createSelfNominateTransaction ( node . sdk , 10000000 , "" )
163
+ . sign ( {
164
+ secret : freshNodeValidator . privateKey ,
165
+ seq : await node . sdk . rpc . chain . getSeq (
166
+ freshNodeValidator . platformAddress
167
+ ) ,
168
+ fee : 10
169
+ } ) ;
170
+ await node . waitForTx (
171
+ await node . sdk . rpc . chain . sendSignedTransaction ( selfNominateTx )
172
+ ) ;
173
+ const delegateTx = stake
174
+ . createDelegateCCSTransaction (
175
+ node . sdk ,
176
+ freshNodeValidator . platformAddress ,
177
+ 5000
178
+ )
179
+ . sign ( {
180
+ secret : faucetSecret ,
181
+ seq : faucetSeq + 1 ,
182
+ fee : 10
183
+ } ) ;
184
+ await node . waitForTx (
185
+ await node . sdk . rpc . chain . sendSignedTransaction ( delegateTx )
186
+ ) ;
187
+ }
0 commit comments