From dc5cb2f7a0fce486ccb801975eb313843dc0b322 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 24 May 2023 09:56:53 +0200 Subject: [PATCH 1/3] Move the Checkpoints library to `utils/structs` --- .../governance/extensions/GovernorVotesQuorumFraction.sol | 2 +- contracts/governance/utils/Votes.sol | 2 +- contracts/token/ERC721/extensions/ERC721Consecutive.sol | 2 +- contracts/utils/{ => structs}/Checkpoints.sol | 6 +++--- scripts/generate/run.js | 4 ++-- scripts/generate/templates/Checkpoints.js | 4 ++-- scripts/generate/templates/Checkpoints.t.js | 2 +- test/utils/{ => structs}/Checkpoints.t.sol | 2 +- test/utils/{ => structs}/Checkpoints.test.js | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) rename contracts/utils/{ => structs}/Checkpoints.sol (99%) rename test/utils/{ => structs}/Checkpoints.t.sol (99%) rename test/utils/{ => structs}/Checkpoints.test.js (98%) diff --git a/contracts/governance/extensions/GovernorVotesQuorumFraction.sol b/contracts/governance/extensions/GovernorVotesQuorumFraction.sol index e103ea0bfac..d327b54440c 100644 --- a/contracts/governance/extensions/GovernorVotesQuorumFraction.sol +++ b/contracts/governance/extensions/GovernorVotesQuorumFraction.sol @@ -4,8 +4,8 @@ pragma solidity ^0.8.0; import "./GovernorVotes.sol"; -import "../../utils/Checkpoints.sol"; import "../../utils/math/SafeCast.sol"; +import "../../utils/structs/Checkpoints.sol"; /** * @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token and a quorum expressed as a diff --git a/contracts/governance/utils/Votes.sol b/contracts/governance/utils/Votes.sol index 7b752ad5d0f..d4e789d990f 100644 --- a/contracts/governance/utils/Votes.sol +++ b/contracts/governance/utils/Votes.sol @@ -5,8 +5,8 @@ pragma solidity ^0.8.0; import "../../interfaces/IERC5805.sol"; import "../../utils/Context.sol"; import "../../utils/Nonces.sol"; -import "../../utils/Checkpoints.sol"; import "../../utils/cryptography/EIP712.sol"; +import "../../utils/structs/Checkpoints.sol"; /** * @dev This is a base abstract contract that tracks voting units, which are a measure of voting power that can be diff --git a/contracts/token/ERC721/extensions/ERC721Consecutive.sol b/contracts/token/ERC721/extensions/ERC721Consecutive.sol index e1462c0c2ed..e1cf80483ae 100644 --- a/contracts/token/ERC721/extensions/ERC721Consecutive.sol +++ b/contracts/token/ERC721/extensions/ERC721Consecutive.sol @@ -5,8 +5,8 @@ pragma solidity ^0.8.1; import "../ERC721.sol"; import "../../../interfaces/IERC2309.sol"; -import "../../../utils/Checkpoints.sol"; import "../../../utils/structs/BitMaps.sol"; +import "../../../utils/structs/Checkpoints.sol"; /** * @dev Implementation of the ERC2309 "Consecutive Transfer Extension" as defined in diff --git a/contracts/utils/Checkpoints.sol b/contracts/utils/structs/Checkpoints.sol similarity index 99% rename from contracts/utils/Checkpoints.sol rename to contracts/utils/structs/Checkpoints.sol index aff54258546..8de17349143 100644 --- a/contracts/utils/Checkpoints.sol +++ b/contracts/utils/structs/Checkpoints.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.8.1) (utils/Checkpoints.sol) +// OpenZeppelin Contracts (last updated v4.8.1) (utils/structs/Checkpoints.sol) // This file was procedurally generated from scripts/generate/templates/Checkpoints.js. pragma solidity ^0.8.0; -import "./math/Math.sol"; -import "./math/SafeCast.sol"; +import "../math/Math.sol"; +import "../math/SafeCast.sol"; /** * @dev This library defines the `History` struct, for checkpointing values as they change at different points in diff --git a/scripts/generate/run.js b/scripts/generate/run.js index 368b53ad1ea..53589455ab5 100755 --- a/scripts/generate/run.js +++ b/scripts/generate/run.js @@ -35,7 +35,7 @@ for (const [file, template] of Object.entries({ 'utils/math/SafeCast.sol': './templates/SafeCast.js', 'utils/structs/EnumerableSet.sol': './templates/EnumerableSet.js', 'utils/structs/EnumerableMap.sol': './templates/EnumerableMap.js', - 'utils/Checkpoints.sol': './templates/Checkpoints.js', + 'utils/structs/Checkpoints.sol': './templates/Checkpoints.js', 'utils/StorageSlot.sol': './templates/StorageSlot.js', })) { generateFromTemplate(file, template, './contracts/'); @@ -43,7 +43,7 @@ for (const [file, template] of Object.entries({ // Tests for (const [file, template] of Object.entries({ - 'utils/Checkpoints.t.sol': './templates/Checkpoints.t.js', + 'utils/structs/Checkpoints.t.sol': './templates/Checkpoints.t.js', })) { generateFromTemplate(file, template, './test/'); } diff --git a/scripts/generate/templates/Checkpoints.js b/scripts/generate/templates/Checkpoints.js index de58ad19e3a..f339fde2268 100644 --- a/scripts/generate/templates/Checkpoints.js +++ b/scripts/generate/templates/Checkpoints.js @@ -5,8 +5,8 @@ const { OPTS } = require('./Checkpoints.opts.js'); const header = `\ pragma solidity ^0.8.0; -import "./math/Math.sol"; -import "./math/SafeCast.sol"; +import "../math/Math.sol"; +import "../math/SafeCast.sol"; /** * @dev This library defines the \`History\` struct, for checkpointing values as they change at different points in diff --git a/scripts/generate/templates/Checkpoints.t.js b/scripts/generate/templates/Checkpoints.t.js index 0451ecea442..3c8f2222363 100644 --- a/scripts/generate/templates/Checkpoints.t.js +++ b/scripts/generate/templates/Checkpoints.t.js @@ -7,8 +7,8 @@ const header = `\ pragma solidity ^0.8.0; import "forge-std/Test.sol"; -import "../../contracts/utils/Checkpoints.sol"; import "../../contracts/utils/math/SafeCast.sol"; +import "../../contracts/utils/structs/Checkpoints.sol"; `; /* eslint-disable max-len */ diff --git a/test/utils/Checkpoints.t.sol b/test/utils/structs/Checkpoints.t.sol similarity index 99% rename from test/utils/Checkpoints.t.sol rename to test/utils/structs/Checkpoints.t.sol index 12598da46e5..aca559b41eb 100644 --- a/test/utils/Checkpoints.t.sol +++ b/test/utils/structs/Checkpoints.t.sol @@ -4,8 +4,8 @@ pragma solidity ^0.8.0; import "forge-std/Test.sol"; -import "../../contracts/utils/Checkpoints.sol"; import "../../contracts/utils/math/SafeCast.sol"; +import "../../contracts/utils/structs/Checkpoints.sol"; contract CheckpointsTrace224Test is Test { using Checkpoints for Checkpoints.Trace224; diff --git a/test/utils/Checkpoints.test.js b/test/utils/structs/Checkpoints.test.js similarity index 98% rename from test/utils/Checkpoints.test.js rename to test/utils/structs/Checkpoints.test.js index d9fd2c8ea8a..ad95373a48a 100644 --- a/test/utils/Checkpoints.test.js +++ b/test/utils/structs/Checkpoints.test.js @@ -1,7 +1,7 @@ const { expectRevert } = require('@openzeppelin/test-helpers'); const { expect } = require('chai'); -const { VALUE_SIZES } = require('../../scripts/generate/templates/Checkpoints.opts.js'); +const { VALUE_SIZES } = require('../../../scripts/generate/templates/Checkpoints.opts.js'); const $Checkpoints = artifacts.require('$Checkpoints'); From db4a27a685b9b4a9561397a92d5a834d55d8e193 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 24 May 2023 09:58:51 +0200 Subject: [PATCH 2/3] add changeset --- .changeset/fresh-birds-kiss.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fresh-birds-kiss.md diff --git a/.changeset/fresh-birds-kiss.md b/.changeset/fresh-birds-kiss.md new file mode 100644 index 00000000000..221f54cdf48 --- /dev/null +++ b/.changeset/fresh-birds-kiss.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-solidity': major +--- + +`Checkpoints`: library moved from `utils` to `utils/structs` From eb1581847cc70d1cb9ece46f1972f140a8816161 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 24 May 2023 11:28:13 +0200 Subject: [PATCH 3/3] update import path for foundry tests --- scripts/generate/templates/Checkpoints.t.js | 4 ++-- test/utils/structs/Checkpoints.t.sol | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/generate/templates/Checkpoints.t.js b/scripts/generate/templates/Checkpoints.t.js index 3c8f2222363..2b8c7b67c4c 100644 --- a/scripts/generate/templates/Checkpoints.t.js +++ b/scripts/generate/templates/Checkpoints.t.js @@ -7,8 +7,8 @@ const header = `\ pragma solidity ^0.8.0; import "forge-std/Test.sol"; -import "../../contracts/utils/math/SafeCast.sol"; -import "../../contracts/utils/structs/Checkpoints.sol"; +import "../../../contracts/utils/math/SafeCast.sol"; +import "../../../contracts/utils/structs/Checkpoints.sol"; `; /* eslint-disable max-len */ diff --git a/test/utils/structs/Checkpoints.t.sol b/test/utils/structs/Checkpoints.t.sol index aca559b41eb..e3f4bd28bc0 100644 --- a/test/utils/structs/Checkpoints.t.sol +++ b/test/utils/structs/Checkpoints.t.sol @@ -4,8 +4,8 @@ pragma solidity ^0.8.0; import "forge-std/Test.sol"; -import "../../contracts/utils/math/SafeCast.sol"; -import "../../contracts/utils/structs/Checkpoints.sol"; +import "../../../contracts/utils/math/SafeCast.sol"; +import "../../../contracts/utils/structs/Checkpoints.sol"; contract CheckpointsTrace224Test is Test { using Checkpoints for Checkpoints.Trace224;