diff --git a/contracts/contracts/Imports.sol b/contracts/contracts/Imports.sol index b669970..205b329 100644 --- a/contracts/contracts/Imports.sol +++ b/contracts/contracts/Imports.sol @@ -3,7 +3,6 @@ pragma solidity ^0.8.18; // Import the contract so hardhat compiles it, and we have the ABI available import {MockContract} from "@safe-global/mock-contract/contracts/MockContract.sol"; -import {TestSafeProtocolRegistryUnrestricted} from "@safe-global/safe-core-protocol/contracts/test/TestSafeProtocolRegistryUnrestricted.sol"; // ExecutableMockContract for testing diff --git a/contracts/contracts/RecoveryWithDelayPlugin.sol b/contracts/contracts/RecoveryWithDelayPlugin.sol index f7f0df0..fae79c4 100644 --- a/contracts/contracts/RecoveryWithDelayPlugin.sol +++ b/contracts/contracts/RecoveryWithDelayPlugin.sol @@ -1,10 +1,9 @@ // SPDX-License-Identifier: LGPL-3.0-only pragma solidity ^0.8.18; import {ISafe} from "@safe-global/safe-core-protocol/contracts/interfaces/Accounts.sol"; -import {ISafeProtocolPlugin} from "@safe-global/safe-core-protocol/contracts/interfaces/Integrations.sol"; import {ISafeProtocolManager} from "@safe-global/safe-core-protocol/contracts/interfaces/Manager.sol"; import {BasePluginWithEventMetadata, PluginMetadata} from "./Base.sol"; -import {SafeTransaction, SafeRootAccess, SafeProtocolAction} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol"; +import { SafeRootAccess, SafeProtocolAction} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol"; /** * @title RecoveryWithDelayPlugin - A contract compatible with Safe{Core} Protocol that replaces a specified owner for a Safe by a non-owner account. diff --git a/contracts/contracts/WhitelistPlugin.sol b/contracts/contracts/WhitelistPlugin.sol index 1a2b0aa..f51e245 100644 --- a/contracts/contracts/WhitelistPlugin.sol +++ b/contracts/contracts/WhitelistPlugin.sol @@ -1,9 +1,8 @@ // SPDX-License-Identifier: LGPL-3.0-only pragma solidity ^0.8.18; import {ISafe} from "@safe-global/safe-core-protocol/contracts/interfaces/Accounts.sol"; -import {ISafeProtocolPlugin} from "@safe-global/safe-core-protocol/contracts/interfaces/Integrations.sol"; import {ISafeProtocolManager} from "@safe-global/safe-core-protocol/contracts/interfaces/Manager.sol"; -import {SafeTransaction, SafeRootAccess, SafeProtocolAction} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol"; +import {SafeTransaction, SafeProtocolAction} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol"; import {BasePluginWithEventMetadata, PluginMetadata} from "./Base.sol"; /** diff --git a/contracts/src/tasks/test_registry.ts b/contracts/src/tasks/test_registry.ts index 5f58e12..b01b086 100644 --- a/contracts/src/tasks/test_registry.ts +++ b/contracts/src/tasks/test_registry.ts @@ -1,7 +1,7 @@ import "hardhat-deploy"; import "@nomicfoundation/hardhat-ethers"; import { task } from "hardhat/config"; -import { getPlugin, getRegistry, getRelayPlugin } from "../utils/contracts"; +import { getPlugin, getRegistry, getRelayPlugin } from "../../test/utils/contracts"; import { IntegrationType } from "../utils/constants"; import { loadPluginMetadata } from "../utils/metadata"; diff --git a/contracts/src/utils/metadata.ts b/contracts/src/utils/metadata.ts index b85504a..ceb31cc 100644 --- a/contracts/src/utils/metadata.ts +++ b/contracts/src/utils/metadata.ts @@ -1,6 +1,6 @@ import { AbiCoder, Interface, isHexString, keccak256 } from "ethers"; import { BasePlugin, IMetadataProvider } from "../../typechain-types"; -import { getInstance } from "../utils/contracts"; +import { getInstance } from "../../test/utils/contracts"; import { HardhatRuntimeEnvironment } from "hardhat/types"; interface PluginMetadata { diff --git a/contracts/src/utils/protocol.ts b/contracts/src/utils/protocol.ts index 8eac372..eda9363 100644 --- a/contracts/src/utils/protocol.ts +++ b/contracts/src/utils/protocol.ts @@ -1,8 +1,8 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; -import protocolDeployments from "@safe-global/safe-core-protocol" +import protocolDeployments from "@safe-global/safe-core-protocol"; import { id } from "ethers"; -const deployMock = async(hre: HardhatRuntimeEnvironment, name: string): Promise => { +const deployMock = async (hre: HardhatRuntimeEnvironment, name: string): Promise => { const { deployments, getNamedAccounts } = hre; const { deployer } = await getNamedAccounts(); const { deploy } = deployments; @@ -13,30 +13,30 @@ const deployMock = async(hre: HardhatRuntimeEnvironment, name: string): Promise< log: true, deterministicDeployment: id(name), }); - return result.address -} + return result.address; +}; -export const getProtocolManagerAddress = async(hre: HardhatRuntimeEnvironment): Promise => { - const chainId = await hre.getChainId() +export const getProtocolManagerAddress = async (hre: HardhatRuntimeEnvironment): Promise => { + const chainId = await hre.getChainId(); // For the tests we deploy a mock for the manager - if (chainId === "31337") return deployMock(hre, "ManagerMock") - - if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain") - const manager = (protocolDeployments as any)[chainId][0].contracts.SafeProtocolManager.address - if (typeof manager !== "string") throw Error("Unexpected Manager") - return manager -} + if (chainId === "31337") return deployMock(hre, "ManagerMock"); -export const getProtocolRegistryAddress = async(hre: HardhatRuntimeEnvironment): Promise => { - const chainId = await hre.getChainId() + if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain"); + const manager = (protocolDeployments as any)[chainId][0].contracts.SafeProtocolManager.address; + if (typeof manager !== "string") throw Error("Unexpected Manager"); + return manager; +}; + +export const getProtocolRegistryAddress = async (hre: HardhatRuntimeEnvironment): Promise => { + const chainId = await hre.getChainId(); // For the tests we deploy a mock for the registry - if (chainId === "31337") return deployMock(hre, "RegistryMock") - - if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain") + if (chainId === "31337") return deployMock(hre, "RegistryMock"); + + if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain"); // We use the unrestricted registry for the demo - const registry = (protocolDeployments as any)[chainId][0].contracts.TestSafeProtocolRegistryUnrestricted.address - if (typeof registry !== "string") throw Error("Unexpected Registry") - return registry -} \ No newline at end of file + const registry = (protocolDeployments as any)[chainId][0].contracts.TestSafeProtocolRegistryUnrestricted.address; + if (typeof registry !== "string") throw Error("Unexpected Registry"); + return registry; +}; diff --git a/contracts/test/RecoveryWithDelayPlugin.spec.ts b/contracts/test/RecoveryWithDelayPlugin.spec.ts index c401eb3..4aa2d45 100644 --- a/contracts/test/RecoveryWithDelayPlugin.spec.ts +++ b/contracts/test/RecoveryWithDelayPlugin.spec.ts @@ -1,7 +1,7 @@ import hre, { deployments, ethers } from "hardhat"; import { expect } from "chai"; import { getProtocolManagerAddress } from "../src/utils/protocol"; -import { getRecoveryWithDelayPlugin } from "../src/utils/contracts"; +import { getRecoveryWithDelayPlugin } from "./utils/contracts"; import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; import { ISafeProtocolManager__factory } from "../typechain-types"; import { SafeProtocolAction, SafeRootAccess } from "../src/utils/dataTypes"; diff --git a/contracts/test/RelayPlugin.spec.ts b/contracts/test/RelayPlugin.spec.ts index b94d5f2..6f73b9d 100644 --- a/contracts/test/RelayPlugin.spec.ts +++ b/contracts/test/RelayPlugin.spec.ts @@ -1,7 +1,7 @@ import hre, { deployments, ethers } from "hardhat"; import { expect } from "chai"; import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; -import { getRelayPlugin } from "../src/utils/contracts"; +import { getRelayPlugin } from "./utils/contracts"; import { loadPluginMetadata } from "../src/utils/metadata"; import { getProtocolManagerAddress } from "../src/utils/protocol"; import { Interface, MaxUint256, ZeroAddress, ZeroHash, getAddress, keccak256 } from "ethers"; diff --git a/contracts/test/WhitelistPlugin.spec.ts b/contracts/test/WhitelistPlugin.spec.ts index 3385ddb..b21cee8 100644 --- a/contracts/test/WhitelistPlugin.spec.ts +++ b/contracts/test/WhitelistPlugin.spec.ts @@ -1,7 +1,7 @@ import hre, { deployments, ethers } from "hardhat"; import { expect } from "chai"; import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; -import { getWhiteListPlugin, getInstance } from "../src/utils/contracts"; +import { getWhiteListPlugin, getInstance } from "./utils/contracts"; import { loadPluginMetadata } from "../src/utils/metadata"; import { buildSingleTx } from "../src/utils/builder"; import { ISafeProtocolManager__factory, MockContract } from "../typechain-types"; diff --git a/contracts/src/utils/contracts.ts b/contracts/test/utils/contracts.ts similarity index 56% rename from contracts/src/utils/contracts.ts rename to contracts/test/utils/contracts.ts index f64eb43..3efa608 100644 --- a/contracts/src/utils/contracts.ts +++ b/contracts/test/utils/contracts.ts @@ -1,9 +1,19 @@ import { Addressable, BaseContract } from "ethers"; -import { BasePlugin, RecoveryWithDelayPlugin, RelayPlugin, TestSafeProtocolRegistryUnrestricted, WhitelistPlugin } from "../../typechain-types"; +import { + BasePlugin, + RecoveryWithDelayPlugin, + RelayPlugin, + TestSafeProtocolRegistryUnrestricted, + WhitelistPlugin, +} from "../../typechain-types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { getProtocolManagerAddress, getProtocolRegistryAddress } from "./protocol"; +import { getProtocolRegistryAddress } from "../../src/utils/protocol"; -export const getInstance = async (hre: HardhatRuntimeEnvironment, name: string, address: string | Addressable): Promise => { +export const getInstance = async ( + hre: HardhatRuntimeEnvironment, + name: string, + address: string | Addressable, +): Promise => { // TODO: this typecasting should be refactored return (await hre.ethers.getContractAt(name, address)) as unknown as T; }; @@ -15,6 +25,8 @@ export const getSingleton = async (hre: HardhatRuntimeEn export const getPlugin = (hre: HardhatRuntimeEnvironment, address: string) => getInstance(hre, "BasePlugin", address); export const getRelayPlugin = (hre: HardhatRuntimeEnvironment) => getSingleton(hre, "RelayPlugin"); -export const getRegistry = async (hre: HardhatRuntimeEnvironment) => getInstance(hre, "TestSafeProtocolRegistryUnrestricted", await getProtocolRegistryAddress(hre)); +export const getRegistry = async (hre: HardhatRuntimeEnvironment) => + getInstance(hre, "TestSafeProtocolRegistryUnrestricted", await getProtocolRegistryAddress(hre)); export const getWhiteListPlugin = async (hre: HardhatRuntimeEnvironment) => getSingleton(hre, "WhitelistPlugin"); -export const getRecoveryWithDelayPlugin= async(hre: HardhatRuntimeEnvironment) => getSingleton(hre, "RecoveryWithDelayPlugin"); +export const getRecoveryWithDelayPlugin = async (hre: HardhatRuntimeEnvironment) => + getSingleton(hre, "RecoveryWithDelayPlugin");