@midnightntwrk/testkit-js 0.0.0-stage → 5.0.1

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.
Files changed (56) hide show
  1. package/README.md +409 -2
  2. package/dist/fixtures/hf/README.md +781 -0
  3. package/dist/fixtures/hf/coin-receiver-016/coin-receiver.compact +24 -0
  4. package/dist/fixtures/hf/coin-receiver-016/compiled/compiler/contract-info.json +104 -0
  5. package/dist/fixtures/hf/coin-receiver-016/compiled/contract/index.d.ts +47 -0
  6. package/dist/fixtures/hf/coin-receiver-016/compiled/contract/index.js +412 -0
  7. package/dist/fixtures/hf/coin-receiver-016/receive-coin-transcript.recording.json +668 -0
  8. package/dist/fixtures/hf/coin-receiver-016/state-v6-envelope.hex +1 -0
  9. package/dist/fixtures/hf/coin-receiver-016/state-v9.hex +1 -0
  10. package/dist/fixtures/hf/counter-016/compiled/compiler/contract-info.json +31 -0
  11. package/dist/fixtures/hf/counter-016/compiled/contract/index.d.ts +39 -0
  12. package/dist/fixtures/hf/counter-016/compiled/contract/index.js +189 -0
  13. package/dist/fixtures/hf/counter-016/compiled/keys/increment.prover +0 -0
  14. package/dist/fixtures/hf/counter-016/compiled/keys/increment.verifier +0 -0
  15. package/dist/fixtures/hf/counter-016/compiled/zkir/increment.bzkir +0 -0
  16. package/dist/fixtures/hf/counter-016/compiled/zkir/increment.zkir +22 -0
  17. package/dist/fixtures/hf/counter-016/increment-transcript.golden.json +23 -0
  18. package/dist/fixtures/hf/fixtures.json +69 -0
  19. package/dist/fixtures/hf/pre-fork-private-state-store/.gitattributes +8 -0
  20. package/dist/fixtures/hf/pre-fork-private-state-store/ENVELOPE.md +70 -0
  21. package/dist/fixtures/hf/pre-fork-private-state-store/store/000005.ldb +0 -0
  22. package/dist/fixtures/hf/pre-fork-private-state-store/store/000006.log +0 -0
  23. package/dist/fixtures/hf/pre-fork-private-state-store/store/CURRENT +1 -0
  24. package/dist/fixtures/hf/pre-fork-private-state-store/store/MANIFEST-000004 +0 -0
  25. package/dist/fixtures/hf/private-counter-016/README.md +13 -0
  26. package/dist/fixtures/hf/private-counter-016/compiled/compiler/contract-info.json +40 -0
  27. package/dist/fixtures/hf/private-counter-016/compiled/contract/index.d.ts +40 -0
  28. package/dist/fixtures/hf/private-counter-016/compiled/contract/index.js +211 -0
  29. package/dist/fixtures/hf/private-counter-twin/compiled/compiler/contract-info.json +41 -0
  30. package/dist/fixtures/hf/private-counter-twin/compiled/contract/index.js +271 -0
  31. package/dist/fixtures/hf/private-counter-twin/private-counter.compact +27 -0
  32. package/dist/fixtures/hf/state-both-keys.hex +1 -0
  33. package/dist/fixtures/hf/state-co-v2-only-foreign.hex +1 -0
  34. package/dist/fixtures/hf/state-migrated-v9-merkle.hex +1 -0
  35. package/dist/fixtures/hf/state-migrated-v9.hex +1 -0
  36. package/dist/fixtures/hf/state-tampered-bytes.hex +1 -0
  37. package/dist/fixtures/hf/state-tampered-keyset-v8to9.hex +1 -0
  38. package/dist/fixtures/hf/state-tampered-keyset-v9to8.hex +1 -0
  39. package/dist/fixtures/hf/state-v8-v6-envelope.hex +1 -0
  40. package/dist/fixtures/hf/state-v8.hex +1 -0
  41. package/dist/fixtures/hf/twin-contract/compiled/compiler/contract-info.json +31 -0
  42. package/dist/fixtures/hf/twin-contract/compiled/compiler/contract-manifest.json +58 -0
  43. package/dist/fixtures/hf/twin-contract/compiled/contract/index.d.ts +40 -0
  44. package/dist/fixtures/hf/twin-contract/compiled/contract/index.js +196 -0
  45. package/dist/fixtures/hf/twin-contract/compiled/keys/increment.prover +0 -0
  46. package/dist/fixtures/hf/twin-contract/compiled/keys/increment.verifier +0 -0
  47. package/dist/fixtures/hf/twin-contract/compiled/zkir/increment.bzkir +0 -0
  48. package/dist/fixtures/hf/twin-contract/compiled/zkir/increment.zkir +22 -0
  49. package/dist/fixtures/hf/twin-contract/counter.compact +15 -0
  50. package/dist/fixtures-hf.d.ts +70 -0
  51. package/dist/fixtures-hf.js +161 -0
  52. package/dist/fixtures-hf.js.map +1 -0
  53. package/dist/index.d.ts +1067 -0
  54. package/dist/index.js +3459 -0
  55. package/dist/index.js.map +1 -0
  56. package/package.json +82 -3
