Skip to content

Commit

Permalink
Added new tests to staking and utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Shloyem committed Feb 27, 2022
1 parent b4cc9a6 commit 633fc32
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
1 change: 0 additions & 1 deletion contracts/staking/BaseShareFieldV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ contract BaseShareFieldV2 {

/**
* @dev This function increase user's productivity and updates the global productivity.
* This function increase user's productivity and updates the global productivity.
* the users' actual share percentage will calculated by:
* Formula: user_productivity / global_productivity
* @param user the user to update
Expand Down
23 changes: 23 additions & 0 deletions test/staking/CompoundStakingFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from "chai";
import {
CERC20,
GoodCompoundStaking,
GoodCompoundStakingV2,
CompoundStakingFactory
} from "../../types";
import { createDAO, deployUniswap } from "../helpers";
Expand Down Expand Up @@ -106,4 +107,26 @@ describe("CompoundStakingFactory", () => {
expect(await staking.name()).to.equal("GoodCompoundStakingV2 Compound DAI");
expect(await staking.symbol()).to.equal("gcDAI");
});
it("should get exact gas cost for interest transfer", async () => {
const goodCompoundStakingV2 = (await ethers.getContractAt(
"GoodCompoundStakingV2",
await stakingFactory.impl()
)) as GoodCompoundStakingV2;

await goodCompoundStakingV2.init(
dai,
cdai,
dao.nameService.address,
"DAI",
"DAI",
5760,
stakingFactory.address,
compUsdOracle.address,
[]
);

const INITIAL_GAS_COST = 250000;
const gasCostForInterestTransfer = await goodCompoundStakingV2.getGasCostForInterestTransfer();
expect(gasCostForInterestTransfer).to.equal(INITIAL_GAS_COST);
});
});
37 changes: 36 additions & 1 deletion test/staking/GoodAaveStakingFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { default as hre, ethers, upgrades } from "hardhat";
import { deployMockContract, MockContract } from "ethereum-waffle";
import { expect } from "chai";
import { CERC20, GoodAaveStaking, AaveStakingFactory } from "../../types";
import { CERC20, GoodAaveStaking, GoodAaveStakingV2, AaveStakingFactory } from "../../types";
import { createDAO, deployUniswap } from "../helpers";
import { Contract } from "ethers";

Expand Down Expand Up @@ -122,4 +122,39 @@ describe("AaveStakingFactory", () => {
expect(await staking.name()).to.equal("GoodAaveStakingV2 USDC");
expect(await staking.symbol()).to.equal("gaUSDC");
});

it("should revert implementation on invalid initialization", async () => {
const goodAaveStakingV2 = (await ethers.getContractAt(
"GoodAaveStakingV2",
await stakingFactory.impl()
)) as GoodAaveStakingV2;
await expect(goodAaveStakingV2.init(
usdc.address,
lendingPool.address,
dao.nameService.address,
"USDC",
"USDC",
5760,
stakingFactory.address,
incentiveController.address,
aaveUsdOracle.address,
[cdai, dai] // violates tokenToDaiSwapPath[0] == _token (cdai != usdc)
)).to.be.revertedWith(
"invalid _tokenToDaiSwapPath"
);
await expect(goodAaveStakingV2.init(
usdc.address,
lendingPool.address,
dao.nameService.address,
"USDC",
"USDC",
5760,
stakingFactory.address,
incentiveController.address,
aaveUsdOracle.address,
[usdc.address, cdai] // violates _tokenToDaiSwapPath[] path leading to dai
)).to.be.revertedWith(
"invalid _tokenToDaiSwapPath"
);
});
});
17 changes: 17 additions & 0 deletions test/utils/ProxyFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,21 @@ describe("proxyfactory", () => {
proxy = await ethers.getContractAt("UpgradableMock", proxyAddr);
expect(await proxy.owner()).to.eq(signers[2].address);
});

it("should use deploy minimal to deploy proxy with impl and initialize it", async () => {
const c1 = await (
await ethers.getContractFactory("UpgradableMock")
).deploy();

const encoded = c1.interface.encodeFunctionData("initialize", [
signers[2].address
]);
const deployTX = await (
await factory.deployMinimal(c1.address, encoded)
).wait();
const proxyAddr = deployTX.events.find(_ => _.event === "ProxyCreated").args
.proxy;
proxy = await ethers.getContractAt("UpgradableMock", proxyAddr);
expect(await proxy.owner()).to.eq(signers[2].address);
});
});

0 comments on commit 633fc32

Please sign in to comment.