AccessManager tests consolidation (#4655)

This commit is contained in:
Ernesto García
2023-10-12 11:32:30 -06:00
committed by GitHub
parent b48d658228
commit 6383299d71
8 changed files with 843 additions and 713 deletions

View File

@ -0,0 +1,30 @@
const { artifacts } = require('hardhat');
function namespaceId(contractName) {
return `openzeppelin.storage.${contractName}`;
}
function namespaceLocation(id) {
const hashIdBN = web3.utils.toBN(web3.utils.keccak256(id)).subn(1); // keccak256(id) - 1
const hashIdHex = web3.utils.padLeft(web3.utils.numberToHex(hashIdBN), 64);
const mask = BigInt(web3.utils.padLeft('0x00', 64, 'f')); // ~0xff
return BigInt(web3.utils.keccak256(hashIdHex)) & mask;
}
function namespaceSlot(contractName, offset) {
try {
// Try to get the artifact paths, will throw if it doesn't exist
artifacts._getArtifactPathSync(`${contractName}Upgradeable`);
return offset + namespaceLocation(namespaceId(contractName));
} catch (_) {
return offset;
}
}
module.exports = {
namespaceSlot,
namespaceLocation,
namespaceId,
};