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

fix(builder): package length check #1114

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/builder/src/package.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CannonStorage } from './';
import { IPFSLoader } from './loader';
import { InMemoryRegistry } from './registry';
import { PackageReference, publishPackage } from './package';
import { InMemoryRegistry } from './registry';
import { DeploymentInfo } from './types';
import { CannonStorage } from '.';

jest.mock('./loader');

Expand All @@ -27,7 +27,7 @@ describe('package.ts', () => {
expect(ref).toHaveProperty('fullPackageRef', fullPackageRef);
});

test.each([['a'], ['aa'], ['-aa'], ['some_package'], ['super-long-package-invalid-namee']])(
test.each([['a'], ['aa'], ['-aa'], ['some_package'], ['super-long-package-invalid-nameee']])(
'throws an error with "%s"',
(packageRef) => {
expect(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface PackagePublishCall {
export class PackageReference {
static DEFAULT_TAG = 'latest';
static DEFAULT_PRESET = 'main';
static PACKAGE_REGEX = /^(?<name>@?[a-z0-9][A-Za-z0-9-]{1,29}[a-z0-9])(?::(?<version>[^@]+))?(@(?<preset>[^\s]+))?$/;
static PACKAGE_REGEX = /^(?<name>@?[a-z0-9][A-Za-z0-9-]{1,30}[a-z0-9])(?::(?<version>[^@]+))?(@(?<preset>[^\s]+))?$/;

/**
* Anything before the colon or an @ (if no version is present) is the package name.
Expand Down
12 changes: 11 additions & 1 deletion packages/registry/test/contracts/CannonRegistry.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { deepEqual, equal, ok } from 'assert/strict';
import { BigNumber, ContractTransaction, Signer } from 'ethers';
import { ethers } from 'hardhat';
import { stringToHex } from 'viem';
import { CannonRegistry as TCannonRegistry } from '../../typechain-types/contracts/CannonRegistry';
import { MockOptimismBridge as TMockOptimismBridge } from '../../typechain-types/contracts/MockOptimismBridge';
import assertRevert from '../helpers/assert-revert';

const toBytes32 = ethers.utils.formatBytes32String;
const toBytes32 = (str: string) => stringToHex(str, { size: 32 });
const parseEther = ethers.utils.parseEther;

describe('CannonRegistry', function () {
Expand Down Expand Up @@ -100,6 +101,15 @@ describe('CannonRegistry', function () {
equal(await CannonRegistry.validatePackageName(toBytes32(testName.slice(0, minLength))), true);
equal(await CannonRegistry.validatePackageName(toBytes32(testName.slice(0, minLength - 1))), false);
});

it('it validates package names of 32 characters directly', async function () {
equal(
await CannonRegistry.validatePackageName('0x692D646F6E742D636F6E7461696E2D612D6E756C6C2D7465726D696E61746F72'),
true
);

equal(await CannonRegistry.validatePackageName(toBytes32('i-dont-contain-a-null-terminator')), true);
});
});

describe('setPackageOwnership()', () => {
Expand Down
Loading