Transpile 7bce2b72

This commit is contained in:
github-actions
2022-01-13 23:13:57 +00:00
commit 37c366503e
465 changed files with 80758 additions and 0 deletions

21
test/helpers/eip712.js Normal file
View File

@ -0,0 +1,21 @@
const ethSigUtil = require('eth-sig-util');
const EIP712Domain = [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
];
async function domainSeparator (name, version, chainId, verifyingContract) {
return '0x' + ethSigUtil.TypedDataUtils.hashStruct(
'EIP712Domain',
{ name, version, chainId, verifyingContract },
{ EIP712Domain },
).toString('hex');
}
module.exports = {
EIP712Domain,
domainSeparator,
};

24
test/helpers/enums.js Normal file
View File

@ -0,0 +1,24 @@
const { BN } = require('@openzeppelin/test-helpers');
function Enum (...options) {
return Object.fromEntries(options.map((key, i) => [ key, new BN(i) ]));
}
module.exports = {
Enum,
ProposalState: Enum(
'Pending',
'Active',
'Canceled',
'Defeated',
'Succeeded',
'Queued',
'Expired',
'Executed',
),
VoteType: Enum(
'Against',
'For',
'Abstain',
),
};

24
test/helpers/erc1967.js Normal file
View File

@ -0,0 +1,24 @@
const ImplementationLabel = 'eip1967.proxy.implementation';
const AdminLabel = 'eip1967.proxy.admin';
const BeaconLabel = 'eip1967.proxy.beacon';
function labelToSlot (label) {
return '0x' + web3.utils.toBN(web3.utils.keccak256(label)).subn(1).toString(16);
}
function getSlot (address, slot) {
return web3.eth.getStorageAt(
web3.utils.isAddress(address) ? address : address.address,
web3.utils.isHex(slot) ? slot : labelToSlot(slot),
);
}
module.exports = {
ImplementationLabel,
AdminLabel,
BeaconLabel,
ImplementationSlot: labelToSlot(ImplementationLabel),
AdminSlot: labelToSlot(AdminLabel),
BeaconSlot: labelToSlot(BeaconLabel),
getSlot,
};

47
test/helpers/sign.js Normal file
View File

@ -0,0 +1,47 @@
function toEthSignedMessageHash (messageHex) {
const messageBuffer = Buffer.from(messageHex.substring(2), 'hex');
const prefix = Buffer.from(`\u0019Ethereum Signed Message:\n${messageBuffer.length}`);
return web3.utils.sha3(Buffer.concat([prefix, messageBuffer]));
}
/**
* Create a signer between a contract and a signer for a voucher of method, args, and redeemer
* Note that `method` is the web3 method, not the truffle-contract method
* @param contract TruffleContract
* @param signer address
* @param redeemer address
* @param methodName string
* @param methodArgs any[]
*/
const getSignFor = (contract, signer) => (redeemer, methodName, methodArgs = []) => {
const parts = [
contract.address,
redeemer,
];
const REAL_SIGNATURE_SIZE = 2 * 65; // 65 bytes in hexadecimal string length
const PADDED_SIGNATURE_SIZE = 2 * 96; // 96 bytes in hexadecimal string length
const DUMMY_SIGNATURE = `0x${web3.utils.padLeft('', REAL_SIGNATURE_SIZE)}`;
// if we have a method, add it to the parts that we're signing
if (methodName) {
if (methodArgs.length > 0) {
parts.push(
contract.contract.methods[methodName](...methodArgs.concat([DUMMY_SIGNATURE])).encodeABI()
.slice(0, -1 * PADDED_SIGNATURE_SIZE),
);
} else {
const abi = contract.abi.find(abi => abi.name === methodName);
parts.push(abi.signature);
}
}
// return the signature of the "Ethereum Signed Message" hash of the hash of `parts`
const messageHex = web3.utils.soliditySha3(...parts);
return web3.eth.sign(messageHex, signer);
};
module.exports = {
toEthSignedMessageHash,
getSignFor,
};