Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aodhgan committed Aug 31, 2021
1 parent 9ed07d5 commit ea19e3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions contracts/test/OwnerOrManagerHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import "hardhat/console.sol";

contract OwnerOrManagerHarness is OwnerOrManager {

event ReallyCoolEvent(address);

constructor() public {
__Ownable_init();

Expand All @@ -16,6 +18,9 @@ contract OwnerOrManagerHarness is OwnerOrManager {
function protectedFunction() public onlyManagerOrOwner {

// do admin priviledges things


emit ReallyCoolEvent(msg.sender);
}

}
14 changes: 11 additions & 3 deletions test/OwnerOrManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { expect } from 'chai';
import { deployMockContract, MockContract } from 'ethereum-waffle';
import { Contract, ContractFactory, Signer, Wallet } from 'ethers';
import { ethers } from 'hardhat';
import { Interface } from 'ethers/lib/utils';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';

describe('Test Set Name', () => {
Expand All @@ -24,9 +22,19 @@ describe('Test Set Name', () => {
})

describe("onlyManagerOrOwner()", ()=>{
it('permissions correctly', async () => {
it('non owner non manager cannot call permissioned function', async () => {
await expect(ownerOrManager.connect(wallet3).protectedFunction()).to.be.revertedWith("Manager/caller-not-manager-or-owner")
})

it('non owner non manager cannot call permissioned function', async () => {
await expect(ownerOrManager.protectedFunction()).to.emit(ownerOrManager, "ReallyCoolEvent")
await ownerOrManager.setManager(wallet2.address)
await expect(ownerOrManager.connect(wallet2).protectedFunction()).to.emit(ownerOrManager, "ReallyCoolEvent")
})

it('manager cannot set new manage', async ()=> {
await expect(ownerOrManager.connect(wallet2).protectedFunction()).to.be.reverted
})
})

})

0 comments on commit ea19e3a

Please sign in to comment.