1717import * as chai from "chai" ;
1818import { expect } from "chai" ;
1919import * as chaiAsPromised from "chai-as-promised" ;
20+ import * as stake from "codechain-stakeholder-sdk" ;
2021import * as fs from "fs" ;
2122import "mocha" ;
2223import * as path from "path" ;
2324
2425import mkdirp = require( "mkdirp" ) ;
2526import { validators } from "../../../tendermint.dynval/constants" ;
2627import { PromiseExpect } from "../../helper/promise" ;
28+ import CodeChain from "../../helper/spawn" ;
2729import { setTermTestTimeout , withNodes } from "../setup" ;
2830
2931chai . use ( chaiAsPromised ) ;
@@ -37,7 +39,8 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
3739 const { nodes } = withNodes ( this , {
3840 promiseExpect,
3941 overrideParams : {
40- maxNumOfValidators : 3
42+ maxNumOfValidators : 3 ,
43+ era : 1
4144 } ,
4245 validators : snapshotValidators . map ( ( signer , index ) => ( {
4346 signer,
@@ -63,30 +66,32 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
6366
6467 it ( "should be exist after some time" , async function ( ) {
6568 const termWaiter = setTermTestTimeout ( this , {
66- terms : 1
69+ terms : 2
6770 } ) ;
6871 const termMetadata = await termWaiter . waitNodeUntilTerm ( nodes [ 0 ] , {
6972 target : 2 ,
7073 termPeriods : 1
7174 } ) ;
72-
73- const blockHash = ( await nodes [ 0 ] . sdk . rpc . chain . getBlockHash (
74- termMetadata . lastTermFinishedBlockNumber
75- ) ) ! ;
76- const stateRoot = ( await nodes [ 0 ] . sdk . rpc . chain . getBlock ( blockHash ) ) !
77- . stateRoot ;
75+ const snapshotBlock = await getSnapshotBlock ( nodes [ 0 ] , termMetadata ) ;
7876 expect (
79- fs . existsSync (
80- path . join (
81- nodes [ 0 ] . snapshotPath ,
82- blockHash . toString ( ) ,
83- stateRoot . toString ( )
84- )
77+ path . join (
78+ nodes [ 0 ] . snapshotPath ,
79+ snapshotBlock . hash . toString ( ) ,
80+ snapshotBlock . stateRoot . toString ( )
8581 )
86- ) . to . be . true ;
82+ ) . to . satisfy ( fs . existsSync ) ;
8783 } ) ;
8884
8985 afterEach ( async function ( ) {
9086 promiseExpect . checkFulfilled ( ) ;
9187 } ) ;
9288} ) ;
89+
90+ async function getSnapshotBlock (
91+ node : CodeChain ,
92+ termMetadata : stake . TermMetadata
93+ ) {
94+ const blockNumber = termMetadata . lastTermFinishedBlockNumber + 1 ;
95+ await node . waitBlockNumber ( blockNumber ) ;
96+ return ( await node . sdk . rpc . chain . getBlock ( blockNumber ) ) ! ;
97+ }
0 commit comments