Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
re-enable variant testing for mapping key
  • Loading branch information
Amxx committed Mar 18, 2024
commit 3f96b4ce9a2511e5516d0412f7473b5ea6b89225
6 changes: 3 additions & 3 deletions scripts/generate/templates/StorageSlot.opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const { capitalize } = require('../../helpers');
const TYPES = [
{ type: 'address', isValueType: true },
{ type: 'bool', isValueType: true, name: 'Boolean' },
{ type: 'bytes32', isValueType: true },
{ type: 'uint256', isValueType: true },
{ type: 'int256', isValueType: true },
{ type: 'bytes32', isValueType: true, variants: ['bytes4'] },
{ type: 'uint256', isValueType: true, variants: ['uint32'] },
{ type: 'int256', isValueType: true, variants: ['int32'] },
{ type: 'string', isValueType: false },
{ type: 'bytes', isValueType: false },
].map(type => Object.assign(type, { name: type.name ?? capitalize(type.type) }));
Expand Down
16 changes: 9 additions & 7 deletions scripts/generate/templates/StorageSlot.t.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const format = require('../format-lines');
const { capitalize } = require('../../helpers');
const { TYPES } = require('./StorageSlot.opts');

const header = `\
Expand All @@ -12,7 +13,7 @@ import {StorageSlot} from "@openzeppelin/contracts/utils/StorageSlot.sol";
const variable = ({ type, name }) => `\
${type} private _${type}Variable;

function testValue${name}1(${type} value) public {
function testValue${name}_1(${type} value) public {
bytes32 slot;
assembly {
slot := _${type}Variable.slot
Expand All @@ -25,7 +26,7 @@ function testValue${name}1(${type} value) public {
assertEq(slot.as${name}Slot().sload(), value);
}

function testValue${name}2(${type} value) public {
function testValue${name}_2(${type} value) public {
bytes32 slot;
assembly {
slot := _${type}Variable.slot
Expand All @@ -42,7 +43,7 @@ function testValue${name}2(${type} value) public {
const array = ({ type, name }) => `\
${type}[] private _${type}Array;

function testArray${name}1(${type}[] calldata values) public {
function testArray${name}_1(${type}[] calldata values) public {
bytes32 slot;
assembly {
slot := _${type}Array.slot
Expand All @@ -58,7 +59,7 @@ function testArray${name}1(${type}[] calldata values) public {
}
}

function testArray${name}2(${type}[] calldata values) public {
function testArray${name}_2(${type}[] calldata values) public {
bytes32 slot;
assembly {
slot := _${type}Array.slot
Expand All @@ -81,7 +82,7 @@ function testArray${name}2(${type}[] calldata values) public {
const mapping = ({ type, name }) => `\
mapping(${type} => uint256) private _${type}Mapping;

function testMapping${name}1(${type} key, uint256 value) public {
function testMapping${name}_1(${type} key, uint256 value) public {
bytes32 slot;
assembly {
slot := _${type}Mapping.slot
Expand All @@ -93,7 +94,7 @@ function testMapping${name}1(${type} key, uint256 value) public {
assertEq(slot.deriveMapping(key).asUint256Slot().sload(), value);
}

function testMapping${name}2(${type} key, uint256 value) public {
function testMapping${name}_2(${type} key, uint256 value) public {
bytes32 slot;
assembly {
slot := _${type}Mapping.slot
Expand All @@ -110,6 +111,7 @@ function testMapping${name}2(${type} key, uint256 value) public {
// GENERATE
module.exports = format(
header.trimEnd(),
'// solhint-disable func-name-mixedcase',
'contract StorageSlotTest is Test {',
'using StorageSlot for *;',
'',
Expand All @@ -120,7 +122,7 @@ module.exports = format(
TYPES.filter(type => type.isValueType).flatMap(type =>
[].concat(
mapping(type),
(type.variant ?? []).map(variant => mapping({ type: variant })),
(type.variants ?? []).map(variant => mapping({ type: variant, name: capitalize(variant) })),
),
),
'}',
Expand Down
Loading