remove arrow functions from js tests (#1225)
This commit is contained in:
@ -13,13 +13,13 @@ const UINT_VALUE = 23;
|
|||||||
const BYTES_VALUE = web3.toHex('test');
|
const BYTES_VALUE = web3.toHex('test');
|
||||||
const INVALID_SIGNATURE = '0xabcd';
|
const INVALID_SIGNATURE = '0xabcd';
|
||||||
|
|
||||||
contract('Bouncer', ([_, owner, anyone, bouncerAddress, authorizedUser]) => {
|
contract('Bouncer', function ([_, owner, anyone, bouncerAddress, authorizedUser]) {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
this.bouncer = await Bouncer.new({ from: owner });
|
this.bouncer = await Bouncer.new({ from: owner });
|
||||||
this.roleBouncer = await this.bouncer.ROLE_BOUNCER();
|
this.roleBouncer = await this.bouncer.ROLE_BOUNCER();
|
||||||
});
|
});
|
||||||
|
|
||||||
context('management', () => {
|
context('management', function () {
|
||||||
it('has a default owner of self', async function () {
|
it('has a default owner of self', async function () {
|
||||||
(await this.bouncer.owner()).should.eq(owner);
|
(await this.bouncer.owner()).should.eq(owner);
|
||||||
});
|
});
|
||||||
@ -57,14 +57,14 @@ contract('Bouncer', ([_, owner, anyone, bouncerAddress, authorizedUser]) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('with bouncer address', () => {
|
context('with bouncer address', function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await this.bouncer.addBouncer(bouncerAddress, { from: owner });
|
await this.bouncer.addBouncer(bouncerAddress, { from: owner });
|
||||||
this.signFor = getBouncerSigner(this.bouncer, bouncerAddress);
|
this.signFor = getBouncerSigner(this.bouncer, bouncerAddress);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('modifiers', () => {
|
describe('modifiers', function () {
|
||||||
context('plain signature', () => {
|
context('plain signature', function () {
|
||||||
it('allows valid signature for sender', async function () {
|
it('allows valid signature for sender', async function () {
|
||||||
await this.bouncer.onlyWithValidSignature(this.signFor(authorizedUser), { from: authorizedUser });
|
await this.bouncer.onlyWithValidSignature(this.signFor(authorizedUser), { from: authorizedUser });
|
||||||
});
|
});
|
||||||
@ -89,7 +89,7 @@ contract('Bouncer', ([_, owner, anyone, bouncerAddress, authorizedUser]) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('method signature', () => {
|
context('method signature', function () {
|
||||||
it('allows valid signature with correct method for sender', async function () {
|
it('allows valid signature with correct method for sender', async function () {
|
||||||
await this.bouncer.onlyWithValidSignatureAndMethod(
|
await this.bouncer.onlyWithValidSignatureAndMethod(
|
||||||
this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: authorizedUser }
|
this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: authorizedUser }
|
||||||
@ -124,7 +124,7 @@ contract('Bouncer', ([_, owner, anyone, bouncerAddress, authorizedUser]) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('method and data signature', () => {
|
context('method and data signature', function () {
|
||||||
it('allows valid signature with correct method and data for sender', async function () {
|
it('allows valid signature with correct method and data for sender', async function () {
|
||||||
await this.bouncer.onlyWithValidSignatureAndData(UINT_VALUE,
|
await this.bouncer.onlyWithValidSignatureAndData(UINT_VALUE,
|
||||||
this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]), { from: authorizedUser }
|
this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]), { from: authorizedUser }
|
||||||
@ -165,8 +165,8 @@ contract('Bouncer', ([_, owner, anyone, bouncerAddress, authorizedUser]) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('signature validation', () => {
|
context('signature validation', function () {
|
||||||
context('plain signature', () => {
|
context('plain signature', function () {
|
||||||
it('validates valid signature for valid user', async function () {
|
it('validates valid signature for valid user', async function () {
|
||||||
(await this.bouncer.checkValidSignature(authorizedUser, this.signFor(authorizedUser))).should.eq(true);
|
(await this.bouncer.checkValidSignature(authorizedUser, this.signFor(authorizedUser))).should.eq(true);
|
||||||
});
|
});
|
||||||
@ -185,7 +185,7 @@ contract('Bouncer', ([_, owner, anyone, bouncerAddress, authorizedUser]) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('method signature', () => {
|
context('method signature', function () {
|
||||||
it('validates valid signature with correct method for valid user', async function () {
|
it('validates valid signature with correct method for valid user', async function () {
|
||||||
(await this.bouncer.checkValidSignatureAndMethod(authorizedUser,
|
(await this.bouncer.checkValidSignatureAndMethod(authorizedUser,
|
||||||
this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
|
this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
|
||||||
@ -208,7 +208,7 @@ contract('Bouncer', ([_, owner, anyone, bouncerAddress, authorizedUser]) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('method and data signature', () => {
|
context('method and data signature', function () {
|
||||||
it('validates valid signature with correct method and data for valid user', async function () {
|
it('validates valid signature with correct method and data for valid user', async function () {
|
||||||
(await this.bouncer.checkValidSignatureAndData(authorizedUser, BYTES_VALUE, UINT_VALUE,
|
(await this.bouncer.checkValidSignatureAndData(authorizedUser, BYTES_VALUE, UINT_VALUE,
|
||||||
this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
|
this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
|
||||||
|
|||||||
@ -63,7 +63,7 @@ contract('ECRecovery', function ([_, anyone]) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
context('toEthSignedMessage', () => {
|
context('toEthSignedMessage', function () {
|
||||||
it('should prefix hashes correctly', async function () {
|
it('should prefix hashes correctly', async function () {
|
||||||
const hashedMessage = web3.sha3(TEST_MESSAGE);
|
const hashedMessage = web3.sha3(TEST_MESSAGE);
|
||||||
(await ecrecovery.toEthSignedMessageHash(hashedMessage)).should.eq(hashMessage(TEST_MESSAGE));
|
(await ecrecovery.toEthSignedMessageHash(hashedMessage)).should.eq(hashMessage(TEST_MESSAGE));
|
||||||
|
|||||||
@ -7,7 +7,7 @@ require('chai')
|
|||||||
.use(require('chai-bignumber')(BigNumber))
|
.use(require('chai-bignumber')(BigNumber))
|
||||||
.should();
|
.should();
|
||||||
|
|
||||||
contract('SafeMath', () => {
|
contract('SafeMath', function () {
|
||||||
const MAX_UINT = new BigNumber(2).pow(256).minus(1);
|
const MAX_UINT = new BigNumber(2).pow(256).minus(1);
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ contract('HasNoContracts', function ([_, owner, anyone]) {
|
|||||||
let hasNoContracts = null;
|
let hasNoContracts = null;
|
||||||
let ownable = null;
|
let ownable = null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async function () {
|
||||||
// Create contract and token
|
// Create contract and token
|
||||||
hasNoContracts = await HasNoContracts.new({ from: owner });
|
hasNoContracts = await HasNoContracts.new({ from: owner });
|
||||||
ownable = await Ownable.new({ from: owner });
|
ownable = await Ownable.new({ from: owner });
|
||||||
|
|||||||
@ -13,7 +13,7 @@ contract('HasNoTokens', function ([_, owner, initialAccount, anyone]) {
|
|||||||
let hasNoTokens = null;
|
let hasNoTokens = null;
|
||||||
let token = null;
|
let token = null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async function () {
|
||||||
// Create contract and token
|
// Create contract and token
|
||||||
hasNoTokens = await HasNoTokens.new({ from: owner });
|
hasNoTokens = await HasNoTokens.new({ from: owner });
|
||||||
token = await ERC223TokenMock.new(initialAccount, 100);
|
token = await ERC223TokenMock.new(initialAccount, 100);
|
||||||
|
|||||||
@ -13,7 +13,7 @@ contract('Superuser', function ([_, firstOwner, newSuperuser, newOwner, anyone])
|
|||||||
this.superuser = await Superuser.new({ from: firstOwner });
|
this.superuser = await Superuser.new({ from: firstOwner });
|
||||||
});
|
});
|
||||||
|
|
||||||
context('in normal conditions', () => {
|
context('in normal conditions', function () {
|
||||||
it('should set the owner as the default superuser', async function () {
|
it('should set the owner as the default superuser', async function () {
|
||||||
(await this.superuser.isSuperuser(firstOwner)).should.be.be.true;
|
(await this.superuser.isSuperuser(firstOwner)).should.be.be.true;
|
||||||
});
|
});
|
||||||
@ -53,7 +53,7 @@ contract('Superuser', function ([_, firstOwner, newSuperuser, newOwner, anyone])
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('in adversarial conditions', () => {
|
context('in adversarial conditions', function () {
|
||||||
it('should prevent non-superusers from transfering the superuser role', async function () {
|
it('should prevent non-superusers from transfering the superuser role', async function () {
|
||||||
await expectThrow(
|
await expectThrow(
|
||||||
this.superuser.transferSuperuser(newOwner, { from: anyone })
|
this.superuser.transferSuperuser(newOwner, { from: anyone })
|
||||||
|
|||||||
@ -11,50 +11,50 @@ const ROLE_ADVISOR = 'advisor';
|
|||||||
contract('RBAC', function ([_, admin, anyone, advisor, otherAdvisor, futureAdvisor]) {
|
contract('RBAC', function ([_, admin, anyone, advisor, otherAdvisor, futureAdvisor]) {
|
||||||
let mock;
|
let mock;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async function () {
|
||||||
mock = await RBACMock.new([advisor, otherAdvisor], { from: admin });
|
mock = await RBACMock.new([advisor, otherAdvisor], { from: admin });
|
||||||
});
|
});
|
||||||
|
|
||||||
context('in normal conditions', () => {
|
context('in normal conditions', function () {
|
||||||
it('allows admin to call #onlyAdminsCanDoThis', async () => {
|
it('allows admin to call #onlyAdminsCanDoThis', async function () {
|
||||||
await mock.onlyAdminsCanDoThis({ from: admin });
|
await mock.onlyAdminsCanDoThis({ from: admin });
|
||||||
});
|
});
|
||||||
it('allows admin to call #onlyAdvisorsCanDoThis', async () => {
|
it('allows admin to call #onlyAdvisorsCanDoThis', async function () {
|
||||||
await mock.onlyAdvisorsCanDoThis({ from: admin });
|
await mock.onlyAdvisorsCanDoThis({ from: admin });
|
||||||
});
|
});
|
||||||
it('allows advisors to call #onlyAdvisorsCanDoThis', async () => {
|
it('allows advisors to call #onlyAdvisorsCanDoThis', async function () {
|
||||||
await mock.onlyAdvisorsCanDoThis({ from: advisor });
|
await mock.onlyAdvisorsCanDoThis({ from: advisor });
|
||||||
});
|
});
|
||||||
it('allows admin to call #eitherAdminOrAdvisorCanDoThis', async () => {
|
it('allows admin to call #eitherAdminOrAdvisorCanDoThis', async function () {
|
||||||
await mock.eitherAdminOrAdvisorCanDoThis({ from: admin });
|
await mock.eitherAdminOrAdvisorCanDoThis({ from: admin });
|
||||||
});
|
});
|
||||||
it('allows advisors to call #eitherAdminOrAdvisorCanDoThis', async () => {
|
it('allows advisors to call #eitherAdminOrAdvisorCanDoThis', async function () {
|
||||||
await mock.eitherAdminOrAdvisorCanDoThis({ from: advisor });
|
await mock.eitherAdminOrAdvisorCanDoThis({ from: advisor });
|
||||||
});
|
});
|
||||||
it('does not allow admins to call #nobodyCanDoThis', async () => {
|
it('does not allow admins to call #nobodyCanDoThis', async function () {
|
||||||
await expectThrow(mock.nobodyCanDoThis({ from: admin }));
|
await expectThrow(mock.nobodyCanDoThis({ from: admin }));
|
||||||
});
|
});
|
||||||
it('does not allow advisors to call #nobodyCanDoThis', async () => {
|
it('does not allow advisors to call #nobodyCanDoThis', async function () {
|
||||||
await expectThrow(mock.nobodyCanDoThis({ from: advisor }));
|
await expectThrow(mock.nobodyCanDoThis({ from: advisor }));
|
||||||
});
|
});
|
||||||
it('does not allow anyone to call #nobodyCanDoThis', async () => {
|
it('does not allow anyone to call #nobodyCanDoThis', async function () {
|
||||||
await expectThrow(mock.nobodyCanDoThis({ from: anyone }));
|
await expectThrow(mock.nobodyCanDoThis({ from: anyone }));
|
||||||
});
|
});
|
||||||
it('allows an admin to remove an advisor\'s role', async () => {
|
it('allows an admin to remove an advisor\'s role', async function () {
|
||||||
await mock.removeAdvisor(advisor, { from: admin });
|
await mock.removeAdvisor(advisor, { from: admin });
|
||||||
});
|
});
|
||||||
it('allows admins to #adminRemoveRole', async () => {
|
it('allows admins to #adminRemoveRole', async function () {
|
||||||
await mock.adminRemoveRole(advisor, ROLE_ADVISOR, { from: admin });
|
await mock.adminRemoveRole(advisor, ROLE_ADVISOR, { from: admin });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('announces a RoleAdded event on addRole', async () => {
|
it('announces a RoleAdded event on addRole', async function () {
|
||||||
await expectEvent.inTransaction(
|
await expectEvent.inTransaction(
|
||||||
mock.adminAddRole(futureAdvisor, ROLE_ADVISOR, { from: admin }),
|
mock.adminAddRole(futureAdvisor, ROLE_ADVISOR, { from: admin }),
|
||||||
'RoleAdded'
|
'RoleAdded'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('announces a RoleRemoved event on removeRole', async () => {
|
it('announces a RoleRemoved event on removeRole', async function () {
|
||||||
await expectEvent.inTransaction(
|
await expectEvent.inTransaction(
|
||||||
mock.adminRemoveRole(futureAdvisor, ROLE_ADVISOR, { from: admin }),
|
mock.adminRemoveRole(futureAdvisor, ROLE_ADVISOR, { from: admin }),
|
||||||
'RoleRemoved'
|
'RoleRemoved'
|
||||||
@ -62,11 +62,11 @@ contract('RBAC', function ([_, admin, anyone, advisor, otherAdvisor, futureAdvis
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('in adversarial conditions', () => {
|
context('in adversarial conditions', function () {
|
||||||
it('does not allow an advisor to remove another advisor', async () => {
|
it('does not allow an advisor to remove another advisor', async function () {
|
||||||
await expectThrow(mock.removeAdvisor(otherAdvisor, { from: advisor }));
|
await expectThrow(mock.removeAdvisor(otherAdvisor, { from: advisor }));
|
||||||
});
|
});
|
||||||
it('does not allow "anyone" to remove an advisor', async () => {
|
it('does not allow "anyone" to remove an advisor', async function () {
|
||||||
await expectThrow(mock.removeAdvisor(advisor, { from: anyone }));
|
await expectThrow(mock.removeAdvisor(advisor, { from: anyone }));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user