Skip to content

Commit b0b1d1a

Browse files
committed
test: Dash.estimateNthNextProposalCycle()
1 parent 07e76eb commit b0b1d1a

File tree

1 file changed

+64
-31
lines changed

1 file changed

+64
-31
lines changed

tests/calc-start-end-epoch.js

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,73 @@
11
"use strict";
22

3-
/** @typedef {Number} Float64 */
4-
/** @typedef {Number} Uint53 */
5-
6-
let GObj = require("../");
7-
8-
const MS_PER_DAY = 24 * 60 * 60 * 1000;
9-
10-
function logEstimates(estimates) {
11-
console.log("Measured Seconds per Block", estimates.secondsPerBlock);
12-
console.log("");
13-
14-
let superblockDeltaDays = estimates.superblockDeltaMs / MS_PER_DAY;
15-
console.log(`Until next Superblock (${estimates.superblockHeight}):`);
16-
console.log(" Blocks:", estimates.superblockDelta);
17-
console.log(" Days:", superblockDeltaDays);
18-
console.log(" Date:", estimates.superblockIso);
19-
console.log("");
20-
21-
let voteDeltaDays = estimates.voteDeltaMs / MS_PER_DAY;
22-
console.log(`Until next Vote (${estimates.voteHeight}):`);
23-
console.log(" Blocks:", estimates.voteDelta);
24-
console.log(" Days:", voteDeltaDays);
25-
console.log(" Date:", estimates.voteIso);
26-
console.log("");
27-
}
3+
let DashGov = require("../");
4+
//let Logger = require("../scripts/estimate.js");
285

296
function check2024Aug1() {
30-
// let currentBlockHeight = 2114626;
31-
// let currentBlockMs = new Date("2024-08-01T22:09:01Z");
327
let currentBlockHeight = 2114623;
33-
let currentBlockMs = new Date("2024-08-01 22:01:00");
8+
let currentBlockTime = "2024-08-01T22:01:00Z";
9+
let currentBlockMs = Date.parse(currentBlockTime);
10+
11+
let cycleCount = 2;
12+
let snapshot = {
13+
ms: currentBlockMs,
14+
block: currentBlockHeight,
15+
};
16+
let estimates = DashGov.estimateProposalCycles(cycleCount, snapshot);
17+
18+
if (!estimates.last?.voteDeltaMs) {
19+
throw new Error(`missing 'estimates.last'`);
20+
}
21+
if (estimates.lameduck?.voteDeltaMs) {
22+
throw new Error(
23+
`has 'estimates.lameduck' during an active proposal period`,
24+
);
25+
}
26+
if (estimates.upcoming?.length !== cycleCount) {
27+
throw new Error(
28+
`expected '${cycleCount}' upcoming cycles but only got '${estimates.upcoming.length}'`,
29+
);
30+
}
3431

35-
let estimates = GObj.estimateFutureBlocks(currentBlockMs, currentBlockHeight);
36-
// TODO test outputs for rough legitimacy
37-
logEstimates(estimates);
32+
//Logger.logEstimates(estimates);
33+
}
34+
35+
function checkLameduck() {
36+
let secondsBefore = 3 * 24 * 60 * 60;
37+
let blocksBefore = secondsBefore / DashGov._AVG_SECS_PER_BLOCK;
38+
blocksBefore = Math.round(blocksBefore);
39+
40+
let voteDeadlineHeight = 2108570;
41+
let voteDeadlineTime = "2024-07-19T02:56:54.552Z";
42+
43+
let lameDuckHeight = voteDeadlineHeight - blocksBefore;
44+
// '2024-07-22T02:56:54.552Z' - 3 days
45+
let lameDuckMs = Date.parse(voteDeadlineTime);
46+
47+
let cycleCount = 3;
48+
let snapshot = {
49+
ms: lameDuckMs,
50+
block: lameDuckHeight,
51+
};
52+
let estimates = DashGov.estimateProposalCycles(cycleCount, snapshot);
53+
54+
if (!estimates.last?.voteDeltaMs) {
55+
throw new Error(`missing 'estimates.last'`);
56+
}
57+
if (!estimates.lameduck?.voteDeltaMs) {
58+
throw new Error(`missing 'estimates.lameduck' on lame duck period`);
59+
}
60+
if (estimates.upcoming?.length !== cycleCount) {
61+
throw new Error(
62+
`expected '${cycleCount}' upcoming cycles but only got '${estimates.upcoming.length}'`,
63+
);
64+
}
65+
66+
//Logger.logEstimates(estimates);
3867
}
3968

4069
check2024Aug1();
70+
checkLameduck();
71+
72+
console.info("PASS: DashGov.estimateProposalCycles(count, snapshot)");
73+
console.info(" - correctly categorizes last, lameduck, and upcoming");

0 commit comments

Comments
 (0)