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

Fix/65 add zero-address checks #6

Merged
merged 3 commits into from
Jul 12, 2021
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
2 changes: 2 additions & 0 deletions contracts/BadgerYieldSource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ contract BadgerYieldSource is IYieldSource {
mapping(address => uint256) private balances;

constructor(address badgerSettAddr, address badgerAddr) public {
require(address(badgerSettAddr) != address(0), "BadgerYieldSource/badgerSettAddr-not-zero-address");
require(address(badgerAddr) != address(0), "BadgerYieldSource/badgerAddr-not-zero-address");
badgerSett = IBadgerSett(badgerSettAddr);
badger = IBadger(badgerAddr);
}
Expand Down
53 changes: 41 additions & 12 deletions test/unit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ describe("BadgerYieldSource", function () {
let yieldSource;
let amount;

let BadgerYieldSourceContract;

let isDeployTest = false;

const deployBadgerYieldSource = async (badgerSettAddress, badgerAddress) => {
yieldSource = await BadgerYieldSourceContract.deploy(
badgerSettAddress,
badgerAddress,
overrides,
);
};

beforeEach(async function () {
[wallet, wallet2, wallet3] = await ethers.getSigners();

Expand All @@ -34,17 +46,13 @@ describe("BadgerYieldSource", function () {
);
badgerSett = await BadgerSettContract.deploy();

//

const tokenAddress = badger.address;
const governanceAddress = wallet.address;
const guardianAddress = wallet.address;
const keeperAddress = wallet.address;
const rewardsAddress = wallet.address;
const strategistAddress = wallet.address;

//

const Controller = await ethers.getContractFactory(
"Controller",
wallet,
Expand Down Expand Up @@ -89,17 +97,16 @@ describe("BadgerYieldSource", function () {
"bBADGER"
);

const BadgerYieldSourceContract = await ethers.getContractFactory(
BadgerYieldSourceContract = await ethers.getContractFactory(
"BadgerYieldSource"
);
yieldSource = await BadgerYieldSourceContract.deploy(
badgerSett.address,
badger.address,
overrides
);

// whilelist the yield source
await badgerSett.approveContractAccess(yieldSource.address);
if (!isDeployTest) {
await deployBadgerYieldSource(badgerSett.address, badger.address);

// whilelist the yield source
await badgerSett.approveContractAccess(yieldSource.address);
}

amount = toWei("100");
await badger.mint(wallet3.address, amount);
Expand All @@ -109,6 +116,28 @@ describe("BadgerYieldSource", function () {
await badgerSett.connect(wallet2).deposit(amount.mul(99));
});

describe('constructor()', () => {
before(() => {
isDeployTest = true;
});

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

it('should fail if badgerSett address is address 0', async () => {
await expect(
deployBadgerYieldSource(ethers.constants.AddressZero, badger.address),
).to.be.revertedWith('BadgerYieldSource/badgerSettAddr-not-zero-address');
});

it('should fail if badger address is address 0', async () => {
await expect(
deployBadgerYieldSource(badgerSett.address, ethers.constants.AddressZero),
).to.be.revertedWith('BadgerYieldSource/badgerAddr-not-zero-address');
});
});

it("get token address", async function () {
let address = await yieldSource.depositToken();
expect(address == badger);
Expand Down