@typeberry/lib 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/core/json-parser/descriptors.d.ts.map +1 -1
- package/packages/core/json-parser/descriptors.js +3 -0
- package/packages/core/json-parser/index.test.js +30 -0
- package/packages/core/networking/package.json +1 -1
- package/packages/core/telemetry/package.json +1 -1
- package/packages/core/utils/compatibility.d.ts +0 -1
- package/packages/core/utils/compatibility.d.ts.map +1 -1
- package/packages/core/utils/compatibility.js +1 -2
- package/packages/core/utils/compatibility.test.js +6 -10
- package/packages/jam/block/index.d.ts +11 -11
- package/packages/jam/block/index.d.ts.map +1 -1
- package/packages/jam/block/index.js +11 -11
- package/packages/jam/block-json/block.d.ts +25 -25
- package/packages/jam/database-lmdb/states.test.js +3 -5
- package/packages/jam/fuzz-proto/v1/types.d.ts +1 -1
- package/packages/jam/jam-host-calls/accumulate/bless.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/bless.js +6 -10
- package/packages/jam/jam-host-calls/accumulate/bless.test.js +32 -72
- package/packages/jam/jam-host-calls/accumulate/new.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/new.js +2 -4
- package/packages/jam/jam-host-calls/accumulate/new.test.js +4 -5
- package/packages/jam/jam-host-calls/general/fetch.d.ts +1 -57
- package/packages/jam/jam-host-calls/general/fetch.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/fetch.js +6 -29
- package/packages/jam/jam-host-calls/general/fetch.test.js +2 -58
- package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts +4 -4
- package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts +13 -13
- package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts +1 -1
- package/packages/jam/node/package.json +1 -1
- package/packages/jam/node/reader.d.ts +25 -25
- package/packages/jam/node/workers.d.ts +183 -183
- package/packages/jam/state/accumulation-queue.d.ts +26 -26
- package/packages/jam/state/assurances.d.ts +26 -26
- package/packages/jam/state/privileged-services.d.ts +1 -1
- package/packages/jam/state/privileged-services.d.ts.map +1 -1
- package/packages/jam/state/privileged-services.js +1 -6
- package/packages/jam/state/service.d.ts +1 -1
- package/packages/jam/state/service.d.ts.map +1 -1
- package/packages/jam/state/statistics.d.ts +0 -8
- package/packages/jam/state/statistics.d.ts.map +1 -1
- package/packages/jam/state/statistics.js +14 -44
- package/packages/jam/state/statistics.test.js +1 -8
- package/packages/jam/state/test.utils.d.ts +1 -1
- package/packages/jam/state/test.utils.d.ts.map +1 -1
- package/packages/jam/state/test.utils.js +4 -22
- package/packages/jam/state-json/accounts.d.ts +10 -0
- package/packages/jam/state-json/accounts.d.ts.map +1 -1
- package/packages/jam/state-json/accounts.js +47 -19
- package/packages/jam/state-json/dump.d.ts.map +1 -1
- package/packages/jam/state-json/dump.js +5 -9
- package/packages/jam/state-json/dump.test.js +2 -10
- package/packages/jam/state-json/statistics.d.ts +1 -1
- package/packages/jam/state-json/statistics.d.ts.map +1 -1
- package/packages/jam/state-json/statistics.js +1 -13
- package/packages/jam/state-merkleization/in-memory-state-codec.d.ts +29 -31
- package/packages/jam/state-merkleization/in-memory-state-codec.d.ts.map +1 -1
- package/packages/jam/state-merkleization/serialize.d.ts +4 -4
- package/packages/jam/state-merkleization/serialize.d.ts.map +1 -1
- package/packages/jam/state-merkleization/serialize.js +5 -8
- package/packages/jam/state-merkleization/serialized-state-view.d.ts.map +1 -1
- package/packages/jam/state-merkleization/state-entries.test.js +1 -7
- package/packages/jam/state-vectors/index.d.ts +75 -75
- package/packages/jam/transition/accumulate/accumulate-state.d.ts +1 -2
- package/packages/jam/transition/accumulate/accumulate-state.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate-utils.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate-utils.js +2 -6
- package/packages/jam/transition/accumulate/accumulate-utils.test.js +2 -4
- package/packages/jam/transition/accumulate/accumulate.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate.js +11 -20
- package/packages/jam/transition/accumulate/index.d.ts +0 -1
- package/packages/jam/transition/accumulate/index.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/index.js +0 -1
- package/packages/jam/transition/accumulate/operand.d.ts +7 -7
- package/packages/jam/transition/chain-stf.d.ts +3 -5
- package/packages/jam/transition/chain-stf.d.ts.map +1 -1
- package/packages/jam/transition/chain-stf.js +5 -29
- package/packages/jam/transition/disputes/disputes.test.data2.d.ts +3 -3
- package/packages/jam/transition/disputes/disputes.test.data2.d.ts.map +1 -1
- package/packages/jam/transition/externalities/accumulate-externalities.d.ts.map +1 -1
- package/packages/jam/transition/externalities/accumulate-externalities.js +22 -49
- package/packages/jam/transition/externalities/accumulate-externalities.test.js +8 -72
- package/packages/jam/transition/externalities/fetch-externalities.d.ts +3 -22
- package/packages/jam/transition/externalities/fetch-externalities.d.ts.map +1 -1
- package/packages/jam/transition/externalities/fetch-externalities.js +3 -55
- package/packages/jam/transition/externalities/fetch-externalities.test.js +199 -112
- package/packages/jam/transition/statistics.d.ts +0 -7
- package/packages/jam/transition/statistics.d.ts.map +1 -1
- package/packages/jam/transition/statistics.js +2 -11
- package/packages/jam/transition/statistics.test.js +0 -40
- package/packages/workers/block-authorship/generator.test.d.ts +2 -0
- package/packages/workers/block-authorship/generator.test.d.ts.map +1 -0
- package/packages/workers/block-authorship/generator.test.js +200 -0
- package/packages/workers/block-authorship/package.json +1 -1
- package/packages/workers/block-authorship/protocol.d.ts +50 -50
- package/packages/workers/importer/package.json +1 -1
- package/packages/workers/importer/protocol.d.ts +54 -54
- package/packages/workers/jam-network/protocol.d.ts +79 -79
- package/packages/jam/transition/accumulate/deferred-transfers.d.ts +0 -36
- package/packages/jam/transition/accumulate/deferred-transfers.d.ts.map +0 -1
- package/packages/jam/transition/accumulate/deferred-transfers.js +0 -94
|
@@ -93,7 +93,6 @@ describe("Statistics", () => {
|
|
|
93
93
|
incomingReports: [],
|
|
94
94
|
availableReports: [],
|
|
95
95
|
accumulationStatistics: new Map(),
|
|
96
|
-
transferStatistics: new Map(),
|
|
97
96
|
currentValidatorData,
|
|
98
97
|
reporters,
|
|
99
98
|
});
|
|
@@ -116,7 +115,6 @@ describe("Statistics", () => {
|
|
|
116
115
|
incomingReports: [],
|
|
117
116
|
availableReports: [],
|
|
118
117
|
accumulationStatistics: new Map(),
|
|
119
|
-
transferStatistics: new Map(),
|
|
120
118
|
currentValidatorData,
|
|
121
119
|
reporters,
|
|
122
120
|
});
|
|
@@ -137,7 +135,6 @@ describe("Statistics", () => {
|
|
|
137
135
|
incomingReports: [],
|
|
138
136
|
availableReports: [],
|
|
139
137
|
accumulationStatistics: new Map(),
|
|
140
|
-
transferStatistics: new Map(),
|
|
141
138
|
currentValidatorData,
|
|
142
139
|
reporters,
|
|
143
140
|
});
|
|
@@ -217,7 +214,6 @@ describe("Statistics", () => {
|
|
|
217
214
|
incomingReports: [],
|
|
218
215
|
availableReports: [],
|
|
219
216
|
accumulationStatistics: new Map(),
|
|
220
|
-
transferStatistics: new Map(),
|
|
221
217
|
currentValidatorData,
|
|
222
218
|
reporters,
|
|
223
219
|
});
|
|
@@ -240,7 +236,6 @@ describe("Statistics", () => {
|
|
|
240
236
|
incomingReports: [],
|
|
241
237
|
availableReports: [],
|
|
242
238
|
accumulationStatistics: new Map(),
|
|
243
|
-
transferStatistics: new Map(),
|
|
244
239
|
currentValidatorData,
|
|
245
240
|
reporters,
|
|
246
241
|
});
|
|
@@ -264,7 +259,6 @@ describe("Statistics", () => {
|
|
|
264
259
|
incomingReports: [],
|
|
265
260
|
availableReports: [],
|
|
266
261
|
accumulationStatistics: new Map(),
|
|
267
|
-
transferStatistics: new Map(),
|
|
268
262
|
currentValidatorData,
|
|
269
263
|
reporters,
|
|
270
264
|
});
|
|
@@ -292,7 +286,6 @@ describe("Statistics", () => {
|
|
|
292
286
|
incomingReports: [],
|
|
293
287
|
availableReports: [],
|
|
294
288
|
accumulationStatistics: new Map(),
|
|
295
|
-
transferStatistics: new Map(),
|
|
296
289
|
currentValidatorData,
|
|
297
290
|
reporters,
|
|
298
291
|
});
|
|
@@ -330,7 +323,6 @@ describe("Statistics", () => {
|
|
|
330
323
|
incomingReports: [],
|
|
331
324
|
availableReports: [],
|
|
332
325
|
accumulationStatistics: new Map(),
|
|
333
|
-
transferStatistics: new Map(),
|
|
334
326
|
currentValidatorData,
|
|
335
327
|
reporters,
|
|
336
328
|
});
|
|
@@ -355,7 +347,6 @@ describe("Statistics", () => {
|
|
|
355
347
|
incomingReports: [],
|
|
356
348
|
availableReports: [],
|
|
357
349
|
accumulationStatistics: new Map(),
|
|
358
|
-
transferStatistics: new Map(),
|
|
359
350
|
currentValidatorData,
|
|
360
351
|
reporters,
|
|
361
352
|
});
|
|
@@ -380,7 +371,6 @@ describe("Statistics", () => {
|
|
|
380
371
|
incomingReports,
|
|
381
372
|
availableReports: [],
|
|
382
373
|
accumulationStatistics: new Map(),
|
|
383
|
-
transferStatistics: new Map(),
|
|
384
374
|
currentValidatorData,
|
|
385
375
|
reporters,
|
|
386
376
|
});
|
|
@@ -405,7 +395,6 @@ describe("Statistics", () => {
|
|
|
405
395
|
incomingReports: [],
|
|
406
396
|
availableReports: [],
|
|
407
397
|
accumulationStatistics: new Map(),
|
|
408
|
-
transferStatistics: new Map(),
|
|
409
398
|
currentValidatorData,
|
|
410
399
|
reporters,
|
|
411
400
|
});
|
|
@@ -430,7 +419,6 @@ describe("Statistics", () => {
|
|
|
430
419
|
incomingReports: asKnownSize([]),
|
|
431
420
|
availableReports,
|
|
432
421
|
accumulationStatistics: new Map(),
|
|
433
|
-
transferStatistics: new Map(),
|
|
434
422
|
currentValidatorData,
|
|
435
423
|
reporters,
|
|
436
424
|
});
|
|
@@ -460,7 +448,6 @@ describe("Statistics", () => {
|
|
|
460
448
|
incomingReports: [],
|
|
461
449
|
availableReports: [],
|
|
462
450
|
accumulationStatistics: new Map(),
|
|
463
|
-
transferStatistics: new Map(),
|
|
464
451
|
currentValidatorData,
|
|
465
452
|
reporters,
|
|
466
453
|
});
|
|
@@ -486,33 +473,6 @@ describe("Statistics", () => {
|
|
|
486
473
|
incomingReports: [],
|
|
487
474
|
availableReports: [],
|
|
488
475
|
accumulationStatistics,
|
|
489
|
-
transferStatistics: new Map(),
|
|
490
|
-
currentValidatorData,
|
|
491
|
-
reporters,
|
|
492
|
-
});
|
|
493
|
-
const state = copyAndUpdateState(statistics.state, update);
|
|
494
|
-
assert.deepEqual(state.statistics.services.get(serviceIndex), expectedStatistics);
|
|
495
|
-
});
|
|
496
|
-
it("should update on transfer score of service statistics based on on transfer statistics", () => {
|
|
497
|
-
const { statistics, currentSlot, validatorIndex, serviceIndex, serviceStatistics, currentValidatorData, reporters, } = prepareData({
|
|
498
|
-
previousSlot: 0,
|
|
499
|
-
currentSlot: 1,
|
|
500
|
-
});
|
|
501
|
-
const transferStatistics = new Map([[tryAsServiceId(0), countGasUsed(3, 7n)]]);
|
|
502
|
-
const expectedStatistics = {
|
|
503
|
-
...serviceStatistics.get(serviceIndex),
|
|
504
|
-
onTransfersCount: 3,
|
|
505
|
-
onTransfersGasUsed: 7n,
|
|
506
|
-
};
|
|
507
|
-
assert.deepEqual(statistics.state.statistics.services.get(serviceIndex), serviceStatistics.get(serviceIndex));
|
|
508
|
-
const update = statistics.transition({
|
|
509
|
-
slot: currentSlot,
|
|
510
|
-
authorIndex: validatorIndex,
|
|
511
|
-
extrinsic: getExtrinsic(),
|
|
512
|
-
incomingReports: [],
|
|
513
|
-
availableReports: [],
|
|
514
|
-
accumulationStatistics: new Map(),
|
|
515
|
-
transferStatistics,
|
|
516
476
|
currentValidatorData,
|
|
517
477
|
reporters,
|
|
518
478
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.test.d.ts","sourceRoot":"","sources":["../../../../../packages/workers/block-authorship/generator.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, it, mock } from "node:test";
|
|
2
|
+
import { Block, DisputesExtrinsic, EpochMarker, Extrinsic, Header, tryAsTimeSlot, tryAsValidatorIndex, ValidatorKeys, } from "#@typeberry/block";
|
|
3
|
+
import { Bytes, BytesBlob } from "#@typeberry/bytes";
|
|
4
|
+
import { asKnownSize, FixedSizeArray } from "#@typeberry/collections";
|
|
5
|
+
import { tinyChainSpec } from "#@typeberry/config";
|
|
6
|
+
import { BANDERSNATCH_KEY_BYTES, BANDERSNATCH_VRF_SIGNATURE_BYTES, BLS_KEY_BYTES, ED25519_KEY_BYTES, initWasm, } from "#@typeberry/crypto";
|
|
7
|
+
import { BANDERSNATCH_RING_ROOT_BYTES } from "#@typeberry/crypto/bandersnatch.js";
|
|
8
|
+
import { Blake2b, HASH_SIZE, keccak } from "#@typeberry/hash";
|
|
9
|
+
import bandersnatchVrf from "#@typeberry/safrole/bandersnatch-vrf.js";
|
|
10
|
+
import { BandernsatchWasm } from "#@typeberry/safrole/bandersnatch-wasm.js";
|
|
11
|
+
import { JAM_FALLBACK_SEAL } from "#@typeberry/safrole/constants.js";
|
|
12
|
+
import { VALIDATOR_META_BYTES, ValidatorData } from "#@typeberry/state";
|
|
13
|
+
import { SafroleSealingKeysKind } from "#@typeberry/state/safrole-data.js";
|
|
14
|
+
import { asOpaqueType, deepEqual, Result } from "#@typeberry/utils";
|
|
15
|
+
import { Generator } from "./generator.js";
|
|
16
|
+
// Test validator data - need 6 validators to match tinyChainSpec.validatorsCount
|
|
17
|
+
const validatorDataArray = [
|
|
18
|
+
{
|
|
19
|
+
bandersnatch: "0xf16e5352840afb47e206b5c89f560f2611835855cf2e6ebad1acc9520a72591d",
|
|
20
|
+
ed25519: "0x837ce344bc9defceb0d7de7e9e9925096768b7adb4dad932e532eb6551e0ea02",
|
|
21
|
+
bls: Bytes.zero(BLS_KEY_BYTES),
|
|
22
|
+
metadata: Bytes.zero(VALIDATOR_META_BYTES),
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
bandersnatch: "0x7f6190116d118d643a98878e294ccf62b509e214299931aad8ff9764181a4e33",
|
|
26
|
+
ed25519: "0xb3e0e096b02e2ec98a3441410aeddd78c95e27a0da6f411a09c631c0f2bea6e9",
|
|
27
|
+
bls: Bytes.zero(BLS_KEY_BYTES),
|
|
28
|
+
metadata: Bytes.zero(VALIDATOR_META_BYTES),
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
bandersnatch: "0x48e5fcdce10e0b64ec4eebd0d9211c7bac2f27ce54bca6f7776ff6fee86ab3e3",
|
|
32
|
+
ed25519: "0x5c7f34a4bd4f2d04076a8c6f9060a0c8d2c6bdd082ceb3eda7df381cb260faff",
|
|
33
|
+
bls: Bytes.zero(BLS_KEY_BYTES),
|
|
34
|
+
metadata: Bytes.zero(VALIDATOR_META_BYTES),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
bandersnatch: "0x5e465beb01dbafe160ce8216047f2155dd0569f058afd52dcea601025a8d161d",
|
|
38
|
+
ed25519: "0x3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29",
|
|
39
|
+
bls: Bytes.zero(BLS_KEY_BYTES),
|
|
40
|
+
metadata: Bytes.zero(VALIDATOR_META_BYTES),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
bandersnatch: "0x3d5e5a51aab2b048f8686ecd79712a80e3265a114cc73f14bdb2a59233fb66d0",
|
|
44
|
+
ed25519: "0x22351e22105a19aabb42589162ad7f1ea0df1c25cebf0e4a9fcd261301274862",
|
|
45
|
+
bls: Bytes.zero(BLS_KEY_BYTES),
|
|
46
|
+
metadata: Bytes.zero(VALIDATOR_META_BYTES),
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
bandersnatch: "0xaa2b95f7572875b0d0f186552ae745ba8222fc0b5bd456554bfe51c68938f8bc",
|
|
50
|
+
ed25519: "0xe68e0cf7f26c59f963b5846202d2327cc8bc0c4eff8cb9abd4012f9a71decf00",
|
|
51
|
+
bls: Bytes.zero(BLS_KEY_BYTES),
|
|
52
|
+
metadata: Bytes.zero(VALIDATOR_META_BYTES),
|
|
53
|
+
},
|
|
54
|
+
].map(({ bandersnatch, bls, ed25519, metadata }) => ValidatorData.create({
|
|
55
|
+
bandersnatch: Bytes.parseBytes(bandersnatch, BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
56
|
+
bls: bls.asOpaque(),
|
|
57
|
+
ed25519: Bytes.parseBytes(ed25519, ED25519_KEY_BYTES).asOpaque(),
|
|
58
|
+
metadata: metadata.asOpaque(),
|
|
59
|
+
}));
|
|
60
|
+
const validators = asKnownSize(validatorDataArray);
|
|
61
|
+
// Expected mock values - these are returned by mocked VRF functions
|
|
62
|
+
const MOCK_SEAL_SIGNATURE = Bytes.fill(BANDERSNATCH_VRF_SIGNATURE_BYTES, 2);
|
|
63
|
+
const MOCK_STATE_ROOT = Bytes.fill(HASH_SIZE, 3);
|
|
64
|
+
const MOCK_PARENT_HASH = Bytes.fill(HASH_SIZE, 0xab);
|
|
65
|
+
// Common test inputs
|
|
66
|
+
const MOCK_BANDERSNATCH_SECRET = Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque();
|
|
67
|
+
const MOCK_SEAL_PAYLOAD = asOpaqueType(BytesBlob.blobFromParts(JAM_FALLBACK_SEAL, Bytes.zero(HASH_SIZE).raw));
|
|
68
|
+
// Mock state entropy values
|
|
69
|
+
const MOCK_ENTROPY_0 = Bytes.fill(HASH_SIZE, 10).asOpaque();
|
|
70
|
+
const MOCK_ENTROPY_1 = Bytes.fill(HASH_SIZE, 20).asOpaque();
|
|
71
|
+
const MOCK_ENTROPY_2 = Bytes.fill(HASH_SIZE, 30).asOpaque();
|
|
72
|
+
const MOCK_ENTROPY_3 = Bytes.fill(HASH_SIZE, 40).asOpaque();
|
|
73
|
+
// Mock BlocksDb
|
|
74
|
+
function createMockBlocksDb(headerHash) {
|
|
75
|
+
return {
|
|
76
|
+
getBestHeaderHash: () => headerHash.asOpaque(),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Mock StatesDb
|
|
80
|
+
function createMockStatesDb(state) {
|
|
81
|
+
return {
|
|
82
|
+
getState: () => state,
|
|
83
|
+
getStateRoot: () => Promise.resolve(MOCK_STATE_ROOT.asOpaque()),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function createMockState(timeslot) {
|
|
87
|
+
const bandersnatchKeys = validatorDataArray.map((v) => v.bandersnatch);
|
|
88
|
+
return {
|
|
89
|
+
timeslot: tryAsTimeSlot(timeslot),
|
|
90
|
+
entropy: FixedSizeArray.new([MOCK_ENTROPY_0, MOCK_ENTROPY_1, MOCK_ENTROPY_2, MOCK_ENTROPY_3], 4),
|
|
91
|
+
previousValidatorData: validators,
|
|
92
|
+
currentValidatorData: validators,
|
|
93
|
+
designatedValidatorData: validators,
|
|
94
|
+
nextValidatorData: validators,
|
|
95
|
+
ticketsAccumulator: asKnownSize([]),
|
|
96
|
+
sealingKeySeries: {
|
|
97
|
+
kind: SafroleSealingKeysKind.Keys,
|
|
98
|
+
keys: asKnownSize(bandersnatchKeys),
|
|
99
|
+
},
|
|
100
|
+
epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
101
|
+
disputesRecords: {
|
|
102
|
+
punishSet: { size: 0, has: () => false },
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Creates an expected block based on mock values and provided parameters.
|
|
108
|
+
* Used for asserting generated blocks match expected structure.
|
|
109
|
+
*/
|
|
110
|
+
function createExpectedBlock(params) {
|
|
111
|
+
return Block.create({
|
|
112
|
+
header: Header.create({
|
|
113
|
+
parentHeaderHash: MOCK_PARENT_HASH.asOpaque(),
|
|
114
|
+
priorStateRoot: MOCK_STATE_ROOT.asOpaque(),
|
|
115
|
+
extrinsicHash: params.extrinsicHash.asOpaque(),
|
|
116
|
+
timeSlotIndex: params.timeSlot,
|
|
117
|
+
bandersnatchBlockAuthorIndex: params.validatorIndex,
|
|
118
|
+
entropySource: MOCK_SEAL_SIGNATURE.asOpaque(),
|
|
119
|
+
seal: MOCK_SEAL_SIGNATURE.asOpaque(),
|
|
120
|
+
epochMarker: params.epochMarker ?? null,
|
|
121
|
+
ticketsMarker: params.ticketsMarker ?? null,
|
|
122
|
+
offendersMarker: [],
|
|
123
|
+
}),
|
|
124
|
+
extrinsic: Extrinsic.create({
|
|
125
|
+
tickets: asOpaqueType([]),
|
|
126
|
+
preimages: [],
|
|
127
|
+
guarantees: asOpaqueType([]),
|
|
128
|
+
assurances: asOpaqueType([]),
|
|
129
|
+
disputes: DisputesExtrinsic.create({
|
|
130
|
+
verdicts: [],
|
|
131
|
+
culprits: [],
|
|
132
|
+
faults: [],
|
|
133
|
+
}),
|
|
134
|
+
}),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
describe("Generator", () => {
|
|
138
|
+
let blake2b;
|
|
139
|
+
let keccakHasher;
|
|
140
|
+
let bandersnatch;
|
|
141
|
+
beforeEach(async () => {
|
|
142
|
+
await initWasm();
|
|
143
|
+
blake2b = await Blake2b.createHasher();
|
|
144
|
+
keccakHasher = await keccak.KeccakHasher.create();
|
|
145
|
+
bandersnatch = await BandernsatchWasm.new();
|
|
146
|
+
// Mock VRF functions to return predictable results
|
|
147
|
+
mock.method(bandersnatchVrf, "getVrfOutputHash", () => Promise.resolve(Result.ok(Bytes.zero(HASH_SIZE).asOpaque())));
|
|
148
|
+
mock.method(bandersnatchVrf, "generateSeal", () => Promise.resolve(Result.ok(MOCK_SEAL_SIGNATURE.asOpaque())));
|
|
149
|
+
mock.method(bandersnatchVrf, "getRingCommitment", () => Promise.resolve(Result.ok(Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque())));
|
|
150
|
+
});
|
|
151
|
+
afterEach(() => {
|
|
152
|
+
mock.restoreAll();
|
|
153
|
+
});
|
|
154
|
+
describe("nextBlock - fallback mode", () => {
|
|
155
|
+
it("should create block for same-epoch slot", async () => {
|
|
156
|
+
const state = createMockState(0);
|
|
157
|
+
const blocksDb = createMockBlocksDb(MOCK_PARENT_HASH);
|
|
158
|
+
const statesDb = createMockStatesDb(state);
|
|
159
|
+
const generator = new Generator(tinyChainSpec, bandersnatch, keccakHasher, blake2b, blocksDb, statesDb);
|
|
160
|
+
const validatorIndex = tryAsValidatorIndex(0);
|
|
161
|
+
const timeSlot = tryAsTimeSlot(1);
|
|
162
|
+
const block = await generator.nextBlock(validatorIndex, MOCK_BANDERSNATCH_SECRET, MOCK_SEAL_PAYLOAD, timeSlot);
|
|
163
|
+
const expectedBlock = createExpectedBlock({
|
|
164
|
+
timeSlot,
|
|
165
|
+
validatorIndex,
|
|
166
|
+
extrinsicHash: block.header.extrinsicHash,
|
|
167
|
+
});
|
|
168
|
+
deepEqual(block, expectedBlock);
|
|
169
|
+
});
|
|
170
|
+
it("should create block with epoch marker at epoch boundary", async () => {
|
|
171
|
+
// tinyChainSpec.epochLength = 12, so:
|
|
172
|
+
// - timeslot 11 is last slot of epoch 0
|
|
173
|
+
// - timeslot 12 is first slot of epoch 1
|
|
174
|
+
const lastSlotOfEpoch0 = tinyChainSpec.epochLength - 1;
|
|
175
|
+
const firstSlotOfEpoch1 = tinyChainSpec.epochLength;
|
|
176
|
+
const state = createMockState(lastSlotOfEpoch0);
|
|
177
|
+
const blocksDb = createMockBlocksDb(MOCK_PARENT_HASH);
|
|
178
|
+
const statesDb = createMockStatesDb(state);
|
|
179
|
+
const generator = new Generator(tinyChainSpec, bandersnatch, keccakHasher, blake2b, blocksDb, statesDb);
|
|
180
|
+
const validatorIndex = tryAsValidatorIndex(0);
|
|
181
|
+
const timeSlot = tryAsTimeSlot(firstSlotOfEpoch1);
|
|
182
|
+
const block = await generator.nextBlock(validatorIndex, MOCK_BANDERSNATCH_SECRET, MOCK_SEAL_PAYLOAD, timeSlot);
|
|
183
|
+
const expectedEpochMarker = EpochMarker.create({
|
|
184
|
+
entropy: MOCK_ENTROPY_0,
|
|
185
|
+
ticketsEntropy: MOCK_ENTROPY_1,
|
|
186
|
+
validators: asKnownSize(validatorDataArray.map((v) => ValidatorKeys.create({
|
|
187
|
+
bandersnatch: v.bandersnatch,
|
|
188
|
+
ed25519: v.ed25519,
|
|
189
|
+
}))),
|
|
190
|
+
});
|
|
191
|
+
const expectedBlock = createExpectedBlock({
|
|
192
|
+
timeSlot,
|
|
193
|
+
validatorIndex,
|
|
194
|
+
extrinsicHash: block.header.extrinsicHash,
|
|
195
|
+
epochMarker: expectedEpochMarker,
|
|
196
|
+
});
|
|
197
|
+
deepEqual(block, expectedBlock);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|