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 tests and typechain + loop #613

Merged
merged 4 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 6 additions & 1 deletion packages/contracts/scripts/generate-typechain-osx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ async function generateTypechain(): Promise<void> {
}

const dirPath = path.dirname(filePath);
if (!excludedDirs.has(dirPath)) {

// Only arrange the contracts' paths in the current
// directory without previous versions.
const containsPrefix = Array.from(excludedDirs).some(prefix => dirPath.startsWith(prefix));

if (!containsPrefix) {
jsonFiles.push(filePath);
}
});
Expand Down
19 changes: 14 additions & 5 deletions packages/contracts/src/core/dao/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ contract DAO is
/// @notice Thrown when a function is removed but left to not corrupt the interface ID.
error FunctionRemoved();

/// @notice Thrown when initialize is called after it has already been executed.
error AlreadyInitialized();

/// @notice Emitted when a new DAO URI is set.
/// @param daoURI The new URI.
event NewURI(string daoURI);
Expand All @@ -137,6 +140,15 @@ contract DAO is
_reentrancyStatus = _NOT_ENTERED;
}

/// @notice This ensures that the initialize function cannot be called during the upgrade process.
modifier onlyCallAtInitialization() {
if (_getInitializedVersion() != 0) {
revert AlreadyInitialized();
}

_;
}

/// @notice Disables the initializers on the implementation contract to prevent it from being left uninitialized.
constructor() {
_disableInitializers();
Expand All @@ -157,7 +169,7 @@ contract DAO is
address _initialOwner,
address _trustedForwarder,
string calldata daoURI_
) external reinitializer(3) {
) external onlyCallAtInitialization reinitializer(3) {
_reentrancyStatus = _NOT_ENTERED; // added in v1.3.0

_registerInterface(type(IDAO).interfaceId);
Expand Down Expand Up @@ -274,8 +286,7 @@ contract DAO is
msg.data
);

for (uint256 i = 0; i < _actions.length; i++) {
// TODO: Merge this loop with the below one.
for (uint256 i = 0; i < _actions.length; ) {
Action calldata action = _actions[i];

bool isAllowed = hasExecutePermission;
Expand All @@ -298,9 +309,7 @@ contract DAO is
if (!isAllowed) {
revert Unauthorized(action.to, msg.sender, permissionId);
}
}

for (uint256 i = 0; i < _actions.length; ) {
bool success;
bytes memory data;

Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/test/core/dao/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('DAO', function () {
dummyAddress1,
daoExampleURI
)
).to.be.revertedWith('Initializable: contract is already initialized');
).to.be.revertedWithCustomError(dao, 'AlreadyInitialized');
});

it('initializes with the correct trusted forwarder', async () => {
Expand Down Expand Up @@ -449,7 +449,6 @@ describe('DAO', function () {

it('supports the `IDAO` interface', async () => {
const iface = IDAO__factory.createInterface();
expect(getInterfaceId(iface)).to.equal('0x9385547e'); // the interfaceID from IDAO v1.0.0
expect(await dao.supportsInterface(getInterfaceId(iface))).to.be.true;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ const EMPTY_DATA = '0x';

const ADDRESS_TWO = `0x${'00'.repeat(19)}02`;

const APPLY_TARGET_PERMISSION_ID = ethers.utils.id('APPLY_TARGET_PERMISSION');

describe('PluginSetupProcessor', function () {
let signers: SignerWithAddress[];
let psp: PluginSetupProcessor;
Expand Down Expand Up @@ -579,7 +581,7 @@ describe('PluginSetupProcessor', function () {
.withArgs(
targetDao.address,
psp.address,
'0xf40ef0af1ef5603c5d084dc17659d339ea90c8ff31545c1ffcadc8207aefa8af'
APPLY_TARGET_PERMISSION_ID
);
});

Expand Down Expand Up @@ -1165,7 +1167,7 @@ describe('PluginSetupProcessor', function () {
.withArgs(
targetDao.address,
psp.address,
'0xf40ef0af1ef5603c5d084dc17659d339ea90c8ff31545c1ffcadc8207aefa8af'
APPLY_TARGET_PERMISSION_ID
);
});

Expand Down Expand Up @@ -1827,7 +1829,7 @@ describe('PluginSetupProcessor', function () {
.withArgs(
targetDao.address,
psp.address,
'0xf40ef0af1ef5603c5d084dc17659d339ea90c8ff31545c1ffcadc8207aefa8af'
APPLY_TARGET_PERMISSION_ID
);
});

Expand Down
Loading