Refactor enumerableMap generate and tests (#4760)

This commit is contained in:
Renan Souza
2023-11-28 23:41:10 +00:00
committed by GitHub
parent 769071d473
commit e0ac73cd6e
4 changed files with 95 additions and 137 deletions

View File

@ -1,12 +1,6 @@
const format = require('../format-lines');
const { fromBytes32, toBytes32 } = require('./conversion');
const TYPES = [
{ name: 'UintToUintMap', keyType: 'uint256', valueType: 'uint256' },
{ name: 'UintToAddressMap', keyType: 'uint256', valueType: 'address' },
{ name: 'AddressToUintMap', keyType: 'address', valueType: 'uint256' },
{ name: 'Bytes32ToUintMap', keyType: 'bytes32', valueType: 'uint256' },
];
const { TYPES } = require('./EnumerableMap.opts');
/* eslint-disable max-len */
const header = `\

View File

@ -0,0 +1,18 @@
const mapType = str => (str == 'uint256' ? 'Uint' : `${str.charAt(0).toUpperCase()}${str.slice(1)}`);
const formatType = (keyType, valueType) => ({
name: `${mapType(keyType)}To${mapType(valueType)}Map`,
keyType,
valueType,
});
const TYPES = [
['uint256', 'uint256'],
['uint256', 'address'],
['address', 'uint256'],
['bytes32', 'uint256'],
].map(args => formatType(...args));
module.exports = {
TYPES,
formatType,
};