Skip to content

Commit

Permalink
hardhat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno committed Oct 18, 2023
1 parent 508bcb1 commit 0ba1518
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 446 deletions.
18 changes: 9 additions & 9 deletions ethereum/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ CHAIN_ETH_NETWORK=localhost
CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT=72000000
CONTRACTS_DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT=10000000
ETH_CLIENT_WEB3_URL=http://127.0.0.1:8545
CONTRACTS_BRIDGEHEAD_DIAMOND_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHEAD_DIAMOND_INIT_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHEAD_MAILBOX_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHEAD_REGISTRY_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHEAD_ADMIN_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHEAD_GETTERS_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHEAD_CHAIN_IMPL_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADMIN_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_DIAMOND_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_DIAMOND_INIT_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_MAILBOX_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_REGISTRY_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_ADMIN_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_GETTERS_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_CHAIN_IMPL_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADMIN_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_PROOF_SYSTEM_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_PROOF_SYSTEM_IMPL_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_PROOF_SYSTEM_PROXY_ADMIN_ADDR=0x0000000000000000000000000000000000000000
Expand Down
10 changes: 3 additions & 7 deletions ethereum/contracts/state-transition/StateTransition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ contract StateTransition is IStateTransition, StateTransitionBase {
return proofStorage.governor;
}


