-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9ef4fc
commit 7603c08
Showing
28 changed files
with
462 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ystemcontract.sol/systemcontracterrors.go → ...mcontractmock.sol/systemcontracterrors.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
482 changes: 241 additions & 241 deletions
482
...ksystemcontract.sol/mocksystemcontract.go → ...temcontractmock.sol/systemcontractmock.go
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...contracts/zevm/connectorzevm.sol/wzeta.go → ...racts/zevm/zetaconnectorzevm.sol/wzeta.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 5 additions & 5 deletions
10
...vm/connectorzevm.sol/zetaconnectorzevm.go → ...etaconnectorzevm.sol/zetaconnectorzevm.go
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../zevm/connectorzevm.sol/zetainterfaces.go → ...m/zetaconnectorzevm.sol/zetainterfaces.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; | ||
import { WETH9, ZetaConnectorZEVM } from "@typechain-types"; | ||
import { expect } from "chai"; | ||
import exp from "constants"; | ||
import { parseEther } from "ethers/lib/utils"; | ||
import { ethers } from "hardhat"; | ||
|
||
import { FUNGIBLE_MODULE_ADDRESS } from "./test.helpers"; | ||
|
||
const hre = require("hardhat"); | ||
|
||
describe("ConnectorZEVM tests", () => { | ||
let zetaTokenContract: WETH9; | ||
let zetaConnectorZEVM: ZetaConnectorZEVM; | ||
|
||
let owner: SignerWithAddress; | ||
let fungibleModuleSigner: SignerWithAddress; | ||
let addrs: SignerWithAddress[]; | ||
let randomSigner: SignerWithAddress; | ||
|
||
beforeEach(async () => { | ||
[owner, randomSigner, ...addrs] = await ethers.getSigners(); | ||
|
||
// Impersonate the fungible module account | ||
await hre.network.provider.request({ | ||
method: "hardhat_impersonateAccount", | ||
params: [FUNGIBLE_MODULE_ADDRESS], | ||
}); | ||
|
||
// Get a signer for the fungible module account | ||
fungibleModuleSigner = await ethers.getSigner(FUNGIBLE_MODULE_ADDRESS); | ||
hre.network.provider.send("hardhat_setBalance", [FUNGIBLE_MODULE_ADDRESS, parseEther("1000000").toHexString()]); | ||
|
||
const WZETAFactory = await ethers.getContractFactory("contracts/zevm/WZETA.sol:WETH9"); | ||
zetaTokenContract = (await WZETAFactory.deploy()) as WETH9; | ||
|
||
const ZetaConnectorZEVMFactory = await ethers.getContractFactory("ZetaConnectorZEVM"); | ||
zetaConnectorZEVM = (await ZetaConnectorZEVMFactory.connect(owner).deploy( | ||
zetaTokenContract.address | ||
)) as ZetaConnectorZEVM; | ||
}); | ||
|
||
describe("ZetaConnectorZEVM", () => { | ||
it("Should revert if the zetaTxSender has no enough zeta", async () => { | ||
await zetaTokenContract.connect(randomSigner).approve(zetaConnectorZEVM.address, 100_000); | ||
|
||
const tx = zetaConnectorZEVM.connect(randomSigner).send({ | ||
destinationAddress: randomSigner.address, | ||
destinationChainId: 1, | ||
destinationGasLimit: 2500000, | ||
message: new ethers.utils.AbiCoder().encode(["string"], ["hello"]), | ||
zetaParams: new ethers.utils.AbiCoder().encode(["string"], ["hello"]), | ||
zetaValueAndGas: 1000, | ||
}); | ||
|
||
// @dev: As we use the standard WETH contract, there's no error message for not enough balance | ||
await expect(tx).to.be.reverted; | ||
}); | ||
|
||
it("Should revert if the zetaTxSender didn't allow ZetaConnector to spend Zeta token", async () => { | ||
await zetaTokenContract.deposit({ value: 100_000 }); | ||
await zetaTokenContract.transfer(randomSigner.address, 100_000); | ||
|
||
const balance = await zetaTokenContract.balanceOf(randomSigner.address); | ||
expect(balance.toString()).to.equal("100000"); | ||
|
||
const tx = zetaConnectorZEVM.send({ | ||
destinationAddress: randomSigner.address, | ||
destinationChainId: 1, | ||
destinationGasLimit: 2500000, | ||
message: new ethers.utils.AbiCoder().encode(["string"], ["hello"]), | ||
zetaParams: new ethers.utils.AbiCoder().encode(["string"], ["hello"]), | ||
zetaValueAndGas: 1000, | ||
}); | ||
|
||
// @dev: As we use the standard WETH contract, there's no error message for not enough balance | ||
await expect(tx).to.be.reverted; | ||
|
||
await zetaTokenContract.connect(randomSigner).transfer(owner.address, balance); | ||
}); | ||
|
||
it("Should emit `ZetaSent` on success", async () => { | ||
const tx = await zetaConnectorZEVM.send({ | ||
destinationAddress: randomSigner.address, | ||
destinationChainId: 1, | ||
destinationGasLimit: 2500000, | ||
message: new ethers.utils.AbiCoder().encode(["string"], ["hello"]), | ||
zetaParams: new ethers.utils.AbiCoder().encode(["string"], ["hello"]), | ||
zetaValueAndGas: 0, | ||
}); | ||
|
||
expect(tx) | ||
.to.emit(zetaConnectorZEVM, "ZetaSent") | ||
.withArgs(owner.address, owner.address, 1, randomSigner.address, 0, 2500000, "hello", "hello"); | ||
}); | ||
|
||
it("Should transfer value and gas to fungible address", async () => { | ||
const zetaValueAndGas = 1000; | ||
await zetaTokenContract.approve(zetaConnectorZEVM.address, zetaValueAndGas); | ||
await zetaTokenContract.deposit({ value: zetaValueAndGas }); | ||
|
||
const balanceBefore = await ethers.provider.getBalance(fungibleModuleSigner.address); | ||
|
||
await zetaConnectorZEVM.send({ | ||
destinationAddress: randomSigner.address, | ||
destinationChainId: 1, | ||
destinationGasLimit: 2500000, | ||
message: new ethers.utils.AbiCoder().encode(["string"], ["hello"]), | ||
zetaParams: new ethers.utils.AbiCoder().encode(["string"], ["hello"]), | ||
zetaValueAndGas, | ||
}); | ||
|
||
const balanceAfter = await ethers.provider.getBalance(fungibleModuleSigner.address); | ||
expect(balanceAfter.sub(balanceBefore)).to.equal(zetaValueAndGas); | ||
}); | ||
|
||
it("Should update wzeta address if is call from fungible address", async () => { | ||
const WZETAFactory = await ethers.getContractFactory("contracts/zevm/WZETA.sol:WETH9"); | ||
const newZetaTokenContract = (await WZETAFactory.deploy()) as WETH9; | ||
|
||
const tx = zetaConnectorZEVM.connect(fungibleModuleSigner).setWzetaAddress(newZetaTokenContract.address); | ||
await expect(tx).to.emit(zetaConnectorZEVM, "SetWZETA").withArgs(newZetaTokenContract.address); | ||
|
||
expect(await zetaConnectorZEVM.wzeta()).to.equal(newZetaTokenContract.address); | ||
}); | ||
|
||
it("Should revert if try to update wzeta address from other address", async () => { | ||
const WZETAFactory = await ethers.getContractFactory("contracts/zevm/WZETA.sol:WETH9"); | ||
const newZetaTokenContract = (await WZETAFactory.deploy()) as WETH9; | ||
|
||
const tx = zetaConnectorZEVM.setWzetaAddress(newZetaTokenContract.address); | ||
await expect(tx).to.be.revertedWith("OnlyFungibleModule"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m/testing/MockSystemContract.sol/index.ts → ...m/testing/SystemContractMock.sol/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* Autogenerated file. Do not edit manually. */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export type { MockSystemContract } from "./MockSystemContract"; | ||
export type { SystemContractErrors } from "./SystemContractErrors"; | ||
export type { SystemContractMock } from "./SystemContractMock"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* Autogenerated file. Do not edit manually. */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import type * as mockSystemContractSol from "./MockSystemContract.sol"; | ||
export type { mockSystemContractSol }; | ||
import type * as systemContractMockSol from "./SystemContractMock.sol"; | ||
export type { systemContractMockSol }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.