Skip to content

Commit c5d8db6

Browse files
authored
fix tests and typechain + loop (#613)
* fix tests and typechain + loop * remove comments * add back vscode files * interface fixed
1 parent 0e070da commit c5d8db6

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

packages/contracts/scripts/generate-typechain-osx.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ async function generateTypechain(): Promise<void> {
2828
}
2929

3030
const dirPath = path.dirname(filePath);
31-
if (!excludedDirs.has(dirPath)) {
31+
32+
// Only arrange the contracts' paths in the current
33+
// directory without previous versions.
34+
const containsPrefix = Array.from(excludedDirs).some(prefix => dirPath.startsWith(prefix));
35+
36+
if (!containsPrefix) {
3237
jsonFiles.push(filePath);
3338
}
3439
});

packages/contracts/src/core/dao/DAO.sol

+18-5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ contract DAO is
120120
/// @notice Thrown when a function is removed but left to not corrupt the interface ID.
121121
error FunctionRemoved();
122122

123+
/// @notice Thrown when initialize is called after it has already been executed.
124+
error AlreadyInitialized();
125+
123126
/// @notice Emitted when a new DAO URI is set.
124127
/// @param daoURI The new URI.
125128
event NewURI(string daoURI);
@@ -137,6 +140,15 @@ contract DAO is
137140
_reentrancyStatus = _NOT_ENTERED;
138141
}
139142

143+
/// @notice This ensures that the initialize function cannot be called during the upgrade process.
144+
modifier onlyCallAtInitialization() {
145+
if (_getInitializedVersion() != 0) {
146+
revert AlreadyInitialized();
147+
}
148+
149+
_;
150+
}
151+
140152
/// @notice Disables the initializers on the implementation contract to prevent it from being left uninitialized.
141153
constructor() {
142154
_disableInitializers();
@@ -157,9 +169,12 @@ contract DAO is
157169
address _initialOwner,
158170
address _trustedForwarder,
159171
string calldata daoURI_
160-
) external reinitializer(3) {
172+
) external onlyCallAtInitialization reinitializer(3) {
161173
_reentrancyStatus = _NOT_ENTERED; // added in v1.3.0
162174

175+
// In addition to the current interfaceId, also support previous version of the interfaceId.
176+
_registerInterface(type(IDAO).interfaceId ^ IExecutor.execute.selector);
177+
163178
_registerInterface(type(IDAO).interfaceId);
164179
_registerInterface(type(IExecutor).interfaceId);
165180
_registerInterface(type(IERC1271).interfaceId);
@@ -202,6 +217,7 @@ contract DAO is
202217
_permissionId: keccak256("SET_SIGNATURE_VALIDATOR_PERMISSION")
203218
});
204219

220+
_registerInterface(type(IDAO).interfaceId);
205221
_registerInterface(type(IExecutor).interfaceId);
206222
}
207223
}
@@ -274,8 +290,7 @@ contract DAO is
274290
msg.data
275291
);
276292

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

281296
bool isAllowed = hasExecutePermission;
@@ -298,9 +313,7 @@ contract DAO is
298313
if (!isAllowed) {
299314
revert Unauthorized(action.to, msg.sender, permissionId);
300315
}
301-
}
302316

303-
for (uint256 i = 0; i < _actions.length; ) {
304317
bool success;
305318
bytes memory data;
306319

packages/contracts/test/core/dao/dao.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe('DAO', function () {
147147
dummyAddress1,
148148
daoExampleURI
149149
)
150-
).to.be.revertedWith('Initializable: contract is already initialized');
150+
).to.be.revertedWithCustomError(dao, 'AlreadyInitialized');
151151
});
152152

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

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

packages/contracts/test/framework/plugin/plugin-setup-processor.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ const EMPTY_DATA = '0x';
109109

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

112+
const APPLY_TARGET_PERMISSION_ID = ethers.utils.id('APPLY_TARGET_PERMISSION');
113+
112114
describe('PluginSetupProcessor', function () {
113115
let signers: SignerWithAddress[];
114116
let psp: PluginSetupProcessor;
@@ -579,7 +581,7 @@ describe('PluginSetupProcessor', function () {
579581
.withArgs(
580582
targetDao.address,
581583
psp.address,
582-
'0xf40ef0af1ef5603c5d084dc17659d339ea90c8ff31545c1ffcadc8207aefa8af'
584+
APPLY_TARGET_PERMISSION_ID
583585
);
584586
});
585587

@@ -1165,7 +1167,7 @@ describe('PluginSetupProcessor', function () {
11651167
.withArgs(
11661168
targetDao.address,
11671169
psp.address,
1168-
'0xf40ef0af1ef5603c5d084dc17659d339ea90c8ff31545c1ffcadc8207aefa8af'
1170+
APPLY_TARGET_PERMISSION_ID
11691171
);
11701172
});
11711173

@@ -1827,7 +1829,7 @@ describe('PluginSetupProcessor', function () {
18271829
.withArgs(
18281830
targetDao.address,
18291831
psp.address,
1830-
'0xf40ef0af1ef5603c5d084dc17659d339ea90c8ff31545c1ffcadc8207aefa8af'
1832+
APPLY_TARGET_PERMISSION_ID
18311833
);
18321834
});
18331835

0 commit comments

Comments
 (0)