function getBridgehub() external view returns (address) {
return proofStorage.bridgehub;
}
Expand Down Expand Up @@ -106,10 +105,7 @@ contract StateTransition is IStateTransition, StateTransitionBase {
cutData.initCalldata = initData;

// deploy proofChainContract
DiamondProxy proofChainContract = new DiamondProxy(
block.chainid,
cutData
);
DiamondProxy proofChainContract = new DiamondProxy(block.chainid, cutData);

// save data
address proofChainAddress = address(proofChainContract);
Expand All @@ -123,10 +119,10 @@ contract StateTransition is IStateTransition, StateTransitionBase {
// set chainId in VM
_specialSetChainIdInVMTx(_chainId, proofChainAddress);

emit NewStateTransitionChain(_chainId, proofChainAddress);
emit StateTransitionNewChain(_chainId, proofChainAddress);
}

function setUpgradeDiamondCutWithProposedUpgrade(Diamond.DiamondCutData calldata _cutData) external onlyGovernor {
function setUpgradeDiamondCut(Diamond.DiamondCutData calldata _cutData) external onlyGovernor {
proofStorage.upgradeCutHash = keccak256(abi.encode(_cutData));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ interface IStateTransitionRegistry {
) external;

// when a new Chain is added
event NewStateTransitionChain(uint256 indexed _chainId, address indexed _proofChainContract);
event StateTransitionNewChain(uint256 indexed _chainId, address indexed _proofChainContract);
}
1 change: 0 additions & 1 deletion ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"initialize-bridges": "ts-node scripts/initialize-bridges.ts",
"initialize-allow-list": "ts-node scripts/initialize-l1-allow-list.ts",
"initialize-validator": "ts-node scripts/initialize-validator.ts",
"initialize-verifier-params": "ts-node scripts/initialize-verifier-params.ts",
"initialize-governance": "ts-node scripts/initialize-governance.ts",
"upgrade-1": "ts-node scripts/upgrades/upgrade-1.ts",
"upgrade-2": "ts-node scripts/upgrades/upgrade-2.ts",
Expand Down
2 changes: 1 addition & 1 deletion ethereum/scripts/initialize-bridges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function initializeBridges(
gasPrice: ethers.BigNumber,
cmdErc20Bridge: string
) {
const bridgehub = IBridgehubFactory.connect(process.env.CONTRACTS_BRIDGEHEAD_DIAMOND_PROXY_ADDR, deployWallet);
const bridgehub = IBridgehubFactory.connect(process.env.CONTRACTS_BRIDGEHUB_DIAMOND_PROXY_ADDR, deployWallet);
const nonce = await deployWallet.getTransactionCount();

const erc20Bridge = cmdErc20Bridge
Expand Down
66 changes: 0 additions & 66 deletions ethereum/scripts/initialize-verifier-params.ts

This file was deleted.

2 changes: 1 addition & 1 deletion ethereum/scripts/upgrades/upgrade-4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async function main() {
ownerAddress: ZERO_ADDRESS,
verbose: true
});
const zkSyncContract = deployer.proofSystemContract(deployWallet);
const zkSyncContract = deployer.stateTransitionContract(deployWallet);

// Get address of the diamond init contract
const diamondUpgradeAddress = cmd.diamondUpgradeAddress;
Expand Down
56 changes: 28 additions & 28 deletions ethereum/src.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ export interface DeployerConfig {
export function deployedAddressesFromEnv(): DeployedAddresses {
return {
Bridgehub: {
BridgehubAdminFacet: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_ADMIN_FACET_ADDR'),
BridgehubGettersFacet: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_GETTERS_FACET_ADDR'),
BridgehubMailboxFacet: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_MAILBOX_FACET_ADDR'),
BridgehubRegistryFacet: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_REGISTRY_FACET_ADDR'),
BridgehubDiamondInit: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_DIAMOND_INIT_ADDR'),
BridgehubDiamondProxy: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_DIAMOND_PROXY_ADDR'),
ChainImplementation: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_CHAIN_IMPL_ADDR'),
ChainProxy: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADDR'),
ChainProxyAdmin: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADMIN_ADDR')
BridgehubAdminFacet: getAddressFromEnv('CONTRACTS_BRIDGEHUB_ADMIN_FACET_ADDR'),
BridgehubGettersFacet: getAddressFromEnv('CONTRACTS_BRIDGEHUB_GETTERS_FACET_ADDR'),
BridgehubMailboxFacet: getAddressFromEnv('CONTRACTS_BRIDGEHUB_MAILBOX_FACET_ADDR'),
BridgehubRegistryFacet: getAddressFromEnv('CONTRACTS_BRIDGEHUB_REGISTRY_FACET_ADDR'),
BridgehubDiamondInit: getAddressFromEnv('CONTRACTS_BRIDGEHUB_DIAMOND_INIT_ADDR'),
BridgehubDiamondProxy: getAddressFromEnv('CONTRACTS_BRIDGEHUB_DIAMOND_PROXY_ADDR'),
ChainImplementation: getAddressFromEnv('CONTRACTS_BRIDGEHUB_CHAIN_IMPL_ADDR'),
ChainProxy: getAddressFromEnv('CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADDR'),
ChainProxyAdmin: getAddressFromEnv('CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADMIN_ADDR')
},
StateTransition: {
StateTransitionProxy: getAddressFromEnv('CONTRACTS_PROOF_SYSTEM_PROXY_ADDR'),
Expand Down Expand Up @@ -139,7 +139,7 @@ export class Deployer {
this.ownerAddress = config.ownerAddress != null ? config.ownerAddress : this.deployWallet.address;
}

public async initialProofChainDiamondCut(extraFacets?: FacetCut[]) {
public async initialStateTransitionChainDiamondCut(extraFacets?: FacetCut[]) {
let facetCuts: FacetCut[] = Object.values(
await getCurrentFacetCutsForAdd(
this.addresses.StateTransition.AdminFacet,
Expand All @@ -163,7 +163,7 @@ export class Deployer {
{
chainId: '0x0000000000000000000000000000000000000000000000000000000000000000',
bridgehub: '0x0000000000000000000000000000000000001234',
proofSystem: '0x0000000000000000000000000000000000002234',
stateTransition: '0x0000000000000000000000000000000000002234',
governor: '0x0000000000000000000000000000000000003234',
storedBatchZero: '0x0000000000000000000000000000000000000000000000000000000000000000',
allowList: this.addresses.AllowList,
Expand Down Expand Up @@ -291,13 +291,13 @@ export class Deployer {
const implAddress = await hardhat.upgrades.erc1967.getImplementationAddress(instance.address);

if (this.verbose) {
console.log(`CONTRACTS_BRIDGEHEAD_CHAIN_IMPL_ADDR=${implAddress}`);
console.log(`CONTRACTS_BRIDGEHUB_CHAIN_IMPL_ADDR=${implAddress}`);
}

this.addresses.Bridgehub.ChainImplementation = implAddress;

if (this.verbose) {
console.log(`CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADMIN_ADDR=${adminAddress}`);
console.log(`CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADMIN_ADDR=${adminAddress}`);
}

if (this.verbose) {
Expand All @@ -315,7 +315,7 @@ export class Deployer {
const contractAddress = await this.deployViaCreate2('BridgehubAdminFacet', [], create2Salt, ethTxOptions);

if (this.verbose) {
console.log(`CONTRACTS_BRIDGEHEAD_ADMIN_FACET_ADDR=${contractAddress}`);
console.log(`CONTRACTS_BRIDGEHUB_ADMIN_FACET_ADDR=${contractAddress}`);
}

this.addresses.Bridgehub.BridgehubAdminFacet = contractAddress;
Expand All @@ -326,7 +326,7 @@ export class Deployer {
const contractAddress = await this.deployViaCreate2('BridgehubGettersFacet', [], create2Salt, ethTxOptions);

if (this.verbose) {
console.log(`CONTRACTS_BRIDGEHEAD_GETTERS_FACET_ADDR=${contractAddress}`);
console.log(`CONTRACTS_BRIDGEHUB_GETTERS_FACET_ADDR=${contractAddress}`);
}

this.addresses.Bridgehub.BridgehubGettersFacet = contractAddress;
Expand All @@ -337,7 +337,7 @@ export class Deployer {
const contractAddress = await this.deployViaCreate2('BridgehubMailboxFacet', [], create2Salt, ethTxOptions);

if (this.verbose) {
console.log(`CONTRACTS_BRIDGEHEAD_MAILBOX_FACET_ADDR=${contractAddress}`);
console.log(`CONTRACTS_BRIDGEHUB_MAILBOX_FACET_ADDR=${contractAddress}`);
}

this.addresses.Bridgehub.BridgehubMailboxFacet = contractAddress;
Expand All @@ -348,7 +348,7 @@ export class Deployer {
const contractAddress = await this.deployViaCreate2('BridgehubRegistryFacet', [], create2Salt, ethTxOptions);

if (this.verbose) {
console.log(`CONTRACTS_BRIDGEHEAD_REGISTRY_FACET_ADDR=${contractAddress}`);
console.log(`CONTRACTS_BRIDGEHUB_REGISTRY_FACET_ADDR=${contractAddress}`);
}

this.addresses.Bridgehub.BridgehubRegistryFacet = contractAddress;
Expand All @@ -358,7 +358,7 @@ export class Deployer {
const contractAddress = await this.deployViaCreate2('BridgehubDiamondInit', [], create2Salt, ethTxOptions);

if (this.verbose) {
console.log(`CONTRACTS_BRIDGEHEAD_DIAMOND_INIT_ADDR=${contractAddress}`);
console.log(`CONTRACTS_BRIDGEHUB_DIAMOND_INIT_ADDR=${contractAddress}`);
}

this.addresses.Bridgehub.BridgehubDiamondInit = contractAddress;
Expand All @@ -373,7 +373,7 @@ export class Deployer {
const genesisRollupLeafIndex = getNumberFromEnv('CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX');
const genesisBlockCommitment = getHashFromEnv('CONTRACTS_GENESIS_BLOCK_COMMITMENT');
const priorityTxMaxGasLimit = getNumberFromEnv('CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT');
const diamondCut = (await this.initialProofChainDiamondCut(extraFacets))
const diamondCut = (await this.initialStateTransitionChainDiamondCut(extraFacets))

const instance = await hardhat.upgrades.deployProxy(StateTransition, [
{
Expand Down Expand Up @@ -608,19 +608,19 @@ export class Deployer {
// const adminAddress = await hardhat.upgrades.erc1967.getAdminAddress(instance.address);

// if (this.verbose) {
// console.log(`CONTRACTS_BRIDGEHEAD_IMPL_ADDR=${implAddress}`);
// console.log(`CONTRACTS_BRIDGEHUB_IMPL_ADDR=${implAddress}`);
// }

// this.addresses.Bridgehub.BridgehubImplementation = implAddress;

// if (this.verbose) {
// console.log(`CONTRACTS_BRIDGEHEAD_PROXY_ADDR=${instance.address}`);
// console.log(`CONTRACTS_BRIDGEHUB_PROXY_ADDR=${instance.address}`);
// }

// this.addresses.Bridgehub.BridgehubDiamondProxy = instance.address;

// if (this.verbose) {
// console.log(`CONTRACTS_BRIDGEHEAD_PROXY_ADMIN_ADDR=${adminAddress}`);
// console.log(`CONTRACTS_BRIDGEHUB_PROXY_ADMIN_ADDR=${adminAddress}`);
// }

// if (this.verbose) {
Expand All @@ -644,7 +644,7 @@ export class Deployer {
);

if (this.verbose) {
console.log(`CONTRACTS_BRIDGEHEAD_DIAMOND_PROXY_ADDR=${contractAddress}`);
console.log(`CONTRACTS_BRIDGEHUB_DIAMOND_PROXY_ADDR=${contractAddress}`);
}

this.addresses.Bridgehub.BridgehubDiamondProxy = contractAddress;
Expand Down Expand Up @@ -706,12 +706,12 @@ export class Deployer {
nonce = nonce ? parseInt(nonce) : await this.deployWallet.getTransactionCount();

const bridgehub = this.bridgehubContract(this.deployWallet);
const proofSystem = this.proofSystemContract(this.deployWallet);
const stateTransition = this.stateTransitionContract(this.deployWallet);

// const inputChainId = getNumberFromEnv("CHAIN_ETH_ZKSYNC_NETWORK_ID");
const inputChainId = 0;
const governor = this.ownerAddress;
const initialDiamondCut = await this.initialProofChainDiamondCut(extraFacets);
const initialDiamondCut = await this.initialStateTransitionChainDiamondCut(extraFacets);

const tx = await bridgehub.newChain(
inputChainId,
Expand All @@ -723,7 +723,7 @@ export class Deployer {
.topics[1];

nonce ++;
const tx2 = await proofSystem.newChain(
const tx2 = await stateTransition.newChain(
chainId,
governor,
initialDiamondCut,
Expand All @@ -733,7 +733,7 @@ export class Deployer {
const proofContractAddress =
'0x' +
receipt2.logs
.find((log) => log.topics[0] == proofSystem.interface.getEventTopic('NewProofChain'))
.find((log) => log.topics[0] == stateTransition.interface.getEventTopic('StateTransitionNewChain'))
.topics[2].slice(26);

this.addresses.StateTransition.DiamondProxy = proofContractAddress;
Expand Down Expand Up @@ -800,7 +800,7 @@ export class Deployer {
return IBridgehubFactory.connect(this.addresses.Bridgehub.BridgehubDiamondProxy, signerOrProvider);
}

public proofSystemContract(signerOrProvider: Signer | providers.Provider) {
public stateTransitionContract(signerOrProvider: Signer | providers.Provider) {
return IStateTransitionFactory.connect(this.addresses.StateTransition.StateTransitionProxy, signerOrProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ contract NewChainTest is RegistryTest {
assertEq(eventStateTransition, stateTransitionAddress, "NewChain.stateTransition is wrong");

// === Storage checks ===
assertEq(bridgehub.getChainStateTransition(chainId), stateTransitionAddress, "saved chainStateTransition is wrong");
assertEq(
bridgehub.getChainStateTransition(chainId),
stateTransitionAddress,
"saved chainStateTransition is wrong"
);
assertEq(bridgehub.getTotalChains(), 1, "saved totalChains is wrong");
assertEq(bridgehub.getChainContract(chainId), chainContractAddress, "saved chainContract address is wrong");
assertEq(resChainId, chainId, "returned chainId is wrong");
Expand Down Expand Up @@ -242,7 +246,11 @@ contract NewChainTest is RegistryTest {
assertEq(eventStateTransition, stateTransitionAddress, "NewChain.stateTransition is wrong");

// === Storage checks ===
assertEq(bridgehub.getChainStateTransition(chainId), stateTransitionAddress, "saved chainStateTransition is wrong");
assertEq(
bridgehub.getChainStateTransition(chainId),
stateTransitionAddress,
"saved chainStateTransition is wrong"
);
assertEq(bridgehub.getTotalChains(), 1, "saved totalChains is wrong");
assertEq(bridgehub.getChainContract(chainId), chainContractAddress, "saved chainContract address is wrong");
assertEq(resChainId, chainId, "returned chainId is wrong");
Expand Down
Loading

0 comments on commit 0ba1518

Please sign in to comment.