-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap.selective-artifacts.test.ts
More file actions
322 lines (294 loc) · 9.03 KB
/
bootstrap.selective-artifacts.test.ts
File metadata and controls
322 lines (294 loc) · 9.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
import { ARTIFACT_DEFAULTS } from "../../../constants/artifact-defaults.ts";
import {
type ArtifactFilter,
DEFAULT_ARTIFACT_FILTER,
} from "./bootstrap.artifacts-filter.ts";
import type { OutputPayload } from "./bootstrap.output.ts";
import { outputResult } from "./bootstrap.output.ts";
let output = "";
let originalWrite: typeof process.stdout.write;
beforeEach(() => {
originalWrite = process.stdout.write;
output = "";
process.stdout.write = ((chunk: string | Uint8Array) => {
output += chunk.toString();
return true;
}) as typeof process.stdout.write;
});
afterEach(() => {
process.stdout.write = originalWrite;
});
afterEach(() => {
process.stdout.write = originalWrite;
});
const createSamplePayload = (filter: ArtifactFilter): OutputPayload => ({
faucet: {
address: "0x1111111111111111111111111111111111111111",
publicKey: "0xaaa",
privateKey: "0xbbb",
enode: "enode://publickey@host:30303",
},
genesis: {
config: {
chainId: 1,
homesteadBlock: 0,
eip150Block: 0,
eip150Hash: "0x0",
eip155Block: 0,
eip158Block: 0,
byzantiumBlock: 0,
constantinopleBlock: 0,
petersburgBlock: 0,
istanbulBlock: 0,
londonBlock: 0,
berlinBlock: 0,
muirGlacierBlock: 0,
shanghaiTime: 0,
cancunTime: 0,
zeroBaseFee: false,
qbft: {
blockperiodseconds: 5,
epochlength: 30_000,
xemptyblockperiodseconds: 30_000,
requesttimeoutseconds: 10,
},
},
nonce: "0x0",
timestamp: "0x0",
gasLimit: "0x1",
difficulty: "0x1",
mixHash: "0x0",
coinbase: "0x0",
alloc: {
"0x1111111111111111111111111111111111111111": {
balance: "0x1000000000000000000",
},
},
extraData: "",
},
validators: [
{
index: 1,
address: "0x2222222222222222222222222222222222222222",
publicKey: "0xccc",
privateKey: "0xddd",
enode: "enode://validator1@host:30303",
},
],
staticNodes: ["enode://validator1@host:30303"],
artifactNames: {
faucetPrefix: "faucet",
validatorPrefix: "besu-node-validator",
genesisConfigMapName: "genesis",
staticNodesConfigMapName: "static-nodes",
subgraphConfigMapName: ARTIFACT_DEFAULTS.subgraphConfigMapName,
},
abiArtifacts: [
{
configMapName: "abi-sample",
fileName: "Sample.json",
contents: JSON.stringify({ contractName: "Sample" }, null, 2),
},
],
subgraphHash: "QmSampleHash",
artifactFilter: filter,
});
describe("Selective artifact generation - screen output", () => {
test("includes genesis when genesis filter is enabled", async () => {
output = "";
const filter: ArtifactFilter = {
genesis: true,
keys: false,
abis: false,
subgraph: false,
allocations: false,
};
await outputResult("screen", createSamplePayload(filter));
expect(output).toContain("Genesis");
expect(output).not.toContain("Validator Nodes");
expect(output).not.toContain("Faucet Account");
});
test("includes keys when keys filter is enabled", async () => {
output = "";
const filter: ArtifactFilter = {
genesis: false,
keys: true,
abis: false,
subgraph: false,
allocations: false,
};
await outputResult("screen", createSamplePayload(filter));
expect(output).toContain("Validator Nodes");
expect(output).toContain("Faucet Account");
expect(output).not.toContain("Genesis");
});
test("excludes static nodes when keys filter is disabled", async () => {
output = "";
const filter: ArtifactFilter = {
genesis: false,
keys: false,
abis: false,
subgraph: false,
allocations: false,
};
await outputResult("screen", createSamplePayload(filter));
expect(output).not.toContain("Static Nodes");
});
test("includes static nodes when keys filter is enabled", async () => {
output = "";
const filter: ArtifactFilter = {
genesis: false,
keys: true,
abis: false,
subgraph: false,
allocations: false,
};
await outputResult("screen", createSamplePayload(filter));
expect(output).toContain("Static Nodes");
});
test("generates all artifacts when all filters are enabled", async () => {
output = "";
const filter = DEFAULT_ARTIFACT_FILTER;
await outputResult("screen", createSamplePayload(filter));
expect(output).toContain("Genesis");
expect(output).toContain("Validator Nodes");
expect(output).toContain("Faucet Account");
expect(output).toContain("Static Nodes");
});
});
describe("Selective artifact generation - file output", () => {
test("only writes genesis files when genesis filter is enabled", async () => {
const filter: ArtifactFilter = {
genesis: true,
keys: false,
abis: false,
subgraph: false,
allocations: false,
};
output = "";
const payload = createSamplePayload(filter);
// Note: We're testing the output side effect (console logs)
// File operations would require filesystem mocking
await outputResult("file", payload);
// Should log about genesis but not keys
expect(output).toContain("genesis.json");
expect(output).not.toContain("private-key");
});
test("only writes key files when keys filter is enabled", async () => {
const filter: ArtifactFilter = {
genesis: false,
keys: true,
abis: false,
subgraph: false,
allocations: false,
};
output = "";
const payload = createSamplePayload(filter);
await outputResult("file", payload);
// Should log about keys but not genesis
expect(output).toContain("private-key");
expect(output).not.toContain("genesis.json");
});
test("only writes abi files when abis filter is enabled", async () => {
const filter: ArtifactFilter = {
genesis: false,
keys: false,
abis: true,
subgraph: false,
allocations: false,
};
output = "";
const payload = createSamplePayload(filter);
await outputResult("file", payload);
// Should log about ABIs
expect(output).toContain("abi-sample");
});
test("only writes subgraph files when subgraph filter is enabled", async () => {
const filter: ArtifactFilter = {
genesis: false,
keys: false,
abis: false,
subgraph: true,
allocations: false,
};
output = "";
const payload = createSamplePayload(filter);
await outputResult("file", payload);
// Should log about subgraph
expect(output).toContain("besu-subgraph");
});
test("skips static nodes file when keys filter is disabled", async () => {
const filter: ArtifactFilter = {
genesis: false,
keys: false,
abis: false,
subgraph: false,
allocations: false,
};
output = "";
const payload = createSamplePayload(filter);
await outputResult("file", payload);
// Should not log about static nodes when keys are disabled
expect(output).not.toContain("static-nodes");
});
test("writes static nodes file when keys filter is enabled", async () => {
const filter: ArtifactFilter = {
genesis: false,
keys: true,
abis: false,
subgraph: false,
allocations: false,
};
output = "";
const payload = createSamplePayload(filter);
await outputResult("file", payload);
// Should log about static nodes when keys are enabled
expect(output).toContain("static-nodes");
});
});
describe("Selective artifact generation - use cases", () => {
test("generates only config without private keys for safe upgrades", () => {
const filter: ArtifactFilter = {
genesis: true,
keys: false,
abis: true,
subgraph: true,
allocations: true,
};
const payload = createSamplePayload(filter);
// Verify the filter has the expected configuration
expect(payload.artifactFilter.genesis).toBe(true);
expect(payload.artifactFilter.keys).toBe(false);
expect(payload.artifactFilter.abis).toBe(true);
expect(payload.artifactFilter.subgraph).toBe(true);
expect(payload.artifactFilter.allocations).toBe(true);
});
test("generates only subgraph and allocations for dApp deployments", () => {
const filter: ArtifactFilter = {
genesis: false,
keys: false,
abis: false,
subgraph: true,
allocations: true,
};
const payload = createSamplePayload(filter);
expect(payload.artifactFilter.subgraph).toBe(true);
expect(payload.artifactFilter.allocations).toBe(true);
expect(payload.artifactFilter.genesis).toBe(false);
expect(payload.artifactFilter.keys).toBe(false);
});
test("generates only ABIs for smart contract interactions", () => {
const filter: ArtifactFilter = {
genesis: false,
keys: false,
abis: true,
subgraph: false,
allocations: false,
};
const payload = createSamplePayload(filter);
expect(payload.artifactFilter.abis).toBe(true);
expect(payload.artifactFilter.genesis).toBe(false);
expect(payload.artifactFilter.keys).toBe(false);
});
});