@@ -24,8 +24,9 @@ import * as path from "path";
2424
2525import  mkdirp  =  require( "mkdirp" ) ; 
2626import  {  validators  }  from  "../../../tendermint.dynval/constants" ; 
27+ import  {  faucetAddress ,  faucetSecret  }  from  "../../helper/constants" ; 
2728import  {  PromiseExpect  }  from  "../../helper/promise" ; 
28- import  CodeChain  from  "../../helper/spawn" ; 
29+ import  CodeChain ,   {   Signer   }  from  "../../helper/spawn" ; 
2930import  {  setTermTestTimeout ,  withNodes  }  from  "../setup" ; 
3031
3132chai . use ( chaiAsPromised ) ; 
@@ -36,6 +37,7 @@ const SNAPSHOT_PATH = `${__dirname}/../../../../snapshot/`;
3637describe ( "Snapshot for Tendermint with Dynamic Validator" ,  function ( )  { 
3738    const  promiseExpect  =  new  PromiseExpect ( ) ; 
3839    const  snapshotValidators  =  validators . slice ( 0 ,  3 ) ; 
40+     const  freshNodeValidator  =  validators [ 3 ] ; 
3941    const  {  nodes }  =  withNodes ( this ,  { 
4042        promiseExpect, 
4143        overrideParams : { 
@@ -82,6 +84,53 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
8284        ) . to . satisfy ( fs . existsSync ) ; 
8385    } ) ; 
8486
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 }  , 
100+             argv : [ 
101+                 "--engine-signer" , 
102+                 freshNodeValidator . platformAddress . toString ( ) , 
103+                 "--password-path" , 
104+                 `test/tendermint.dynval/${ freshNodeValidator . platformAddress . value }  , 
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 }  
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+ 
85134    afterEach ( async  function ( )  { 
86135        promiseExpect . checkFulfilled ( ) ; 
87136    } ) ; 
@@ -95,3 +144,44 @@ async function getSnapshotBlock(
95144    await  node . waitBlockNumber ( blockNumber ) ; 
96145    return  ( await  node . sdk . rpc . chain . getBlock ( blockNumber ) ) ! ; 
97146} 
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