Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: forgotten reinitializer bump #469

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions packages/contracts/src/core/dao/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ contract DAO is
address _initialOwner,
address _trustedForwarder,
string calldata daoURI_
) external reinitializer(2) {
) external reinitializer(3) {
_reentrancyStatus = _NOT_ENTERED; // added in v1.3.0

_registerInterface(type(IDAO).interfaceId);
Expand All @@ -173,7 +173,7 @@ contract DAO is
function initializeFrom(
uint8[3] calldata _previousProtocolVersion,
bytes calldata _initData
) external reinitializer(2) {
) external reinitializer(3) {
_initData; // Silences the unused function parameter warning.

// Check that the contract is not upgrading from a different major release.
Expand Down
60 changes: 30 additions & 30 deletions packages/contracts/test/core/dao/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ describe('DAO', function () {
);
});

it('sets OZs `_initialized` at storage slot [0] to 2', async () => {
it('sets OZs `_initialized` at storage slot [0] to 3', async () => {
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
dao.address,
OZ_INITIALIZED_SLOT_POSITION
)
).toNumber()
).to.equal(2);
).to.equal(3);
});

it('sets the `_reentrancyStatus` at storage slot [304] to `_NOT_ENTERED = 1`', async () => {
Expand All @@ -239,11 +239,11 @@ describe('DAO', function () {
.withArgs([0, 1, 0]);
});

it('initializes `_reentrancyStatus` for versions < 1.3.0', async () => {
it('increments `_initialized` to `3`', async () => {
// Create an unitialized DAO.
const uninitializedDao = await deployWithProxy<DAO>(DAO);

// Expect the contract to be uninitialized with `_initialized = 0` and `_reentrancyStatus = 0`.
// Expect the contract to be uninitialized with `_initialized = 0`.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
Expand All @@ -252,28 +252,42 @@ describe('DAO', function () {
)
).toNumber()
).to.equal(0);

// Call `initializeFrom` with version 1.2.0.
await expect(uninitializedDao.initializeFrom([1, 2, 0], EMPTY_DATA)).to
.not.be.reverted;

// Expect the contract to be initialized with `_initialized = 3`.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
REENTRANCY_STATUS_SLOT_POSITION
OZ_INITIALIZED_SLOT_POSITION
)
).toNumber()
).to.equal(0);
).to.equal(3);
});

// Call `initializeFrom` with version 1.2.0.
await expect(uninitializedDao.initializeFrom([1, 2, 0], EMPTY_DATA)).to
.not.be.reverted;
it('initializes `_reentrancyStatus` for versions < 1.3.0', async () => {
// Create an unitialized DAO.
const uninitializedDao = await deployWithProxy<DAO>(DAO);

// Expect the contract to be uninitialized with `_reentrancyStatus = 0`.

// Expect the contract to be initialized with `_initialized = 2` and `_reentrancyStatus = 1`.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
OZ_INITIALIZED_SLOT_POSITION
REENTRANCY_STATUS_SLOT_POSITION
)
).toNumber()
).to.equal(2);
).to.equal(0);

// Call `initializeFrom` with version 1.2.0.
await expect(uninitializedDao.initializeFrom([1, 2, 0], EMPTY_DATA)).to
.not.be.reverted;

// Expect the contract to be initialized with `_reentrancyStatus = 1`.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
Expand All @@ -288,15 +302,8 @@ describe('DAO', function () {
// Create an unitialized DAO.
const uninitializedDao = await deployWithProxy<DAO>(DAO);

// Expect the contract to be uninitialized with `_initialized = 0` and `_reentrancyStatus = 0`.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
OZ_INITIALIZED_SLOT_POSITION
)
).toNumber()
).to.equal(0);
// Expect the contract to be uninitialized with `_reentrancyStatus = 0`.

expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
Expand All @@ -310,15 +317,8 @@ describe('DAO', function () {
await expect(uninitializedDao.initializeFrom([1, 3, 0], EMPTY_DATA)).to
.not.be.reverted;

// Expect the contract to be initialized with `_initialized = 2` but `_reentrancyStatus` to remain unchanged.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
OZ_INITIALIZED_SLOT_POSITION
)
).toNumber()
).to.equal(2);
// Expect `_reentrancyStatus` to remain unchanged.

expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
Expand Down
Loading