-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathread-write.test.mjs
More file actions
358 lines (329 loc) · 11.1 KB
/
read-write.test.mjs
File metadata and controls
358 lines (329 loc) · 11.1 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { runTutorial } from './run-tutorial.mjs';
import {
assertTutorialSuccess,
extractId,
extractKeyId,
} from './assertions.mjs';
// Accumulated state passed forward as env vars to dependent tutorials.
const state = {};
describe('Write tutorials (sequential)', { concurrency: 1 }, () => {
// -----------------------------------------------------------------------
// Phase 0: Address transfers (no identity needed)
// -----------------------------------------------------------------------
it('send-funds', { timeout: 120_000 }, async () => {
const result = await runTutorial('send-funds.mjs', { timeoutMs: 120_000 });
assertTutorialSuccess(result, {
name: 'send-funds',
expectedPatterns: ['Transaction broadcast!'],
errorPatterns: ['Something went wrong'],
});
});
// -----------------------------------------------------------------------
// Phase 1: Identity
// -----------------------------------------------------------------------
it('identity-register', { timeout: 180_000 }, async () => {
const result = await runTutorial(
'1-Identities-and-Names/identity-register.mjs',
{ timeoutMs: 180_000 },
);
// This tutorial has a known SDK bug workaround — it may extract the
// identity ID from an error message. Either path prints "Identity registered!".
assert.match(
result.stdout,
/Identity registered!/,
`Expected identity registration output.\nSTDOUT: ${result.stdout}\nSTDERR: ${result.stderr}`,
);
console.log(result.stdout);
});
it('identity-retrieve', { timeout: 120_000 }, async () => {
const result = await runTutorial(
'1-Identities-and-Names/identity-retrieve.mjs',
{ timeoutMs: 120_000 },
);
assertTutorialSuccess(result, {
name: 'identity-retrieve',
expectedPatterns: ['Identity retrieved:'],
errorPatterns: ['Something went wrong'],
});
});
it('identity-topup', { timeout: 120_000 }, async () => {
const result = await runTutorial(
'1-Identities-and-Names/identity-topup.mjs',
{ timeoutMs: 120_000 },
);
assertTutorialSuccess(result, {
name: 'identity-topup',
expectedPatterns: ['Top-up result:', 'Final balance:'],
errorPatterns: ['Something went wrong'],
});
});
it('identity-transfer-credits', { timeout: 120_000 }, async () => {
const result = await runTutorial(
'1-Identities-and-Names/identity-transfer-credits.mjs',
{ timeoutMs: 120_000 },
);
assertTutorialSuccess(result, {
name: 'identity-transfer-credits',
expectedPatterns: ['balance after transfer:'],
errorPatterns: ['Something went wrong'],
});
});
it('identity-withdraw-credits', { timeout: 120_000 }, async () => {
const result = await runTutorial(
'1-Identities-and-Names/identity-withdraw-credits.mjs',
{ timeoutMs: 120_000 },
);
assertTutorialSuccess(result, {
name: 'identity-withdraw-credits',
expectedPatterns: ['balance after withdrawal:'],
errorPatterns: ['Something went wrong'],
});
});
it('identity-update-add-key', { timeout: 120_000 }, async () => {
const result = await runTutorial(
'1-Identities-and-Names/identity-update-add-key.mjs',
{ timeoutMs: 120_000 },
);
assertTutorialSuccess(result, {
name: 'identity-update-add-key',
expectedPatterns: ['Identity updated:'],
errorPatterns: ['Something went wrong'],
});
const keyId = extractKeyId(result.stdout);
assert.ok(keyId, `Failed to extract key ID from stdout:\n${result.stdout}`);
state.addedKeyId = keyId;
});
it('identity-update-disable-key', { timeout: 120_000 }, async (ctx) => {
if (!state.addedKeyId) {
ctx.skip('No KEY_ID (identity-update-add-key must pass first)');
return;
}
const result = await runTutorial(
'1-Identities-and-Names/identity-update-disable-key.mjs',
{
env: { DISABLE_KEY_ID: state.addedKeyId },
timeoutMs: 120_000,
},
);
assertTutorialSuccess(result, {
name: 'identity-update-disable-key',
expectedPatterns: ['Identity updated:'],
errorPatterns: ['Something went wrong'],
});
});
it('name-register', { timeout: 120_000 }, async () => {
const label = `test-${Date.now()}-${Math.random()
.toString(36)
.slice(2, 6)}`;
const result = await runTutorial(
'1-Identities-and-Names/name-register.mjs',
{
env: { NAME_LABEL: label },
timeoutMs: 120_000,
},
);
assertTutorialSuccess(result, {
name: 'name-register',
expectedPatterns: ['Name registered:'],
errorPatterns: ['Something went wrong', 'already registered'],
});
});
// -----------------------------------------------------------------------
// Phase 2: Contracts
// -----------------------------------------------------------------------
it('contract-register-minimal', { timeout: 180_000 }, async () => {
const result = await runTutorial(
'2-Contracts-and-Documents/contract-register-minimal.mjs',
{ timeoutMs: 180_000 },
);
assertTutorialSuccess(result, {
name: 'contract-register-minimal',
expectedPatterns: ['Contract registered:'],
errorPatterns: ['Something went wrong'],
});
const id = extractId(result.stdout);
assert.ok(
id,
`Failed to extract contract ID from stdout:\n${result.stdout}`,
);
state.dataContractId = id;
});
it('contract-register-indexed', { timeout: 180_000 }, async () => {
const result = await runTutorial(
'2-Contracts-and-Documents/contract-register-indexed.mjs',
{ timeoutMs: 180_000 },
);
assertTutorialSuccess(result, {
name: 'contract-register-indexed',
expectedPatterns: ['Contract registered:'],
errorPatterns: ['Something went wrong'],
});
});
it('contract-register-binary', { timeout: 180_000 }, async () => {
const result = await runTutorial(
'2-Contracts-and-Documents/contract-register-binary.mjs',
{ timeoutMs: 180_000 },
);
assertTutorialSuccess(result, {
name: 'contract-register-binary',
expectedPatterns: ['Contract registered:'],
errorPatterns: ['Something went wrong'],
});
});
it('contract-register-timestamps', { timeout: 180_000 }, async () => {
const result = await runTutorial(
'2-Contracts-and-Documents/contract-register-timestamps.mjs',
{ timeoutMs: 180_000 },
);
assertTutorialSuccess(result, {
name: 'contract-register-timestamps',
expectedPatterns: ['Contract registered:'],
errorPatterns: ['Something went wrong'],
});
});
it('contract-register-history', { timeout: 180_000 }, async () => {
const result = await runTutorial(
'2-Contracts-and-Documents/contract-register-history.mjs',
{ timeoutMs: 180_000 },
);
assertTutorialSuccess(result, {
name: 'contract-register-history',
expectedPatterns: ['Contract registered:'],
errorPatterns: ['Something went wrong'],
});
const id = extractId(result.stdout);
assert.ok(
id,
`Failed to extract history contract ID from stdout:\n${result.stdout}`,
);
state.historyContractId = id;
});
it('contract-register-nft', { timeout: 180_000 }, async () => {
const result = await runTutorial(
'2-Contracts-and-Documents/contract-register-nft.mjs',
{ timeoutMs: 180_000 },
);
assertTutorialSuccess(result, {
name: 'contract-register-nft',
expectedPatterns: ['Contract registered:'],
errorPatterns: ['Something went wrong'],
});
});
it('contract-update-minimal', { timeout: 120_000 }, async (ctx) => {
if (!state.dataContractId) {
ctx.skip(
'No DATA_CONTRACT_ID (contract-register-minimal must pass first)',
);
return;
}
const result = await runTutorial(
'2-Contracts-and-Documents/contract-update-minimal.mjs',
{
env: { DATA_CONTRACT_ID: state.dataContractId },
timeoutMs: 120_000,
},
);
assertTutorialSuccess(result, {
name: 'contract-update-minimal',
expectedPatterns: ['Contract updated:'],
errorPatterns: ['Something went wrong'],
});
});
it('contract-update-history', { timeout: 120_000 }, async (ctx) => {
if (!state.historyContractId) {
ctx.skip(
'No DATA_CONTRACT_ID (contract-register-history must pass first)',
);
return;
}
const result = await runTutorial(
'2-Contracts-and-Documents/contract-update-history.mjs',
{
env: { DATA_CONTRACT_ID: state.historyContractId },
timeoutMs: 120_000,
},
);
assertTutorialSuccess(result, {
name: 'contract-update-history',
expectedPatterns: ['Contract updated:'],
errorPatterns: ['Something went wrong'],
});
});
// -----------------------------------------------------------------------
// Phase 3: Documents (depend on contract from Phase 2)
// -----------------------------------------------------------------------
it('document-submit', { timeout: 120_000 }, async (ctx) => {
if (!state.dataContractId) {
ctx.skip(
'No DATA_CONTRACT_ID (contract-register-minimal must pass first)',
);
return;
}
const result = await runTutorial(
'2-Contracts-and-Documents/document-submit.mjs',
{
env: { DATA_CONTRACT_ID: state.dataContractId },
timeoutMs: 120_000,
},
);
assertTutorialSuccess(result, {
name: 'document-submit',
expectedPatterns: ['Document submitted:'],
errorPatterns: ['Something went wrong'],
});
const docId = extractId(result.stdout);
assert.ok(
docId,
`Failed to extract document ID from stdout:\n${result.stdout}`,
);
state.documentId = docId;
});
it('document-update', { timeout: 120_000 }, async (ctx) => {
if (!state.dataContractId || !state.documentId) {
ctx.skip(
'No DATA_CONTRACT_ID or DOCUMENT_ID (earlier tests must pass first)',
);
return;
}
const result = await runTutorial(
'2-Contracts-and-Documents/document-update.mjs',
{
env: {
DATA_CONTRACT_ID: state.dataContractId,
DOCUMENT_ID: state.documentId,
},
timeoutMs: 120_000,
},
);
assertTutorialSuccess(result, {
name: 'document-update',
expectedPatterns: ['Document updated:'],
errorPatterns: ['Something went wrong'],
});
});
it('document-delete', { timeout: 120_000 }, async (ctx) => {
if (!state.dataContractId || !state.documentId) {
ctx.skip(
'No DATA_CONTRACT_ID or DOCUMENT_ID (earlier tests must pass first)',
);
return;
}
const result = await runTutorial(
'2-Contracts-and-Documents/document-delete.mjs',
{
env: {
DATA_CONTRACT_ID: state.dataContractId,
DOCUMENT_ID: state.documentId,
},
timeoutMs: 120_000,
},
);
assertTutorialSuccess(result, {
name: 'document-delete',
expectedPatterns: ['Document deleted successfully'],
errorPatterns: ['Something went wrong'],
});
});
});