|
1 | 1 | "use strict";
|
2 | 2 |
|
3 |
| -/** @typedef {Number} Float64 */ |
4 |
| -/** @typedef {Number} Uint53 */ |
| 3 | +let DashGov = require("../"); |
| 4 | +//let Logger = require("../scripts/estimate.js"); |
5 | 5 |
|
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); |
7 | 10 |
|
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 | + }); |
9 | 16 |
|
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 | + } |
12 | 30 |
|
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 | +} |
18 | 33 |
|
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); |
24 | 38 |
|
25 |
| - console.log(""); |
26 |
| -} |
| 39 | + let voteDeadlineHeight = 2108570; |
| 40 | + let voteDeadlineTime = "2024-07-19T02:56:54.552Z"; |
27 | 41 |
|
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); |
33 | 45 |
|
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); |
38 | 52 |
|
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`); |
42 | 58 | }
|
| 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); |
43 | 66 | }
|
44 | 67 |
|
45 | 68 | check2024Aug1();
|
| 69 | +checkLameduck(); |
| 70 | + |
| 71 | +console.info("PASS: DashGov.estimateProposalCycles(count, snapshot)"); |
| 72 | +console.info(" - correctly categorizes last, lameduck, and upcoming"); |
0 commit comments