Commit 5326e7c3 by Alen Committed by Matt Condon

Removed redundant modifiers from CappedToken. (#969)

parent feb66513
pragma solidity ^0.4.23;
import "../token/ERC20/RBACMintableToken.sol";
import "../token/ERC20/CappedToken.sol";
contract RBACCappedTokenMock is CappedToken, RBACMintableToken {
constructor(
uint256 _cap
)
CappedToken(_cap)
public
{}
}
\ No newline at end of file
...@@ -26,8 +26,6 @@ contract CappedToken is MintableToken { ...@@ -26,8 +26,6 @@ contract CappedToken is MintableToken {
address _to, address _to,
uint256 _amount uint256 _amount
) )
onlyOwner
canMint
public public
returns (bool) returns (bool)
{ {
......
import expectThrow from '../../helpers/expectThrow';
export default function ([owner, anotherAccount, minter, cap]) {
describe('capped token', function () {
const from = minter;
it('should start with the correct cap', async function () {
let _cap = await this.token.cap();
assert(cap.eq(_cap));
});
it('should mint when amount is less than cap', async function () {
const result = await this.token.mint(owner, cap.sub(1), { from });
assert.equal(result.logs[0].event, 'Mint');
});
it('should fail to mint if the ammount exceeds the cap', async function () {
await this.token.mint(owner, cap.sub(1), { from });
await expectThrow(this.token.mint(owner, 100, { from }));
});
it('should fail to mint after cap is reached', async function () {
await this.token.mint(owner, cap, { from });
await expectThrow(this.token.mint(owner, 1, { from }));
});
});
}
import expectThrow from '../../helpers/expectThrow';
import ether from '../../helpers/ether'; import ether from '../../helpers/ether';
import shouldBehaveLikeMintableToken from './MintableToken.behaviour';
import shouldBehaveLikeCappedToken from './CappedToken.behaviour';
var CappedToken = artifacts.require('CappedToken'); var CappedToken = artifacts.require('CappedToken');
contract('Capped', function (accounts) { contract('Capped', function ([owner, anotherAccount]) {
const cap = ether(1000); const _cap = ether(1000);
let token;
beforeEach(async function () { beforeEach(async function () {
token = await CappedToken.new(cap); this.token = await CappedToken.new(_cap, { from: owner });
});
it('should start with the correct cap', async function () {
let _cap = await token.cap();
assert(cap.eq(_cap));
}); });
it('should mint when amount is less than cap', async function () { shouldBehaveLikeCappedToken([owner, anotherAccount, owner, _cap]);
const result = await token.mint(accounts[0], 100);
assert.equal(result.logs[0].event, 'Mint');
});
it('should fail to mint if the ammount exceeds the cap', async function () { shouldBehaveLikeMintableToken([owner, anotherAccount, owner]);
await token.mint(accounts[0], cap.sub(1));
await expectThrow(token.mint(accounts[0], 100));
});
it('should fail to mint after cap is reached', async function () {
await token.mint(accounts[0], cap);
await expectThrow(token.mint(accounts[0], 1));
});
}); });
import ether from '../../helpers/ether';
import shouldBehaveLikeRBACMintableToken from './RBACMintableToken.behaviour';
import shouldBehaveLikeMintableToken from './MintableToken.behaviour';
import shouldBehaveLikeCappedToken from './CappedToken.behaviour';
const RBACCappedTokenMock = artifacts.require('RBACCappedTokenMock');
contract('RBACCappedToken', function ([owner, anotherAccount, minter]) {
const _cap = ether(1000);
beforeEach(async function () {
this.token = await RBACCappedTokenMock.new(_cap, { from: owner });
await this.token.addMinter(minter, { from: owner });
});
shouldBehaveLikeMintableToken([owner, anotherAccount, minter]);
shouldBehaveLikeRBACMintableToken([owner, anotherAccount]);
shouldBehaveLikeCappedToken([owner, anotherAccount, minter, _cap]);
});
import expectThrow from '../../helpers/expectThrow';
const ROLE_MINTER = 'minter';
export default function ([owner, anotherAccount]) {
describe('handle roles', function () {
it('owner can add and remove a minter role', async function () {
await this.token.addMinter(anotherAccount, { from: owner });
let hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER);
assert.equal(hasRole, true);
await this.token.removeMinter(anotherAccount, { from: owner });
hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER);
assert.equal(hasRole, false);
});
it('another account can\'t add or remove a minter role', async function () {
await expectThrow(
this.token.addMinter(anotherAccount, { from: anotherAccount })
);
await this.token.addMinter(anotherAccount, { from: owner });
await expectThrow(
this.token.removeMinter(anotherAccount, { from: anotherAccount })
);
});
});
};
import expectThrow from '../../helpers/expectThrow'; import shouldBehaveLikeRBACMintableToken from './RBACMintableToken.behaviour';
import shouldBehaveLikeMintableToken from './MintableToken.behaviour'; import shouldBehaveLikeMintableToken from './MintableToken.behaviour';
const RBACMintableToken = artifacts.require('RBACMintableToken');
const ROLE_MINTER = 'minter'; const RBACMintableToken = artifacts.require('RBACMintableToken');
contract('RBACMintableToken', function ([owner, anotherAccount, minter]) { contract('RBACMintableToken', function ([owner, anotherAccount, minter]) {
beforeEach(async function () { beforeEach(async function () {
...@@ -10,28 +9,6 @@ contract('RBACMintableToken', function ([owner, anotherAccount, minter]) { ...@@ -10,28 +9,6 @@ contract('RBACMintableToken', function ([owner, anotherAccount, minter]) {
await this.token.addMinter(minter, { from: owner }); await this.token.addMinter(minter, { from: owner });
}); });
describe('handle roles', function () { shouldBehaveLikeRBACMintableToken([owner, anotherAccount, minter]);
it('owner can add and remove a minter role', async function () {
await this.token.addMinter(anotherAccount, { from: owner });
let hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER);
assert.equal(hasRole, true);
await this.token.removeMinter(anotherAccount, { from: owner });
hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER);
assert.equal(hasRole, false);
});
it('another account can\'t add or remove a minter role', async function () {
await expectThrow(
this.token.addMinter(anotherAccount, { from: anotherAccount })
);
await this.token.addMinter(anotherAccount, { from: owner });
await expectThrow(
this.token.removeMinter(anotherAccount, { from: anotherAccount })
);
});
});
shouldBehaveLikeMintableToken([owner, anotherAccount, minter]); shouldBehaveLikeMintableToken([owner, anotherAccount, minter]);
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment