Replace revert strings with custom errors (#4261)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
Ernesto García
2023-06-12 17:41:52 -06:00
committed by GitHub
parent 08fd777f6d
commit b425a72240
138 changed files with 3220 additions and 1287 deletions

View File

@ -1,4 +1,5 @@
const { forward } = require('../helpers/time');
const { ProposalState } = require('./enums');
function zip(...args) {
return Array(Math.max(...args.map(array => array.length)))
@ -196,6 +197,44 @@ class GovernorHelper {
}
}
/**
* Encodes a list ProposalStates into a bytes32 representation where each bit enabled corresponds to
* the underlying position in the `ProposalState` enum. For example:
*
* 0x000...10000
* ^^^^^^------ ...
* ^----- Succeeded
* ^---- Defeated
* ^--- Canceled
* ^-- Active
* ^- Pending
*/
function proposalStatesToBitMap(proposalStates, options = {}) {
if (!Array.isArray(proposalStates)) {
proposalStates = [proposalStates];
}
const statesCount = Object.keys(ProposalState).length;
let result = 0;
const uniqueProposalStates = new Set(proposalStates.map(bn => bn.toNumber())); // Remove duplicates
for (const state of uniqueProposalStates) {
if (state < 0 || state >= statesCount) {
expect.fail(`ProposalState ${state} out of possible states (0...${statesCount}-1)`);
} else {
result |= 1 << state;
}
}
if (options.inverted) {
const mask = 2 ** statesCount - 1;
result = result ^ mask;
}
const hex = web3.utils.numberToHex(result);
return web3.utils.padLeft(hex, 64);
}
module.exports = {
GovernorHelper,
proposalStatesToBitMap,
};