|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +let Assert = require("assert/strict"); |
| 4 | + |
| 5 | +let DashGov = require("../"); |
| 6 | + |
| 7 | +let currentBlockHeight = 2114623; |
| 8 | +let currentBlockMs = Date.parse("2024-08-01T22:01:00Z"); |
| 9 | +let snapshot = { block: currentBlockHeight, ms: currentBlockMs }; |
| 10 | + |
| 11 | +let tests = [ |
| 12 | + [ |
| 13 | + -1, |
| 14 | + { |
| 15 | + voteHeight: 2091954, |
| 16 | + voteIso: "2024-06-21T19:44:00.268Z", |
| 17 | + voteMs: 1718999040268, |
| 18 | + voteDelta: -22669, |
| 19 | + voteDeltaMs: -3572218838.0476646, |
| 20 | + superblockHeight: 2093616, |
| 21 | + superblockDelta: -21007, |
| 22 | + superblockIso: "2024-06-24T20:29:01.895Z", |
| 23 | + superblockMs: 1719260941895, |
| 24 | + superblockDeltaMs: -3310318105.380356, |
| 25 | + }, |
| 26 | + ], |
| 27 | + [ |
| 28 | + 0, |
| 29 | + { |
| 30 | + voteHeight: 2108570, |
| 31 | + voteIso: "2024-07-22T03:03:37.268Z", |
| 32 | + voteMs: 1721617417268, |
| 33 | + voteDelta: -6053, |
| 34 | + voteDeltaMs: -953841838.0476648, |
| 35 | + superblockHeight: 2110232, |
| 36 | + superblockDelta: -4391, |
| 37 | + superblockIso: "2024-07-25T03:48:38.895Z", |
| 38 | + superblockMs: 1721879318895, |
| 39 | + superblockDeltaMs: -691941105.3803562, |
| 40 | + }, |
| 41 | + ], |
| 42 | + [ |
| 43 | + 1, |
| 44 | + { |
| 45 | + voteHeight: 2125186, |
| 46 | + voteIso: "2024-08-21T10:23:14.268Z", |
| 47 | + voteMs: 1724235794268, |
| 48 | + voteDelta: 10563, |
| 49 | + voteDeltaMs: 1664535161.952335, |
| 50 | + superblockHeight: 2126848, |
| 51 | + superblockDelta: 12225, |
| 52 | + superblockIso: "2024-08-24T11:08:15.894Z", |
| 53 | + superblockMs: 1724497695894, |
| 54 | + superblockDeltaMs: 1926435894.6196434, |
| 55 | + }, |
| 56 | + ], |
| 57 | +]; |
| 58 | + |
| 59 | +for (let test of tests) { |
| 60 | + let offset = test[0]; |
| 61 | + let expected = test[1]; |
| 62 | + let estimate = DashGov.estimateNthNextGovCycle( |
| 63 | + snapshot, |
| 64 | + DashGov._AVG_SECS_PER_BLOCK, |
| 65 | + offset, |
| 66 | + ); |
| 67 | + Assert.deepEqual(estimate, expected); |
| 68 | +} |
| 69 | + |
| 70 | +console.info( |
| 71 | + `PASS: DashGov.estimateNthNextGovCycle(snapshot, secsPerBlock, offset)`, |
| 72 | +); |
0 commit comments