Skip to content

Commit

Permalink
feat(payroll): add checks for zero addresses in initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRBerg committed Oct 29, 2019
1 parent c86e6b8 commit b415ea3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/payroll/contracts/Payroll.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ contract Payroll is Initializable, OwnableWithoutRenounce, Exponential, GSNRecip
* @param sablierAddress The address of the Sablier contract.
*/
function initialize(address ownerAddress, address signerAddress, address sablierAddress) public initializer {
require(ownerAddress != address(0x00), "owner is the zero address");
require(signerAddress != address(0x00), "signer is the zero address");
require(sablierAddress != address(0x00), "sablier contract is the zero address");
OwnableWithoutRenounce.initialize(ownerAddress);
GSNRecipient.initialize();
GSNBouncerSignature.initialize(signerAddress);
Expand Down
53 changes: 45 additions & 8 deletions packages/payroll/test/payroll/Payroll.behavior.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const traveler = require("ganache-time-traveler");
const { devConstants } = require("@sablier/dev-utils");
const truffleAssert = require("truffle-assertions");

const shouldBehaveLikeDiscardRelayer = require("./admin/DiscardRelayer");
const shouldBehaveLikeWhitelistRelayer = require("./admin/WhitelistRelayer");
Expand All @@ -11,16 +12,52 @@ const shouldBehaveLikeWithdrawFromSalary = require("./effects/salary/WithdrawFro
const shouldBehaveLikeCancelSalary = require("./effects/salary/CancelSalary");
const shouldBehaveLikeCancelCompoundingSalary = require("./effects/compoundingSalary/CancelCompoundingSalary");

const Payroll = artifacts.require("./Payroll.sol");
const { ZERO_ADDRESS } = devConstants;

function shouldBehaveLikePayroll(alice, bob, carol, eve) {
let snapshotId;
describe("initialization", function() {
it("reverts when the owner is the zero address", async function() {
const opts = { from: alice };
const payroll = await Payroll.new(opts);

beforeEach(async () => {
const snapshot = await traveler.takeSnapshot();
snapshotId = snapshot.result;
});
const ownerAddress = ZERO_ADDRESS;
const signerAddress = alice;
const sablierAddress = this.sablier.address;

await truffleAssert.reverts(
payroll.methods["initialize(address,address,address)"](ownerAddress, signerAddress, sablierAddress, opts),
"owner is the zero address",
);
});

it("reverts when the signer is the zero address", async function() {
const opts = { from: alice };
const payroll = await Payroll.new(opts);

const ownerAddress = alice;
const signerAddress = ZERO_ADDRESS;
const sablierAddress = this.sablier.address;

afterEach(async () => {
await traveler.revertToSnapshot(snapshotId);
await truffleAssert.reverts(
payroll.methods["initialize(address,address,address)"](ownerAddress, signerAddress, sablierAddress, opts),
"signer is the zero address",
);
});

it("reverts when the sablier contract is the zero address", async function() {
const opts = { from: alice };
const payroll = await Payroll.new(opts);

const ownerAddress = alice;
const signerAddress = alice;
const sablierAddress = ZERO_ADDRESS;

await truffleAssert.reverts(
payroll.methods["initialize(address,address,address)"](ownerAddress, signerAddress, sablierAddress, opts),
"sablier contract is the zero address",
);
});
});

describe("admin functions", function() {
Expand Down
14 changes: 13 additions & 1 deletion packages/payroll/test/setup.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
const { chaiPlugin } = require("@sablier/dev-utils");
const traveler = require("ganache-time-traveler");

const BigNumber = require("bignumber.js");
const chai = require("chai");
const chaiBigNumber = require("chai-bignumber");

chai.use(chaiBigNumber(BigNumber));
chai.should();
chai.use(chaiBigNumber(BigNumber));
chai.use(chaiPlugin);

let snapshotId;

beforeEach(async () => {
const snapshot = await traveler.takeSnapshot();
snapshotId = snapshot.result;
});

afterEach(async () => {
await traveler.revertToSnapshot(snapshotId);
});

0 comments on commit b415ea3

Please sign in to comment.