Skip to content

Commit

Permalink
fix tests and typechain + loop
Browse files Browse the repository at this point in the history
  • Loading branch information
novaknole committed Sep 27, 2024
1 parent 0e070da commit 4aac22c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
8 changes: 0 additions & 8 deletions .vscode/extensions.json

This file was deleted.

11 changes: 2 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"prettier.documentSelectors": ["**/*.sol"],
"solidity.formatter": "prettier",
"editor.tabSize": 4,
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
"solidity.defaultCompiler": "remote"
}
9 changes: 8 additions & 1 deletion packages/contracts/scripts/generate-typechain-osx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ async function generateTypechain(): Promise<void> {
excludedDirs.add(path.join(artifactsDir, OSX_VERSION_ALIASES[i]));
}

console.log(excludedDirs)

const jsonFiles: string[] = [];

console.log('Searching for files...');
Expand All @@ -28,7 +30,11 @@ 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 All @@ -37,6 +43,7 @@ async function generateTypechain(): Promise<void> {

const filesArg = jsonFiles.join(' ');

// console.log(filesArg, ' kk')
if (filesArg) {
await execPromise(
`typechain --target ethers-v5 --out-dir ./typechain ${filesArg}`
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

0 comments on commit 4aac22c

Please sign in to comment.