Skip to content

Commit

Permalink
fix tests and typechain + loop (#613)
Browse files Browse the repository at this point in the history
* fix tests and typechain + loop

* remove comments

* add back vscode files

* interface fixed
  • Loading branch information
novaknole authored Sep 29, 2024
1 parent 0e070da commit c5d8db6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
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
23 changes: 18 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,9 +169,12 @@ 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

// In addition to the current interfaceId, also support previous version of the interfaceId.
_registerInterface(type(IDAO).interfaceId ^ IExecutor.execute.selector);

_registerInterface(type(IDAO).interfaceId);
_registerInterface(type(IExecutor).interfaceId);
_registerInterface(type(IERC1271).interfaceId);
Expand Down Expand Up @@ -202,6 +217,7 @@ contract DAO is
_permissionId: keccak256("SET_SIGNATURE_VALIDATOR_PERMISSION")
});

_registerInterface(type(IDAO).interfaceId);
_registerInterface(type(IExecutor).interfaceId);
}
}
Expand Down Expand Up @@ -274,8 +290,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 +313,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

0 comments on commit c5d8db6

Please sign in to comment.