Removed redundant modifiers from CappedToken. (#969)
This commit is contained in:
13
contracts/mocks/RBACCappedTokenMock.sol
Normal file
13
contracts/mocks/RBACCappedTokenMock.sol
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
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
|
||||||
|
{}
|
||||||
|
}
|
||||||
@ -26,8 +26,6 @@ contract CappedToken is MintableToken {
|
|||||||
address _to,
|
address _to,
|
||||||
uint256 _amount
|
uint256 _amount
|
||||||
)
|
)
|
||||||
onlyOwner
|
|
||||||
canMint
|
|
||||||
public
|
public
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
|
|||||||
28
test/token/ERC20/CappedToken.behaviour.js
Normal file
28
test/token/ERC20/CappedToken.behaviour.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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 }));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -1,36 +1,17 @@
|
|||||||
|
|
||||||
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 () {
|
shouldBehaveLikeCappedToken([owner, anotherAccount, owner, _cap]);
|
||||||
let _cap = await token.cap();
|
|
||||||
|
|
||||||
assert(cap.eq(_cap));
|
shouldBehaveLikeMintableToken([owner, anotherAccount, owner]);
|
||||||
});
|
|
||||||
|
|
||||||
it('should mint when amount is less than cap', async function () {
|
|
||||||
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 () {
|
|
||||||
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));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
19
test/token/ERC20/RBACCappedToken.test.js
Normal file
19
test/token/ERC20/RBACCappedToken.test.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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]);
|
||||||
|
});
|
||||||
28
test/token/ERC20/RBACMintableToken.behaviour.js
Normal file
28
test/token/ERC20/RBACMintableToken.behaviour.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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 })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -1,8 +1,7 @@
|
|||||||
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]) {
|
|||||||
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]);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user