Skip to content

Commit 59fde94

Browse files
committed
f: calc start and end epoch (moved logging to estimate script)
1 parent 2b1570e commit 59fde94

File tree

1 file changed

+57
-30
lines changed

1 file changed

+57
-30
lines changed

tests/calc-start-end-epoch.js

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,72 @@
11
"use strict";
22

3-
/** @typedef {Number} Float64 */
4-
/** @typedef {Number} Uint53 */
3+
let DashGov = require("../");
4+
//let Logger = require("../scripts/estimate.js");
55

6-
let GObj = require("../");
6+
function check2024Aug1() {
7+
let currentBlockHeight = 2114623;
8+
let currentBlockTime = "2024-08-01T22:01:00Z";
9+
let currentBlockMs = Date.parse(currentBlockTime);
710

8-
const MS_PER_DAY = 24 * 60 * 60 * 1000;
11+
let cycleCount = 2;
12+
let estimates = DashGov.estimateProposalCycles(cycleCount, {
13+
ms: currentBlockMs,
14+
block: currentBlockHeight,
15+
});
916

10-
function logEstimates(estimates) {
11-
console.log(`Until next...`);
17+
if (!estimates.last?.voteDeltaMs) {
18+
throw new Error(`missing 'estimates.last'`);
19+
}
20+
if (estimates.lameduck?.voteDeltaMs) {
21+
throw new Error(
22+
`has 'estimates.lameduck' during an active proposal period`,
23+
);
24+
}
25+
if (estimates.upcoming?.length !== cycleCount) {
26+
throw new Error(
27+
`expected '${cycleCount}' upcoming cycles but only got '${estimates.upcoming.length}'`,
28+
);
29+
}
1230

13-
let voteDeltaDays = estimates.voteDeltaMs / MS_PER_DAY;
14-
console.log(` Vote (${estimates.voteHeight}):`);
15-
console.log(" Blocks:", estimates.voteDelta);
16-
console.log(" Days:", voteDeltaDays);
17-
console.log(" Date:", estimates.voteIso);
31+
//Logger.logEstimates(estimates);
32+
}
1833

19-
let superblockDeltaDays = estimates.superblockDeltaMs / MS_PER_DAY;
20-
console.log(` Superblock (${estimates.superblockHeight}):`);
21-
console.log(" Blocks:", estimates.superblockDelta);
22-
console.log(" Days:", superblockDeltaDays);
23-
console.log(" Date:", estimates.superblockIso);
34+
function checkLameduck() {
35+
let secondsBefore = 3 * 24 * 60 * 60;
36+
let blocksBefore = secondsBefore / DashGov._AVG_SECS_PER_BLOCK;
37+
blocksBefore = Math.round(blocksBefore);
2438

25-
console.log("");
26-
}
39+
let voteDeadlineHeight = 2108570;
40+
let voteDeadlineTime = "2024-07-19T02:56:54.552Z";
2741

28-
function check2024Aug1() {
29-
// let currentBlockHeight = 2114626;
30-
// let currentBlockMs = new Date("2024-08-01T22:09:01Z");
31-
let currentBlockHeight = 2114623;
32-
let currentBlockMs = new Date("2024-08-01 22:01:00");
42+
let lameDuckHeight = voteDeadlineHeight - blocksBefore;
43+
// '2024-07-22T02:56:54.552Z' - 3 days
44+
let lameDuckMs = Date.parse(voteDeadlineTime);
3345

34-
let estimates = GObj.estimateFutureBlocks(currentBlockMs, currentBlockHeight);
35-
console.log("Measured Seconds per Block", estimates[0].secondsPerBlock);
36-
console.log("");
37-
console.log(estimates);
46+
let cycleCount = 3;
47+
let snapshot = {
48+
ms: lameDuckMs,
49+
block: lameDuckHeight,
50+
};
51+
let estimates = DashGov.estimateProposalCycles(cycleCount, snapshot);
3852

39-
for (let estimate of estimates) {
40-
// TODO test outputs for rough legitimacy
41-
logEstimates(estimate);
53+
if (!estimates.last?.voteDeltaMs) {
54+
throw new Error(`missing 'estimates.last'`);
55+
}
56+
if (!estimates.lameduck?.voteDeltaMs) {
57+
throw new Error(`missing 'estimates.lameduck' on lame duck period`);
4258
}
59+
if (estimates.upcoming?.length !== cycleCount) {
60+
throw new Error(
61+
`expected '${cycleCount}' upcoming cycles but only got '${estimates.upcoming.length}'`,
62+
);
63+
}
64+
65+
//Logger.logEstimates(estimates);
4366
}
4467

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

0 commit comments

Comments
 (0)