Skip to content

Commit

Permalink
update(GaugeController.sol): add unit tests for access roles
Browse files Browse the repository at this point in the history
  • Loading branch information
kamescg committed Jun 1, 2022
1 parent 89bd9c6 commit c888e42
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test/GaugeController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const { parseEther: toWei } = utils;

describe('GaugeController', () => {
let owner: SignerWithAddress;
let wallet2: SignerWithAddress;
let GaugeController: Contract;
let GaugeReward: MockContract;
let Token: Contract;
Expand All @@ -23,7 +24,7 @@ describe('GaugeController', () => {
const gaugeAddress = '0x0000000000000000000000000000000000000001';

before(async () => {
[owner] = await getSigners();
[owner, wallet2] = await getSigners();
GaugeControllerFactory = await ethers.getContractFactory('GaugeController');
GaugeRewardArtifact = await artifacts.readArtifact('GaugeReward');
TokenFactory = await ethers.getContractFactory('ERC20Mintable');
Expand Down Expand Up @@ -176,6 +177,11 @@ describe('GaugeController', () => {
'1000000000000000000',
);
});

it('should FAIL to execute BECAUSE of unauthorized access', async () => {
const unauthorized = GaugeController.connect(wallet2);
expect(unauthorized.addGaugeWithScale(gaugeAddress, toWei('1'))).to.be.revertedWith('Ownable/caller-not-owner');
});
});

/**
Expand All @@ -192,6 +198,11 @@ describe('GaugeController', () => {
await GaugeController.removeGauge(gaugeAddress);
expect(await GaugeController.getGaugeScaleBalance(gaugeAddress)).to.eq('0');
});

it('should FAIL to execute BECAUSE of unauthorized access', async () => {
const unauthorized = GaugeController.connect(wallet2);
expect(unauthorized.removeGauge(gaugeAddress)).to.be.revertedWith('Ownable/caller-not-owner');
});
});

/**
Expand Down Expand Up @@ -220,8 +231,29 @@ describe('GaugeController', () => {
'500000000000000000',
);
});

it('should FAIL to execute BECAUSE of unauthorized access', async () => {
await GaugeController.addGauge(gaugeAddress);
const unauthorized = GaugeController.connect(wallet2);
expect(unauthorized.setGaugeScale(gaugeAddress, toWei('2'))).to.be.revertedWith('Manageable/caller-not-manager-or-owner');
});
});

describe('setGaugeReward(IGaugeReward _gaugeReward)', () => {
it('should SUCCEED to SET a new GaugeReward address', async () => {
await GaugeController.addGauge(gaugeAddress);
await GaugeController.setGaugeReward('0x0000000000000000000000000000000000000001');
expect(await GaugeController.gaugeReward()).to.eq(
'0x0000000000000000000000000000000000000001',
);
});

it('should FAIL to execute BECAUSE of unauthorized access', async () => {
const unauthorized = GaugeController.connect(wallet2);
expect(unauthorized.setGaugeReward('0x0000000000000000000000000000000000000001')).to.be.revertedWith('Manageable/caller-not-manager-or-owner');
});
})

/**
* @description Test getGaugeBalance(address _gauge) function
* -= Expected Behavior =-
Expand Down

0 comments on commit c888e42

Please sign in to comment.