Skip to content

Commit

Permalink
Feat/94 emit version updated event (#98)
Browse files Browse the repository at this point in the history
* Emit LineaRollupVersionChanged on upgrade

* make padded hex bytes generic
  • Loading branch information
thedarkjester authored Sep 25, 2024
1 parent 5777e29 commit 346ce2a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
5 changes: 4 additions & 1 deletion contracts/contracts/LineaRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ contract LineaRollup is
* @param _unpauseTypeRoles The list of unpause type roles.
* @param _gatewayOperator The address of the gateway operator.
*/
function reinitializePauseTypesAndPermissions(
function reinitializeLineaRollupV6(
RoleAddress[] calldata _roleAddresses,
PauseTypeRole[] calldata _pauseTypeRoles,
PauseTypeRole[] calldata _unpauseTypeRoles,
Expand All @@ -134,6 +134,9 @@ contract LineaRollup is
__Permissions_init(_roleAddresses);
__PauseManager_init(_pauseTypeRoles, _unpauseTypeRoles);
gatewayOperator = _gatewayOperator;

/// @dev using the constants requires string memory and more complex code.
emit LineaRollupVersionChanged(bytes8("5.0"), bytes8("6.0"));
}

/**
Expand Down
8 changes: 8 additions & 0 deletions contracts/contracts/interfaces/l1/ILineaRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ interface ILineaRollup {
bytes l2MessagingBlocksOffsets;
}

/**
* @notice Emitted when the LineaRollup contract version has changed.
* @dev All bytes8 values are string based SemVer in the format M.m - e.g. "6.0";
* @param previousVersion The previous version.
* @param newVersion The new version.
*/
event LineaRollupVersionChanged(bytes8 indexed previousVersion, bytes8 indexed newVersion);

/**
* @notice Emitted when the gateway operator role is granted.
* @param caller The address that granted the role.
Expand Down
20 changes: 12 additions & 8 deletions contracts/test/LineaRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
generateBlobDataSubmission,
generateBlobParentShnarfData,
ShnarfDataGenerator,
convertStringToPaddedHexBytes,
} from "./utils/helpers";
import { CalldataSubmissionData } from "./utils/types";
import aggregatedProof1To81 from "./testData/compressedData/multipleProofs/aggregatedProof-1-81.json";
Expand Down Expand Up @@ -2244,7 +2245,7 @@ describe("Linea Rollup contract", () => {
const NewLineaRollupFactory = await ethers.getContractFactory("contracts/LineaRollup.sol:LineaRollup");
const newLineaRollup = await upgrades.upgradeProxy(lineaRollup, NewLineaRollupFactory);

await newLineaRollup.reinitializePauseTypesAndPermissions(
const upgradeCall = newLineaRollup.reinitializeLineaRollupV6(
[
{ addressWithRole: securityCouncil.address, role: DEFAULT_ADMIN_ROLE },
{ addressWithRole: securityCouncil.address, role: VERIFIER_SETTER_ROLE },
Expand All @@ -2254,10 +2255,18 @@ describe("Linea Rollup contract", () => {
multiCallAddress,
);

const expectedVersion5Bytes8 = convertStringToPaddedHexBytes("5.0", 8);
const expectedVersion6Bytes8 = convertStringToPaddedHexBytes("6.0", 8);

await expectEvent(newLineaRollup, upgradeCall, "LineaRollupVersionChanged", [
expectedVersion5Bytes8,
expectedVersion6Bytes8,
]);

expect(await newLineaRollup.currentL2BlockNumber()).to.equal(0);
});

it("Should revert with ZeroAddressNotAllowed when addressWithRole is zero address in reinitializePauseTypesAndPermissions", async () => {
it("Should revert with ZeroAddressNotAllowed when addressWithRole is zero address in reinitializeLineaRollupV6", async () => {
// Deploy new implementation
const NewLineaRollupFactory = await ethers.getContractFactory("contracts/LineaRollup.sol:LineaRollup");
const newLineaRollup = await upgrades.upgradeProxy(lineaRollup, NewLineaRollupFactory);
Expand All @@ -2270,12 +2279,7 @@ describe("Linea Rollup contract", () => {

await expectRevertWithCustomError(
newLineaRollup,
newLineaRollup.reinitializePauseTypesAndPermissions(
roleAddresses,
pauseTypeRoles,
unpauseTypeRoles,
multiCallAddress,
),
newLineaRollup.reinitializeLineaRollupV6(roleAddresses, pauseTypeRoles, unpauseTypeRoles, multiCallAddress),
"ZeroAddressNotAllowed",
);
});
Expand Down
12 changes: 12 additions & 0 deletions contracts/test/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,15 @@ export async function expectEvent(contract: any, asyncCall: Promise<any>, eventN
.to.emit(contract, eventName)
.withArgs(...eventArgs);
}

export function convertStringToPaddedHexBytes(strVal: string, paddedSize: number): string {
if (strVal.length > paddedSize) {
throw "Length is longer than padded size!";
}

const strBytes = ethers.toUtf8Bytes(strVal);
const bytes = ethers.zeroPadBytes(strBytes, paddedSize);
const bytes8Hex = ethers.hexlify(bytes);

return bytes8Hex;
}

0 comments on commit 346ce2a

Please sign in to comment.