Skip to content

Commit

Permalink
test: add validation in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-waite committed Jun 7, 2022
1 parent df11f93 commit 00c4f6d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
30 changes: 2 additions & 28 deletions proposals/dao/tokemak_withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,8 @@ const teardown: TeardownUpgradeFunc = async (addresses, oldContracts, contracts,
// Run any validations required on the fip using mocha or console logging
// IE check balances, check state of contracts, etc.
const validate: ValidateUpgradeFunc = async (addresses, oldContracts, contracts, logging) => {
const ethTokemakPCVDeposit = contracts.ethTokemakPCVDeposit;

// Validate that DAO can withdraw funds in the next cycle
// impersonate the rollover signer, and make the Tokemak pool go to next cycle
await forceEth(addresses.tokemakManagerRollover);
const tokemakRolloverSigner = await getImpersonatedSigner(addresses.tokemakManagerRollover);
const tokemakManagerAbi = [
'function nextCycleStartTime() view returns (uint256)',
'function completeRollover(string calldata rewardsIpfsHash)'
];
const tokemakManager = new ethers.Contract(addresses.tokemakManager, tokemakManagerAbi, tokemakRolloverSigner);
const cycleEnd = await tokemakManager.nextCycleStartTime();
await time.increaseTo(cycleEnd + 1);
await tokemakManager.completeRollover(IPFS_JSON_FILE_HASH);

// Perform withdraw
await ethTokemakPCVDeposit.withdraw(ethTokemakPCVDeposit.address, ethers.constants.WeiPerEther.mul(10_000));

// Should end with 0 tWETH, 10k ETH
expect((await contracts.tWETH.balanceOf(ethTokemakPCVDeposit.address)).toString()).to.be.equal(
ethers.utils.parseEther('0')
);
expect((await ethers.provider.getBalance(ethTokemakPCVDeposit.address)).toString()).to.be.equal(
ethers.utils.parseEther('10000')
);

// Then re-deposit, to clean up state for e2e tests
await ethTokemakPCVDeposit.deposit();
console.log(`No actions to complete in validate for fip${fipNumber}`);
// Validation performed in e2e test
};

export { deploy, setup, teardown, validate };
48 changes: 41 additions & 7 deletions test/integration/tests/fip-38-tokemak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,56 @@ describe('e2e-fip-38-tokemak', function () {
doLogging && console.log(`Environment loaded.`);
});

it('should have deposited ETH, and be able to withdraw', async function () {
it('should be able to withdraw ETH', async function () {
const {
ethTokemakPCVDeposit,
tWETH // Tokemak ETH reactor
} = contracts;

// we should start with 10k tWETH, 0 ETH
expect((await tWETH.balanceOf(ethTokemakPCVDeposit.address)).toString()).to.be.equal(
// impersonate the rollover signer, and make the Tokemak pool go to next cycle
await forceEth(TOKEMAK_MANAGER_ROLLOVER_ADDRESS);
const tokemakRolloverSigner = await getImpersonatedSigner(TOKEMAK_MANAGER_ROLLOVER_ADDRESS);
const tokemakManagerAbi = [
'function nextCycleStartTime() view returns (uint256)',
'function completeRollover(string calldata rewardsIpfsHash)'
];
const tokemakManager = new ethers.Contract(TOKEMAK_MANAGER_ADDRESS, tokemakManagerAbi, tokemakRolloverSigner);
const cycleEnd = await tokemakManager.nextCycleStartTime();
await time.increaseTo(cycleEnd + 1);
await tokemakManager.completeRollover(IPFS_JSON_FILE_HASH);

// Perform withdraw
await ethTokemakPCVDeposit.withdraw(ethTokemakPCVDeposit.address, tenPow18.mul(toBN(10_000)));

// Should end with 0 tWETH, 10k ETH
expect((await tWETH.balanceOf(ethTokemakPCVDeposit.address)).toString()).to.be.equal(ethers.utils.parseEther('0'));
expect((await ethers.provider.getBalance(ethTokemakPCVDeposit.address)).toString()).to.be.equal(
ethers.utils.parseEther('10000')
);
});

it('should be able to deposit and then withdraw ETH', async function () {
const {
ethTokemakPCVDeposit,
tWETH // Tokemak ETH reactor
} = contracts;

// Starting state: 10k tETH, 0 WETH
// Want to transfer ETH, and deposit. Then verify deposit and then withdraw
const ethWhaleSigner = await getImpersonatedSigner('0x73BCEb1Cd57C711feaC4224D062b0F6ff338501e');
await ethWhaleSigner.sendTransaction({ to: ethTokemakPCVDeposit.address, value: ethers.utils.parseEther('10000') });
await ethTokemakPCVDeposit.deposit();

// Now has 20k tETH, 0k WETH
expect((await tWETH.balanceOf(ethTokemakPCVDeposit.address)).toString()).to.be.equal(
ethers.utils.parseEther('20000')
);
expect((await ethers.provider.getBalance(ethTokemakPCVDeposit.address)).toString()).to.be.equal(
ethers.utils.parseEther('0')
);

// request to withdraw 10k ETH
await ethTokemakPCVDeposit.requestWithdrawal(tenPow18.mul(toBN(10_000)));
// request to withdraw 20k ETH
await ethTokemakPCVDeposit.requestWithdrawal(tenPow18.mul(toBN(20_000)));

// impersonate the rollover signer, and make the Tokemak pool go to next cycle
await forceEth(TOKEMAK_MANAGER_ROLLOVER_ADDRESS);
Expand All @@ -76,12 +110,12 @@ describe('e2e-fip-38-tokemak', function () {
await tokemakManager.completeRollover(IPFS_JSON_FILE_HASH);

// Perform withdraw
await ethTokemakPCVDeposit.withdraw(ethTokemakPCVDeposit.address, tenPow18.mul(toBN(10_000)));
await ethTokemakPCVDeposit.withdraw(ethTokemakPCVDeposit.address, tenPow18.mul(toBN(20_000)));

// Should end with 0 tWETH, 10k ETH
expect((await tWETH.balanceOf(ethTokemakPCVDeposit.address)).toString()).to.be.equal(ethers.utils.parseEther('0'));
expect((await ethers.provider.getBalance(ethTokemakPCVDeposit.address)).toString()).to.be.equal(
ethers.utils.parseEther('10000')
ethers.utils.parseEther('20000')
);
});
});

0 comments on commit 00c4f6d

Please sign in to comment.