Skip to content

Commit

Permalink
hardhat test
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno committed Oct 19, 2023
1 parent 5f78a1b commit 86a5095
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion ethereum/contracts/state-transition/StateTransition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ contract StateTransition is IStateTransition, StateTransitionBase {

// construct init data
bytes memory initData;
bytes memory copiedData = _diamondCut.initCalldata[164:];
bytes memory copiedData = _diamondCut.initCalldata[196:];
initData = bytes.concat(
IDiamondInit.initialize.selector,
bytes32(_chainId),
bytes32(uint256(uint160(address(bridgehub)))),
bytes32(uint256(uint160(address(this)))),
bytes32(uint256(uint160(_governor))),
bytes32(uint256(uint160(_governor))),
bytes32(proofStorage.storedBatchZero),
copiedData
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pragma solidity ^0.8.13;
import "../../common/interfaces/IAllowList.sol";
import "../../common/libraries/Diamond.sol";
import "./facets/Base.sol";
import {L2_TX_MAX_GAS_LIMIT, L2_TO_L1_LOG_SERIALIZE_SIZE} from "../../common/Config.sol";
import {InitializeData } from "../chain-interfaces/IDiamondInit.sol";
import {L2_TX_MAX_GAS_LIMIT, L2_TO_L1_LOG_SERIALIZE_SIZE} from "../../common/Config.sol";
import {InitializeData} from "../chain-interfaces/IDiamondInit.sol";

/// @author Matter Labs
/// @dev The contract is used only once to initialize the diamond proxy.
Expand All @@ -19,7 +19,6 @@ contract DiamondInit is StateTransitionChainBase {
/// @return Magic 32 bytes, which indicates that the contract logic is expected to be used as a diamond proxy
/// initializer
function initialize(InitializeData calldata _initializeData) external reentrancyGuardInitializer returns (bytes32) {

require(address(_initializeData.verifier) != address(0), "vt");
require(_initializeData.governor != address(0), "vy");
require(_initializeData.admin != address(0), "hc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ contract AdminFacet is StateTransitionChainBase, IAdmin {
/// @notice Executes a proposed governor upgrade
/// @dev Only the current governor can execute the upgrade
/// @param _diamondCut The diamond cut parameters to be executed
function executeUpgrade(Diamond.DiamondCutData calldata _diamondCut, uint256 _latestProtocolVersion) external onlyStateTransition {
function executeUpgrade(Diamond.DiamondCutData calldata _diamondCut, uint256 _latestProtocolVersion)
external
onlyStateTransition
{
Diamond.diamondCut(_diamondCut);
if (chainStorage.protocolVersion == _latestProtocolVersion) {
chainStorage.upToDate = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface IAdmin is IStateTransitionChainBase {

function setPriorityTxMaxGasLimit(uint256 _newPriorityTxMaxGasLimit) external;

function executeUpgrade(Diamond.DiamondCutData calldata _diamondCut) external;
function executeUpgrade(Diamond.DiamondCutData calldata _diamondCut, uint256 _latestProtocolVersion) external;

function freezeNotUpdated(uint256 _protocolVersion) external;

Expand All @@ -36,7 +36,6 @@ interface IAdmin is IStateTransitionChainBase {

/// @notice Validator's status changed
event ValidatorStatusUpdate(address indexed validatorAddress, bool isActive);


/// @notice pendingGovernor is changed
/// @dev Also emitted when new governor is accepted and in this case, `newPendingGovernor` would be zero address
Expand Down
1 change: 1 addition & 0 deletions ethereum/src.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export class Deployer {
bridgehub: '0x0000000000000000000000000000000000001234',
stateTransition: '0x0000000000000000000000000000000000002234',
governor: '0x0000000000000000000000000000000000003234',
admin: '0x0000000000000000000000000000000000004234',
storedBatchZero: '0x0000000000000000000000000000000000000000000000000000000000000000',
allowList: this.addresses.AllowList,
verifier: this.addresses.StateTransition.Verifier,
Expand Down
11 changes: 8 additions & 3 deletions ethereum/test/unit_tests/diamond_proxy_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ describe('Diamond proxy tests', function () {
bridgehub: '0x0000000000000000000000000000000000000000',
stateTransition: await owner.getAddress(),
governor: governorAddress,
admin: governorAddress,
storedBatchZero: '0x02c775f0a90abf7a0e8043f2fdc38f0580ca9f9996a895d05a501bfeaa3b2e21',
allowList: '0x0000000000000000000000000000000000000000',
verifier: '0x0000000000000000000000000000000000000000',
verifier: '0x0000000000000000000000000000000000000001',
verifierParams: dummyVerifierParams,
l2BootloaderBytecodeHash: '0x0100000000000000000000000000000000000000000000000000000000000000',
l2DefaultAccountBytecodeHash: '0x0100000000000000000000000000000000000000000000000000000000000000',
Expand Down Expand Up @@ -137,7 +138,8 @@ describe('Diamond proxy tests', function () {
const diamondCutInitData = diamondCut([], diamondProxyTest.address, diamondProxyTestCalldata);

const adminFacetExecuteCalldata = adminFacet.interface.encodeFunctionData('executeUpgrade', [
diamondCutInitData
diamondCutInitData,
0
]);
await proxy.fallback({ data: adminFacetExecuteCalldata });

Expand All @@ -155,7 +157,10 @@ describe('Diamond proxy tests', function () {
];
const diamondCutData = diamondCut(facetCuts, ethers.constants.AddressZero, '0x');

const adminFacetExecuteCalldata = adminFacet.interface.encodeFunctionData('executeUpgrade', [diamondCutData]);
const adminFacetExecuteCalldata = adminFacet.interface.encodeFunctionData('executeUpgrade', [
diamondCutData,
0
]);
await proxy.fallback({ data: adminFacetExecuteCalldata });
});

Expand Down
18 changes: 10 additions & 8 deletions ethereum/test/unit_tests/l2-upgrade.test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import * as ethers from 'ethers';
import { BigNumberish, Wallet, BytesLike } from 'ethers';
import { REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT, hashBytecode } from 'zksync-web3/build/src/utils';

import { keccak256 } from 'ethers/lib/utils';

const L2_BOOTLOADER_BYTECODE_HASH = '0x1000100000000000000000000000000000000000000000000000000000000000';
const L2_DEFAULT_ACCOUNT_BYTECODE_HASH = '0x1001000000000000000000000000000000000000000000000000000000000000';

Expand Down Expand Up @@ -94,11 +96,11 @@ describe('L2 upgrade test', function () {

await (await proxyAdmin.setValidator(await deployWallet.getAddress(), true)).wait();

// let priorityOp = await proxyGetters.priorityQueueFrontOperation();
let priorityOp = await proxyGetters.priorityQueueFrontOperation();
// priorityOpTxHash = priorityOp[0];
// priorityOperationsHash = keccak256(
// ethers.utils.defaultAbiCoder.encode(['uint256', 'uint256'], [EMPTY_STRING_KECCAK, priorityOp[0]])
// );
priorityOperationsHash = keccak256(
ethers.utils.defaultAbiCoder.encode(['uint256', 'uint256'], [EMPTY_STRING_KECCAK, priorityOp[0]])
);
});

it('Upgrade should work even if not all blocks are processed', async () => {
Expand Down Expand Up @@ -916,8 +918,8 @@ async function executeUpgrade(
const diamondCutData = diamondCut([], diamondUpgradeInit.address, upgradeCalldata);

// This promise will be handled in the tests
(await stateTransition.setUpgradeDiamondCut(diamondCutData)).wait();
return stateTransition.upgradeChain(chainId, diamondCutData);
(await stateTransition.setUpgradeDiamondCut(diamondCutData, partialUpgrade.newProtocolVersion)).wait();
return stateTransition.upgradeChain(chainId, partialUpgrade.newProtocolVersion, diamondCutData);
}

async function executeCustomUpgrade(
Expand Down Expand Up @@ -945,8 +947,8 @@ async function executeCustomUpgrade(
const diamondCutData = diamondCut([], diamondUpgradeInit.address, upgradeCalldata);

// This promise will be handled in the tests
(await stateTransition.setUpgradeDiamondCut(diamondCutData)).wait();
return stateTransition.upgradeChain(chainId, diamondCutData);
(await stateTransition.setUpgradeDiamondCut(diamondCutData, partialUpgrade.newProtocolVersion)).wait();
return stateTransition.upgradeChain(chainId, partialUpgrade.newProtocolVersion, diamondCutData);
}

async function makeExecutedEqualCommitted(
Expand Down

0 comments on commit 86a5095

Please sign in to comment.