Skip to content

Commit

Permalink
fix(contract): check constructor addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Jul 7, 2021
1 parent a151fe4 commit a99e3a4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 20 deletions.
1 change: 0 additions & 1 deletion contracts/ISushiBar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ interface ISushiBar {
function totalSupply() external view returns (uint256);

function balanceOf(address account) external view returns (uint256);

}
13 changes: 10 additions & 3 deletions contracts/SushiYieldSource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.6.12;

import { IYieldSource } from "@pooltogether/yield-source-interface/contracts/IYieldSource.sol";
import "@pooltogether/yield-source-interface/contracts/IYieldSource.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";

import "./ISushiBar.sol";
Expand All @@ -11,7 +11,6 @@ import "./ISushi.sol";
/// @title A pooltogether yield source for sushi token
/// @author Steffel Fenix
contract SushiYieldSource is IYieldSource {

using SafeMath for uint256;

ISushiBar public immutable sushiBar;
Expand All @@ -20,6 +19,15 @@ contract SushiYieldSource is IYieldSource {
mapping(address => uint256) public balances;

constructor(ISushiBar _sushiBar, ISushi _sushiAddr) public {
require(
address(_sushiBar) != address(0),
"SushiYieldSource/sushiBar-not-zero-address"
);
require(
address(_sushiAddr) != address(0),
"SushiYieldSource/sushiAddr-not-zero-address"
);

sushiBar = _sushiBar;
sushiAddr = _sushiAddr;
}
Expand Down Expand Up @@ -90,5 +98,4 @@ contract SushiYieldSource is IYieldSource {

return (sushiBalanceDiff);
}

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"hardhat-typechain": "^0.3.5",
"prettier": "^2.2.1",
"prettier-plugin-solidity": "^1.0.0-beta.6",
"solidity-coverage": "^0.7.16",
"solidity-coverage": "0.7.16",
"ts-generator": "^0.1.1",
"ts-node": "^9.1.1",
"typechain": "^4.0.3",
Expand Down
14 changes: 7 additions & 7 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,35 @@ async function getYieldSourcePrizePoolProxy(tx) {
}

async function run() {
console.log("running fork script")
console.log("running fork script");

await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [SUSHI_HOLDER],
});

const SUSHI_TOKEN_ADDRESS = "0x6B3595068778DD592e39A122f4f5a5cF09C90fE2"
const XSUSHI_ADDRESS = "0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272"
const SUSHI_TOKEN_ADDRESS = "0x6B3595068778DD592e39A122f4f5a5cF09C90fE2";
const XSUSHI_ADDRESS = "0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272";

const sushiHolder = await ethers.provider.getUncheckedSigner(SUSHI_HOLDER);
const sushi = await ethers.getContractAt(
"IERC20Upgradeable",
SUSHI_TOKEN_ADDRESS,
sushiHolder
);
console.log("getting builder")
console.log("getting builder");
const builder = await ethers.getContractAt(
"PoolWithMultipleWinnersBuilder",
"0x39E2F33ff4Ad3491106B3BB15dc66EbE24e4E9C7"
);
console.log("deploying")
console.log("deploying");
SushiYieldSourceFactory = await ethers.getContractFactory("SushiYieldSource");
sushiYieldSource = await SushiYieldSourceFactory.deploy(
XSUSHI_ADDRESS,
SUSHI_TOKEN_ADDRESS
SUSHI_TOKEN_ADDRESS
);

console.log("deployed SushiYieldSource at ", sushiYieldSource.address)
console.log("deployed SushiYieldSource at ", sushiYieldSource.address);

const block = await ethers.provider.getBlock();

Expand Down
2 changes: 1 addition & 1 deletion test/integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe("SushiYieldSource integration", function () {
{ gasLimit: 9500000 }
);

const exchangeWalletAddress = "0xD551234Ae421e3BCBA99A0Da6d736074f22192FF";
const exchangeWalletAddress = "0xF977814e90dA44bFA03b6295A0616a897441aceC";
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [exchangeWalletAddress],
Expand Down
52 changes: 46 additions & 6 deletions test/unit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ describe("SushiYieldSource", function () {
let yieldSource;
let amount;

let SushiYieldSourceContract;

let isDeployTest = false;

const deploySushiYieldSource = async (sushiBarAddress, sushiAddress) => {
yieldSource = await SushiYieldSourceContract.deploy(
sushiBarAddress,
sushiAddress,
overrides
);
};

beforeEach(async function () {
[wallet, wallet2] = await ethers.getSigners();
const ERC20MintableContract = await hre.ethers.getContractFactory(
Expand All @@ -33,21 +45,49 @@ describe("SushiYieldSource", function () {
);
sushiBar = await SushiBarContract.deploy(sushi.address);

const SushiYieldSourceContract = await ethers.getContractFactory(
SushiYieldSourceContract = await ethers.getContractFactory(
"SushiYieldSource"
);
yieldSource = await SushiYieldSourceContract.deploy(
sushiBar.address,
sushi.address,
overrides
);

if (!isDeployTest) {
deploySushiYieldSource(sushiBar.address, sushi.address);
}

amount = toWei("100");
await sushi.mint(wallet.address, amount);
await sushi.mint(wallet2.address, amount.mul(99));
await sushi.connect(wallet2).approve(sushiBar.address, amount.mul(99));
await sushiBar.connect(wallet2).enter(amount.mul(99));
});

describe("constructor()", () => {
let randomWalletAddress;

before(() => {
isDeployTest = true;
});

beforeEach(() => {
randomWalletAddress = ethers.Wallet.createRandom().address;
});

after(() => {
isDeployTest = false;
});

it("should fail if sushiBar address is address 0", async () => {
await expect(
deploySushiYieldSource(ethers.constants.AddressZero, sushi.address)
).to.be.revertedWith("SushiYieldSource/sushiBar-not-zero-address");
});

it("should fail if sushi address is address 0", async () => {
await expect(
deploySushiYieldSource(sushiBar.address, ethers.constants.AddressZero)
).to.be.revertedWith("SushiYieldSource/sushiAddr-not-zero-address");
});
});

it("get token address", async function () {
let address = await yieldSource.depositToken();
expect(address == sushi);
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8512,7 +8512,7 @@ solidity-comments-extractor@^0.0.4:
resolved "https://registry.yarnpkg.com/solidity-comments-extractor/-/solidity-comments-extractor-0.0.4.tgz#ce420aef23641ffd0131c7d80ba85b6e1e42147e"
integrity sha512-58glBODwXIKMaQ7rfcJOrWtFQMMOK28tJ0/LcB5Xhu7WtAxk4UX2fpgKPuaL41XjMp/y0gAa1MTLqk018wuSzA==

solidity-coverage@^0.7.16:
solidity-coverage@0.7.16:
version "0.7.16"
resolved "https://registry.yarnpkg.com/solidity-coverage/-/solidity-coverage-0.7.16.tgz#c8c8c46baa361e2817bbf275116ddd2ec90a55fb"
integrity sha512-ttBOStywE6ZOTJmmABSg4b8pwwZfYKG8zxu40Nz+sRF5bQX7JULXWj/XbX0KXps3Fsp8CJXg8P29rH3W54ipxw==
Expand Down

0 comments on commit a99e3a4

Please sign in to comment.