Skip to content

Commit

Permalink
add setter.js test file
Browse files Browse the repository at this point in the history
  • Loading branch information
danoctavian committed Jun 25, 2021
1 parent 331bd9f commit 35b93bb
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/unit/Distributor/setters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { web3, accounts } = require('hardhat');
const { expectRevert } = require('@openzeppelin/test-helpers');
const { assert } = require('chai');
const { hex } = require('../utils').helpers;
const { toBN } = web3.utils;

const [, treasury, coverHolder, newTreasury, nonOwner] = accounts;

describe('buyCover', function () {

it('allows setting new treasury address by owner', async function () {
const { distributor } = this.contracts;

await distributor.setTreasury(newTreasury);

const currentTreasury = await distributor.treasury();
assert.equal(newTreasury, currentTreasury);
});

it('rejects setting new treasury to 0', async function () {
const { distributor } = this.contracts;

await expectRevert(
distributor.setTreasury('0x0000000000000000000000000000000000000000'),
'Distributor: treasury address is 0',
);
});

it('disallows setting the fee percentage by non-owner', async function () {
const { distributor } = this.contracts;

await expectRevert(
distributor.setTreasury(newTreasury, { from: nonOwner }),
'Ownable: caller is not the owner',
);
});

it('allows setting the fee percentage by owner', async function () {
const { distributor } = this.contracts;

const newFeePercentage = '20000';

await distributor.setFeePercentage(newFeePercentage);

const storedFeePercentage = await distributor.feePercentage();
assert(storedFeePercentage.toString(), newFeePercentage);
});

it('disallows setting the fee percentage by non-owner', async function () {
const { distributor } = this.contracts;

const newFeePercentage = '20000';

await expectRevert(
distributor.setFeePercentage(newFeePercentage, {
from: nonOwner,
}),
'Ownable: caller is not the owner',
);
});
});

0 comments on commit 35b93bb

Please sign in to comment.