Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(fast-usdc): bundle size under 1MB RPC limit #10902

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/fast-usdc/test/bundle-size.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
import { Buffer } from 'buffer';
import { createRequire } from 'module';
import { promisify } from 'util';
import { gzip } from 'zlib';

const nodeRequire = createRequire(import.meta.url);

const MB = 1024 * 1024;

const bundleName = 'fast-usdc';
const entryModule = nodeRequire.resolve('../src/fast-usdc.contract.js');
const optSmall = { elideComments: true } as const;

const compressText = async (fileContents: string) => {
const buffer = Buffer.from(fileContents, 'utf-8');
const compressed = await promisify(gzip)(buffer);
return compressed;
};

test('fast-usdc.contract.js bundle meets 1MB request limit', async t => {
const bundleCache = await makeNodeBundleCache('bundles', {}, s => import(s));

const bundle = await bundleCache.load(
entryModule,
'fast-usdc',
undefined,
optSmall,
);
const uncompressed = JSON.stringify(bundle);
const compressed = await compressText(uncompressed);

t.assert(compressed);
const sizeInMb = compressed.length / MB;
t.log({
bundleName,
compressedSize: `${sizeInMb.toFixed(3)} MB`,
originallySize: `${(JSON.stringify(bundle).length / MB).toFixed(3)} MB`,
});
// JSON RPC hex encoding doubles the size
t.assert(sizeInMb * 2 < 1, 'Compressed bundle is less than 0.5MB');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's take this opportunity to create a more general solution that can be used in other packages, even off repo.

e.g. an Ava macro,

import test from 'ava';
import { bundleSizeLimit } from '@agoric/boot';

const bundleName = 'fast-usdc';
const entryModule = nodeRequire.resolve('../src/fast-usdc.contract.js');

test(bundleSizeLimit, entryModule);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the test call is so small at that point it could go in the existing test/fast-usdc.contract.test.ts.

});
Loading