Skip to content

Commit

Permalink
test: ensure compressed bundle size is less than 1MB
Browse files Browse the repository at this point in the history
closes #36
  • Loading branch information
0xpatrickdev committed Jan 25, 2024
1 parent 9aae653 commit 4566b43
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 39 deletions.
1 change: 0 additions & 1 deletion contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsdoc": "^46.4.3",
"eslint-plugin-prettier": "^5.0.0",
"execa": "^8.0.1",
"import-meta-resolve": "^2.2.1",
"prettier": "^3.0.3",
"prettier-plugin-jsdoc": "^1.0.0",
Expand Down
26 changes: 14 additions & 12 deletions contract/test/test-build-proposal.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
/* eslint-disable import/order -- https://github.com/endojs/endo/issues/1235 */
import { test } from './prepare-test-env-ava.js';
import { execa } from 'execa';
import { promises as fs } from 'fs';
import { execSync } from 'node:child_process';
import { promises as fs } from 'node:fs';
import { makeCompressFile } from './utils.js';

test('proposal builder generates bundles less than 5MB', async t => {
const { stdout } = await execa('agoric', [
'run',
'scripts/build-contract-deployer.js',
]);
test.before(t => (t.context.compressFile = makeCompressFile(fs.readFile)));

test.only('proposal builder generates compressed bundles less than 1MB', async t => {
const stdout = execSync('agoric run scripts/build-contract-deployer.js',{ encoding: 'utf8' });
t.log('agoric run stdout:', stdout);
t.truthy(stdout, 'Proposal successfully bundled.');

const regex = /agd tx swingset install-bundle @(.*?)\.json/g;
const bundles = Array.from(stdout.matchAll(regex), m => `${m[1]}.json`);
t.assert(bundles.length, 'Found bundles in stdout');

for (const bundle of bundles) {
const { size } = await fs.stat(bundle);
t.assert(size);
const sizeInMb = size / (1024 * 1024);
t.assert(sizeInMb < 5, `Bundle ${bundle} is less than 5MB`);
// eslint-disable-next-line @jessie.js/safe-await-separator
const buffer = await t.context.compressFile(bundle);
t.assert(buffer);
const sizeInMb = buffer.length / (1024 * 1024);
t.assert(sizeInMb < 1, 'Compressed bundle is less than 1MB');
t.log({
bundleId: bundle.split('cache/')[1].split('.json')[0],
fileSize: `${sizeInMb} MB`,
compressedSize: `${sizeInMb} MB`,
});
}
});
15 changes: 15 additions & 0 deletions contract/test/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { gzip } from 'zlib';
import { promisify } from 'util';
import { Buffer } from 'buffer';

/**
* @typedef {import('fs').promises['readFile']} PromisifiedFSReadFile
*/

/** @param {PromisifiedFSReadFile} readFile */
export const makeCompressFile = readFile => async filePath => {
const fileContents = await readFile(filePath, 'utf8');
const buffer = Buffer.from(fileContents, 'utf-8');
const compressed = await promisify(gzip)(buffer);
return compressed;
};
27 changes: 1 addition & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3791,21 +3791,6 @@ execa@^7.1.1:
signal-exit "^3.0.7"
strip-final-newline "^3.0.0"

execa@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/execa/-/execa-8.0.1.tgz#51f6a5943b580f963c3ca9c6321796db8cc39b8c"
integrity sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==
dependencies:
cross-spawn "^7.0.3"
get-stream "^8.0.1"
human-signals "^5.0.0"
is-stream "^3.0.0"
merge-stream "^2.0.0"
npm-run-path "^5.1.0"
onetime "^6.0.0"
signal-exit "^4.1.0"
strip-final-newline "^3.0.0"

expand-template@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/expand-template/-/expand-template-2.0.3.tgz#6e14b3fcee0f3a6340ecb57d2e8918692052a47c"
Expand Down Expand Up @@ -4016,11 +4001,6 @@ get-stream@^6.0.0, get-stream@^6.0.1:
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7"
integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==

get-stream@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-8.0.1.tgz#def9dfd71742cd7754a7761ed43749a27d02eca2"
integrity sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==

get-symbol-description@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/get-symbol-description/-/get-symbol-description-1.0.0.tgz#7fdb81c900101fbd564dd5f1a30af5aadc1e58d6"
Expand Down Expand Up @@ -4192,11 +4172,6 @@ human-signals@^4.3.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-4.3.1.tgz#ab7f811e851fca97ffbd2c1fe9a958964de321b2"
integrity sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==

human-signals@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-5.0.0.tgz#42665a284f9ae0dade3ba41ebc37eb4b852f3a28"
integrity sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==

iconv-lite@^0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
Expand Down Expand Up @@ -6107,7 +6082,7 @@ signal-exit@^3.0.2, signal-exit@^3.0.3, signal-exit@^3.0.7:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==

signal-exit@^4.0.1, signal-exit@^4.1.0:
signal-exit@^4.0.1:
version "4.1.0"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.1.0.tgz#952188c1cbd546070e2dd20d0f41c0ae0530cb04"
integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==
Expand Down

0 comments on commit 4566b43

Please sign in to comment.