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 e65bb56
Showing 1 changed file with 30 additions and 30 deletions.
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

0 comments on commit e65bb56

Please sign in to comment.