Skip to content

Commit

Permalink
test: adapt reinitializer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heueristik committed Sep 22, 2023
1 parent 27b3d64 commit 6391ac6
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 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,7 +239,7 @@ 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);

Expand All @@ -252,14 +252,6 @@ describe('DAO', function () {
)
).toNumber()
).to.equal(0);
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
REENTRANCY_STATUS_SLOT_POSITION
)
).toNumber()
).to.equal(0);

// Call `initializeFrom` with version 1.2.0.
await expect(uninitializedDao.initializeFrom([1, 2, 0], EMPTY_DATA)).to
Expand All @@ -273,30 +265,45 @@ describe('DAO', function () {
OZ_INITIALIZED_SLOT_POSITION
)
).toNumber()
).to.equal(2);
).to.equal(3);
});

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(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
REENTRANCY_STATUS_SLOT_POSITION
)
).toNumber()
).to.equal(1);
});
).to.equal(0);

it('does not initialize `_reentrancyStatus` for versions >= 1.3.0', async () => {
// Create an unitialized DAO.
const uninitializedDao = await deployWithProxy<DAO>(DAO);
// 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 uninitialized with `_initialized = 0` and `_reentrancyStatus = 0`.
// Expect the contract to be initialized with `_reentrancyStatus = 1`.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
OZ_INITIALIZED_SLOT_POSITION
REENTRANCY_STATUS_SLOT_POSITION
)
).toNumber()
).to.equal(0);
).to.equal(1);
});

it('does not initialize `_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(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
Expand All @@ -310,15 +317,15 @@ 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 the contract to be initialized with `_initialized = 3` but `_reentrancyStatus` to remain unchanged.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
OZ_INITIALIZED_SLOT_POSITION
)
).toNumber()
).to.equal(2);
).to.equal(3);
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
Expand Down

0 comments on commit 6391ac6

Please sign in to comment.