17
17
import * as chai from "chai" ;
18
18
import { expect } from "chai" ;
19
19
import * as chaiAsPromised from "chai-as-promised" ;
20
+ import * as stake from "codechain-stakeholder-sdk" ;
20
21
import * as fs from "fs" ;
21
22
import "mocha" ;
22
23
import * as path from "path" ;
23
24
24
25
import mkdirp = require( "mkdirp" ) ;
25
26
import { validators } from "../../../tendermint.dynval/constants" ;
26
27
import { PromiseExpect } from "../../helper/promise" ;
28
+ import CodeChain from "../../helper/spawn" ;
27
29
import { setTermTestTimeout , withNodes } from "../setup" ;
28
30
29
31
chai . use ( chaiAsPromised ) ;
@@ -37,7 +39,8 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
37
39
const { nodes } = withNodes ( this , {
38
40
promiseExpect,
39
41
overrideParams : {
40
- maxNumOfValidators : 3
42
+ maxNumOfValidators : 3 ,
43
+ era : 1
41
44
} ,
42
45
validators : snapshotValidators . map ( ( signer , index ) => ( {
43
46
signer,
@@ -63,30 +66,32 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
63
66
64
67
it ( "should be exist after some time" , async function ( ) {
65
68
const termWaiter = setTermTestTimeout ( this , {
66
- terms : 1
69
+ terms : 2
67
70
} ) ;
68
71
const termMetadata = await termWaiter . waitNodeUntilTerm ( nodes [ 0 ] , {
69
72
target : 2 ,
70
73
termPeriods : 1
71
74
} ) ;
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 ) ;
78
76
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 ( )
85
81
)
86
- ) . to . be . true ;
82
+ ) . to . satisfy ( fs . existsSync ) ;
87
83
} ) ;
88
84
89
85
afterEach ( async function ( ) {
90
86
promiseExpect . checkFulfilled ( ) ;
91
87
} ) ;
92
88
} ) ;
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