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

added e2e test #13

Merged
merged 7 commits into from
May 31, 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
99 changes: 99 additions & 0 deletions test/v2/core/e2e.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const {ethers} = require("hardhat");
const {expect} = require("chai");
const {parseEther} = require("ethers/lib/utils");

describe("e2e test", () => {
let sgEth, deployer, alice, multiSig;
let MINTER_ROLE;

beforeEach(async () => {
const [owner, addr1, addr2] = await ethers.getSigners();

const SgETH = await ethers.getContractFactory("SgETH");
sgEth = await SgETH.deploy([]);
await sgEth.deployed();

deployer = owner;
alice = addr1;
multiSig = addr2;

MINTER_ROLE = await sgEth.MINTER();

// deploy sgeth
const WSGETH = await ethers.getContractFactory("WSGETH");
const wsgETH = await WSGETH.deploy(sgEth.address, 24 * 60 * 60);
await wsgETH.deployed();

const splitterAddresses = [deployer.address, multiSig.address, wsgETH.address];
const splitterValues = [6, 3, 31];

const PaymentSplitter = await ethers.getContractFactory("PaymentSplitter");
const paymentSplitter = await PaymentSplitter.deploy(splitterAddresses, splitterValues);
await paymentSplitter.deployed();

const rolloverVirtual = "1080000000000000000";
const vETH2Addr = "0x898bad2774eb97cf6b94605677f43b41871410b1";

const Withdrawals = await ethers.getContractFactory("Withdrawals");
const withdrawals = await Withdrawals.deploy(vETH2Addr, rolloverVirtual);
await withdrawals.deployed();

const numValidators = 1000;
const adminFee = 0;

const addresses = [
paymentSplitter.address, // fee splitter
sgEth.address, // sgETH address
wsgETH.address, // wsgETH address
multiSig.address, // government address
ethers.constants.AddressZero, // deposit contract address - can't find deposit contract - using dummy address
];

// add secondary minter contract / eoa
const Minter = await ethers.getContractFactory("SharedDepositMinterV2");
const minter = await Minter.deploy(numValidators, adminFee, addresses);
await minter.deployed();

const RewardsReceiver = await ethers.getContractFactory("RewardsReceiver");
const rewardsReceiver = await RewardsReceiver.deploy(withdrawals.address, [
sgEth.address,
wsgETH.address,
paymentSplitter.address,
minter.address,
]);
await rewardsReceiver.deployed();
});

it("e2e test", async () => {
// deployer can't mint
await expect(sgEth.connect(deployer).mint(deployer.address, parseEther("1"))).to.be.revertedWith(
`AccessControl: account ${deployer.address.toLowerCase()} is missing role ${MINTER_ROLE}`,
);
// no one can't mint
await expect(sgEth.connect(alice).mint(alice.address, parseEther("1"))).to.be.revertedWith(
`AccessControl: account ${alice.address.toLowerCase()} is missing role ${MINTER_ROLE}`,
);
// add minter
await expect(sgEth.connect(deployer).addMinter(deployer.address))
.to.be.emit(sgEth, "RoleGranted")
.withArgs(MINTER_ROLE, deployer.address, deployer.address);
// minter can mint
await expect(sgEth.connect(deployer).mint(deployer.address, parseEther("1")))
.to.be.emit(sgEth, "Transfer")
.withArgs(ethers.constants.AddressZero, deployer.address, parseEther("1"));

await sgEth.removeMinter(deployer.address);
// add secondary owner
// revoke deployer admin rights
await expect(sgEth.transferOwnership(multiSig.address))
.to.be.emit(sgEth, "RoleGranted")
.withArgs(ethers.constants.HashZero, multiSig.address, deployer.address)
.and.to.be.emit(sgEth, "RoleRevoked")
.withArgs(ethers.constants.HashZero, deployer.address, deployer.address);

// check auth invariants are preserved. i.e ex owner and outsiders cannot interact with the contract
await expect(sgEth.connect(deployer).transferOwnership(alice.address)).to.be.revertedWith(
`AccessControl: account ${deployer.address.toLowerCase()} is missing role ${ethers.constants.HashZero}`,
);
});
});
6 changes: 4 additions & 2 deletions test/v2/core/sgETH.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
const {ethers} = require("hardhat");
const {expect} = require("chai");
const {parseEther} = require("ethers/lib/utils");

describe("SgETH.sol", () => {
let sgEth, deployer, alice;
let sgEth, deployer, alice, multiSig;
let MINTER_ROLE;

beforeEach(async () => {
const [owner, addr1] = await ethers.getSigners();
const [owner, addr1, addr2] = await ethers.getSigners();

const SgETH = await ethers.getContractFactory("SgETH");
sgEth = await SgETH.deploy([]);
await sgEth.deployed();

deployer = owner;
alice = addr1;
multiSig = addr2;

MINTER_ROLE = await sgEth.MINTER();
});
Expand Down
Loading