Use Prettier for JS files (#3913)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
Francisco
2023-01-04 11:03:40 -03:00
committed by GitHub
parent 88754d0b36
commit a28aafdc85
135 changed files with 2737 additions and 3121 deletions

View File

@ -3,9 +3,7 @@ const { ZERO_ADDRESS, ZERO_BYTES32 } = constants;
const { expect } = require('chai');
const {
shouldSupportInterfaces,
} = require('../utils/introspection/SupportsInterface.behavior');
const { shouldSupportInterfaces } = require('../utils/introspection/SupportsInterface.behavior');
const TimelockController = artifacts.require('TimelockController');
const CallReceiverMock = artifacts.require('CallReceiverMock');
@ -17,42 +15,28 @@ const MINDELAY = time.duration.days(1);
const salt = '0x025e7b0be353a74631ad648c667493c0e1cd31caa4cc2d3520fdc171ea0cc726'; // a random value
function genOperation (target, value, data, predecessor, salt) {
const id = web3.utils.keccak256(web3.eth.abi.encodeParameters([
'address',
'uint256',
'bytes',
'uint256',
'bytes32',
], [
target,
value,
data,
predecessor,
salt,
]));
function genOperation(target, value, data, predecessor, salt) {
const id = web3.utils.keccak256(
web3.eth.abi.encodeParameters(
['address', 'uint256', 'bytes', 'uint256', 'bytes32'],
[target, value, data, predecessor, salt],
),
);
return { id, target, value, data, predecessor, salt };
}
function genOperationBatch (targets, values, payloads, predecessor, salt) {
const id = web3.utils.keccak256(web3.eth.abi.encodeParameters([
'address[]',
'uint256[]',
'bytes[]',
'uint256',
'bytes32',
], [
targets,
values,
payloads,
predecessor,
salt,
]));
function genOperationBatch(targets, values, payloads, predecessor, salt) {
const id = web3.utils.keccak256(
web3.eth.abi.encodeParameters(
['address[]', 'uint256[]', 'bytes[]', 'uint256', 'bytes32'],
[targets, values, payloads, predecessor, salt],
),
);
return { id, targets, values, payloads, predecessor, salt };
}
contract('TimelockController', function (accounts) {
const [ , admin, proposer, canceller, executor, other ] = accounts;
const [, admin, proposer, canceller, executor, other] = accounts;
const TIMELOCK_ADMIN_ROLE = web3.utils.soliditySha3('TIMELOCK_ADMIN_ROLE');
const PROPOSER_ROLE = web3.utils.soliditySha3('PROPOSER_ROLE');
@ -61,12 +45,7 @@ contract('TimelockController', function (accounts) {
beforeEach(async function () {
// Deploy new timelock
this.mock = await TimelockController.new(
MINDELAY,
[ proposer ],
[ executor ],
admin,
);
this.mock = await TimelockController.new(MINDELAY, [proposer], [executor], admin);
expect(await this.mock.hasRole(CANCELLER_ROLE, proposer)).to.be.equal(true);
await this.mock.revokeRole(CANCELLER_ROLE, proposer, { from: admin });
@ -77,9 +56,7 @@ contract('TimelockController', function (accounts) {
this.implementation2 = await Implementation2.new({ from: admin });
});
shouldSupportInterfaces([
'ERC1155Receiver',
]);
shouldSupportInterfaces(['ERC1155Receiver']);
it('initial state', async function () {
expect(await this.mock.getMinDelay()).to.be.bignumber.equal(MINDELAY);
@ -89,27 +66,21 @@ contract('TimelockController', function (accounts) {
expect(await this.mock.EXECUTOR_ROLE()).to.be.equal(EXECUTOR_ROLE);
expect(await this.mock.CANCELLER_ROLE()).to.be.equal(CANCELLER_ROLE);
expect(await Promise.all([ PROPOSER_ROLE, CANCELLER_ROLE, EXECUTOR_ROLE ].map(role =>
this.mock.hasRole(role, proposer),
))).to.be.deep.equal([ true, false, false ]);
expect(
await Promise.all([PROPOSER_ROLE, CANCELLER_ROLE, EXECUTOR_ROLE].map(role => this.mock.hasRole(role, proposer))),
).to.be.deep.equal([true, false, false]);
expect(await Promise.all([ PROPOSER_ROLE, CANCELLER_ROLE, EXECUTOR_ROLE ].map(role =>
this.mock.hasRole(role, canceller),
))).to.be.deep.equal([ false, true, false ]);
expect(
await Promise.all([PROPOSER_ROLE, CANCELLER_ROLE, EXECUTOR_ROLE].map(role => this.mock.hasRole(role, canceller))),
).to.be.deep.equal([false, true, false]);
expect(await Promise.all([ PROPOSER_ROLE, CANCELLER_ROLE, EXECUTOR_ROLE ].map(role =>
this.mock.hasRole(role, executor),
))).to.be.deep.equal([ false, false, true ]);
expect(
await Promise.all([PROPOSER_ROLE, CANCELLER_ROLE, EXECUTOR_ROLE].map(role => this.mock.hasRole(role, executor))),
).to.be.deep.equal([false, false, true]);
});
it('optional admin', async function () {
const mock = await TimelockController.new(
MINDELAY,
[ proposer ],
[ executor ],
ZERO_ADDRESS,
{ from: other },
);
const mock = await TimelockController.new(MINDELAY, [proposer], [executor], ZERO_ADDRESS, { from: other });
expect(await mock.hasRole(TIMELOCK_ADMIN_ROLE, admin)).to.be.equal(false);
expect(await mock.hasRole(TIMELOCK_ADMIN_ROLE, other)).to.be.equal(false);
@ -125,13 +96,15 @@ contract('TimelockController', function (accounts) {
'0xba41db3be0a9929145cfe480bd0f1f003689104d275ae912099f925df424ef94',
'0x60d9109846ab510ed75c15f979ae366a8a2ace11d34ba9788c13ac296db50e6e',
);
expect(await this.mock.hashOperation(
this.operation.target,
this.operation.value,
this.operation.data,
this.operation.predecessor,
this.operation.salt,
)).to.be.equal(this.operation.id);
expect(
await this.mock.hashOperation(
this.operation.target,
this.operation.value,
this.operation.data,
this.operation.predecessor,
this.operation.salt,
),
).to.be.equal(this.operation.id);
});
it('hashOperationBatch', async function () {
@ -142,13 +115,15 @@ contract('TimelockController', function (accounts) {
'0xce8f45069cc71d25f71ba05062de1a3974f9849b004de64a70998bca9d29c2e7',
'0x8952d74c110f72bfe5accdf828c74d53a7dfb71235dfa8a1e8c75d8576b372ff',
);
expect(await this.mock.hashOperationBatch(
this.operation.targets,
this.operation.values,
this.operation.payloads,
this.operation.predecessor,
this.operation.salt,
)).to.be.equal(this.operation.id);
expect(
await this.mock.hashOperationBatch(
this.operation.targets,
this.operation.values,
this.operation.payloads,
this.operation.predecessor,
this.operation.salt,
),
).to.be.equal(this.operation.id);
});
});
describe('simple', function () {
@ -185,8 +160,9 @@ contract('TimelockController', function (accounts) {
const block = await web3.eth.getBlock(receipt.receipt.blockHash);
expect(await this.mock.getTimestamp(this.operation.id))
.to.be.bignumber.equal(web3.utils.toBN(block.timestamp).add(MINDELAY));
expect(await this.mock.getTimestamp(this.operation.id)).to.be.bignumber.equal(
web3.utils.toBN(block.timestamp).add(MINDELAY),
);
});
it('prevent overwriting active operation', async function () {
@ -392,8 +368,9 @@ contract('TimelockController', function (accounts) {
const block = await web3.eth.getBlock(receipt.receipt.blockHash);
expect(await this.mock.getTimestamp(this.operation.id))
.to.be.bignumber.equal(web3.utils.toBN(block.timestamp).add(MINDELAY));
expect(await this.mock.getTimestamp(this.operation.id)).to.be.bignumber.equal(
web3.utils.toBN(block.timestamp).add(MINDELAY),
);
});
it('prevent overwriting active operation', async function () {
@ -637,16 +614,8 @@ contract('TimelockController', function (accounts) {
it('partial execution', async function () {
const operation = genOperationBatch(
[
this.callreceivermock.address,
this.callreceivermock.address,
this.callreceivermock.address,
],
[
0,
0,
0,
],
[this.callreceivermock.address, this.callreceivermock.address, this.callreceivermock.address],
[0, 0, 0],
[
this.callreceivermock.contract.methods.mockFunction().encodeABI(),
this.callreceivermock.contract.methods.mockFunctionThrows().encodeABI(),
@ -724,10 +693,7 @@ contract('TimelockController', function (accounts) {
describe('maintenance', function () {
it('prevent unauthorized maintenance', async function () {
await expectRevert(
this.mock.updateDelay(0, { from: other }),
'TimelockController: caller must be timelock',
);
await expectRevert(this.mock.updateDelay(0, { from: other }), 'TimelockController: caller must be timelock');
});
it('timelock scheduled maintenance', async function () {
@ -889,14 +855,9 @@ contract('TimelockController', function (accounts) {
);
await time.increase(MINDELAY);
await expectRevert(
this.mock.execute(
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
{ from: executor },
),
this.mock.execute(operation.target, operation.value, operation.data, operation.predecessor, operation.salt, {
from: executor,
}),
'TimelockController: underlying transaction reverted',
);
});
@ -921,14 +882,9 @@ contract('TimelockController', function (accounts) {
);
await time.increase(MINDELAY);
await expectRevert(
this.mock.execute(
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
{ from: executor },
),
this.mock.execute(operation.target, operation.value, operation.data, operation.predecessor, operation.salt, {
from: executor,
}),
'TimelockController: underlying transaction reverted',
);
});
@ -953,14 +909,10 @@ contract('TimelockController', function (accounts) {
);
await time.increase(MINDELAY);
await expectRevert(
this.mock.execute(
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
{ from: executor, gas: '70000' },
),
this.mock.execute(operation.target, operation.value, operation.data, operation.predecessor, operation.salt, {
from: executor,
gas: '70000',
}),
'TimelockController: underlying transaction reverted',
);
});
@ -1025,14 +977,9 @@ contract('TimelockController', function (accounts) {
expect(await web3.eth.getBalance(this.callreceivermock.address)).to.be.bignumber.equal(web3.utils.toBN(0));
await expectRevert(
this.mock.execute(
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
{ from: executor },
),
this.mock.execute(operation.target, operation.value, operation.data, operation.predecessor, operation.salt, {
from: executor,
}),
'TimelockController: underlying transaction reverted',
);
@ -1064,14 +1011,9 @@ contract('TimelockController', function (accounts) {
expect(await web3.eth.getBalance(this.callreceivermock.address)).to.be.bignumber.equal(web3.utils.toBN(0));
await expectRevert(
this.mock.execute(
operation.target,
operation.value,
operation.data,
operation.predecessor,
operation.salt,
{ from: executor },
),
this.mock.execute(operation.target, operation.value, operation.data, operation.predecessor, operation.salt, {
from: executor,
}),
'TimelockController: underlying transaction reverted',
);