@@ -0,0 +1,161 @@
1
+ import { readFileSync, statSync } from 'node:fs';
2
+ import { resolve, relative, isAbsolute } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ /*
6
+ * This file is part of midnight-js.
7
+ * Copyright (C) Midnight Foundation
8
+ * SPDX-License-Identifier: Apache-2.0
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * You may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ /**
20
+ * Typed access to the hard-fork state fixtures shipped with this package.
21
+ *
22
+ * The fixture bytes live next to this module, under `fixtures/hf/`, and are
23
+ * copied verbatim into `dist` by the build. Paths are resolved relative to this
24
+ * module's own URL, so the same code reaches `src/fixtures/hf` when running
25
+ * from source and `dist/fixtures/hf` when running from the published package.
26
+ *
27
+ * Every accessor throws on anything it cannot serve. None of them returns empty
28
+ * bytes, a missing-file placeholder or a partially decoded buffer.
29
+ */
30
+ /**
31
+ * The nine hard-fork state fixtures, by file name. Provenance and the exact
32
+ * tampering applied to each are documented in `fixtures/hf/README.md`, which
33
+ * ships alongside the bytes.
34
+ */
35
+ const HF_FIXTURE_NAMES = [
36
+ 'state-v8.hex',
37
+ 'state-v8-v6-envelope.hex',
38
+ 'state-migrated-v9.hex',
39
+ 'state-migrated-v9-merkle.hex',
40
+ 'state-tampered-keyset-v8to9.hex',
41
+ 'state-tampered-keyset-v9to8.hex',
42
+ 'state-tampered-bytes.hex',
43
+ 'state-both-keys.hex',
44
+ 'state-co-v2-only-foreign.hex'
45
+ ];
46
+ /**
47
+ * What a fixture is good for.
48
+ *
49
+ * - `valid` — a real state that deserializes cleanly on the ledger matching
50
+ * its `protocolVersion`, and is fit to use as a known-good input.
51
+ * - `synthetic` — hand-built rather than produced by a real migration, but
52
+ * still a valid state on its ledger.
53
+ * - `tampered` — deliberately corrupt; expected to be rejected at decode.
54
+ * - `foreign-key` — decodes cleanly, but carries a deliberately foreign
55
+ * verifier key, so it fails only later at execution. Deliberately kept out
56
+ * of `valid`: filtering on `valid` must never hand back a poisoned state.
57
+ */
58
+ const HF_FIXTURE_STATUSES = ['valid', 'synthetic', 'tampered', 'foreign-key'];
59
+ const FIXTURES_DIR = fileURLToPath(new URL('./fixtures/hf/', import.meta.url));
60
+ const MANIFEST_FILE = 'fixtures.json';
61
+ const HEX_TEXT = /^[0-9a-f]+$/;
62
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
63
+ const isFixtureStatus = (value) => HF_FIXTURE_STATUSES.some((status) => status === value);
64
+ const isProtocolVersion = (value) => value === null || Number.isInteger(value);
65
+ /**
66
+ * Resolves a path inside the shipped fixture tree, for assets this module
67
+ * exposes no dedicated reader for: every compiled contract and its sources,
68
+ * the golden and recorded transcripts, the `coin-receiver-016` state
69
+ * envelopes, the frozen private-state store, the manifest and the README.
70
+ * Deliberately not enumerated fixture-by-fixture -- that list has gone stale
71
+ * before. What each asset is, and which of them are reachable only this way, is
72
+ * documented in `fixtures/hf/README.md`.
73
+ *
74
+ * @param relativePath Path relative to the fixture directory, e.g.
75
+ * `twin-contract/counter.compact`.
76
+ * @returns The absolute path to an existing file.
77
+ * @throws If the path escapes the fixture directory, or names no shipped file.
78
+ */
79
+ const hfFixturePath = (relativePath) => {
80
+ const path = resolve(FIXTURES_DIR, relativePath);
81
+ const inside = relative(FIXTURES_DIR, path);
82
+ if (inside.startsWith('..') || isAbsolute(inside)) {
83
+ throw new Error(`${relativePath} resolves outside the hard-fork fixture directory ${FIXTURES_DIR}`);
84
+ }
85
+ if (!statSync(path, { throwIfNoEntry: false })?.isFile()) {
86
+ throw new Error(`no such hard-fork fixture file: ${relativePath} (looked in ${FIXTURES_DIR})`);
87
+ }
88
+ return path;
89
+ };
90
+ const parseEntry = (name, value) => {
91
+ if (!isRecord(value)) {
92
+ throw new Error(`${MANIFEST_FILE} entry ${name} is not an object`);
93
+ }
94
+ const { protocolVersion, status } = value;
95
+ if (!isProtocolVersion(protocolVersion)) {
96
+ throw new Error(`${MANIFEST_FILE} entry ${name} has a protocolVersion that is neither an integer nor null`);
97
+ }
98
+ if (!isFixtureStatus(status)) {
99
+ throw new Error(`${MANIFEST_FILE} entry ${name} has status ${JSON.stringify(status)}, expected one of ${HF_FIXTURE_STATUSES.join(', ')}`);
100
+ }
101
+ return { protocolVersion, status };
102
+ };
103
+ const readManifest = () => {
104
+ const parsed = JSON.parse(readFileSync(hfFixturePath(MANIFEST_FILE), 'utf8'));
105
+ if (!isRecord(parsed) || !isRecord(parsed.fixtures)) {
106
+ throw new Error(`${MANIFEST_FILE} declares no "fixtures" object`);
107
+ }
108
+ const { fixtures } = parsed;
109
+ const declared = Object.keys(fixtures).sort().join();
110
+ const expected = [...HF_FIXTURE_NAMES].sort().join();
111
+ if (declared !== expected) {
112
+ throw new Error(`${MANIFEST_FILE} declares [${declared}], expected [${expected}]`);
113
+ }
114
+ const entry = (name) => parseEntry(name, fixtures[name]);
115
+ // Spelled out rather than folded from `HF_FIXTURE_NAMES`, so the compiler
116
+ // checks the key set instead of a cast asserting it: adding a name to
117
+ // `HF_FIXTURE_NAMES` is a type error here until it is listed.
118
+ return {
119
+ 'state-v8.hex': entry('state-v8.hex'),
120
+ 'state-v8-v6-envelope.hex': entry('state-v8-v6-envelope.hex'),
121
+ 'state-migrated-v9.hex': entry('state-migrated-v9.hex'),
122
+ 'state-migrated-v9-merkle.hex': entry('state-migrated-v9-merkle.hex'),
123
+ 'state-tampered-keyset-v8to9.hex': entry('state-tampered-keyset-v8to9.hex'),
124
+ 'state-tampered-keyset-v9to8.hex': entry('state-tampered-keyset-v9to8.hex'),
125
+ 'state-tampered-bytes.hex': entry('state-tampered-bytes.hex'),
126
+ 'state-both-keys.hex': entry('state-both-keys.hex'),
127
+ 'state-co-v2-only-foreign.hex': entry('state-co-v2-only-foreign.hex')
128
+ };
129
+ };
130
+ /**
131
+ * The shipped `fixtures.json`, keyed by fixture name and validated on load, so
132
+ * a manifest that has drifted from {@link HF_FIXTURE_NAMES} fails at import
133
+ * rather than at the first lookup.
134
+ *
135
+ * Only the fields this package promises are exposed here. The full per-fixture
136
+ * provenance stays in the shipped manifest, reachable via
137
+ * `hfFixturePath('fixtures.json')`.
138
+ */
139
+ const hfFixturesManifest = readManifest();
140
+ /**
141
+ * Reads one hard-fork state fixture as raw bytes, ready to hand to a ledger's
142
+ * `ContractState.deserialize`.
143
+ *
144
+ * @param name One of {@link HF_FIXTURE_NAMES}.
145
+ * @returns The decoded fixture bytes.
146
+ * @throws If the name is not a shipped fixture, or its file is not whole hex —
147
+ * a truncated decode would look like a valid but different state.
148
+ */
149
+ const readHfFixture = (name) => {
150
+ if (!HF_FIXTURE_NAMES.includes(name)) {
151
+ throw new Error(`unknown hard-fork fixture: ${name} (expected one of ${HF_FIXTURE_NAMES.join(', ')})`);
152
+ }
153
+ const text = readFileSync(hfFixturePath(name), 'utf8').trim();
154
+ if (text.length === 0 || text.length % 2 !== 0 || !HEX_TEXT.test(text)) {
155
+ throw new Error(`hard-fork fixture ${name} is not whole lower-case hex`);
156
+ }
157
+ return Uint8Array.from(Buffer.from(text, 'hex'));
158
+ };
159
+
160
+ export { HF_FIXTURE_NAMES, HF_FIXTURE_STATUSES, hfFixturePath, hfFixturesManifest, readHfFixture };
161
+ //# sourceMappingURL=fixtures-hf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixtures-hf.js","sources":["../src/fixtures-hf.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;AAaG;AAEH;;;;;;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