Skip to content

Commit 580f985

Browse files
committed
Add a test for termSeconds that should be applied after the term is terminated
1 parent 0a39b0c commit 580f985

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

test/src/e2e.dynval/dv.changeParams.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,61 @@ describe("Change commonParams", function() {
105105
Math.floor(secondTermLastBlockTimeStamp / termSeconds)
106106
);
107107
});
108+
109+
it("should be applied after a term seconds", async function() {
110+
this.slow(20_000 + 5_000);
111+
this.timeout((20_000 + 5_000) * 1.5);
112+
113+
const initialTermSeconds = defaultParams.termSeconds;
114+
const newTermSeconds = 5;
115+
116+
const term1Metadata = (await stake.getTermMetadata(nodes[0].sdk))!;
117+
{
118+
expect(term1Metadata.currentTermId).to.be.equal(1);
119+
}
120+
await nodes[0].waitForTx(
121+
changeParams(nodes[0], 1, {
122+
...defaultParams,
123+
termSeconds: newTermSeconds
124+
})
125+
);
126+
127+
await nodes[0].waitForTermChange(
128+
2,
129+
initialTermSeconds * 1000 * margin
130+
);
131+
132+
const term2Metadata = (await stake.getTermMetadata(nodes[0].sdk))!;
133+
{
134+
expect(term2Metadata.currentTermId).to.be.equal(2);
135+
}
136+
137+
await nodes[0].waitForTermChange(3, newTermSeconds * 1000 * margin);
138+
139+
const term3Metadata = (await stake.getTermMetadata(nodes[0].sdk))!;
140+
{
141+
expect(term2Metadata.currentTermId).to.be.equal(2);
142+
}
143+
144+
const [ts1, ts2, ts3] = await Promise.all(
145+
[term1Metadata, term2Metadata, term3Metadata].map(m =>
146+
nodes[0].sdk.rpc.chain
147+
.getBlock(m.lastTermFinishedBlockNumber)
148+
.then(block => block!.timestamp)
149+
)
150+
);
151+
152+
// allows +- 30% error
153+
expect(ts2 - ts1)
154+
.is.approximately(initialTermSeconds, initialTermSeconds * 0.3)
155+
.but.not.approximately(newTermSeconds, newTermSeconds * 0.3);
156+
expect(ts3 - ts2)
157+
.is.approximately(newTermSeconds, newTermSeconds * 0.3)
158+
.but.not.approximately(
159+
initialTermSeconds,
160+
initialTermSeconds * 0.3
161+
);
162+
});
108163
});
109164

110165
describe("Change minimum fee", async function() {

0 commit comments

Comments
 (0)