Skip to content

Commit

Permalink
[#4] Setup TestExecutor contract
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Jun 20, 2023
1 parent 22338ec commit 81efd68
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
8 changes: 8 additions & 0 deletions contracts/interfaces/Accounts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ pragma solidity ^0.8.18;
* @title ISafe Declares the functions that are called on a Safe by Safe protocol.
*/
interface ISafe {

Check failure on line 8 in contracts/interfaces/Accounts.sol

View workflow job for this annotation

GitHub Actions / lint

Delete ⏎····
function setModule(address _module) external;

function execTransactionFromModule(
address payable to,
uint256 value,
bytes calldata data,
uint8 operation
) external returns (bool success);
}
35 changes: 35 additions & 0 deletions contracts/test/TestExecutor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0;
import {ISafe} from "../interfaces/Accounts.sol";

contract TestExecutor is ISafe {
address public module;
address[] public owners;


Check failure on line 9 in contracts/test/TestExecutor.sol

View workflow job for this annotation

GitHub Actions / lint

Delete ⏎
function setModule(address _module) external {
module = _module;
}

function exec(address payable to, uint256 value, bytes calldata data) external {
bool success;
bytes memory response;
(success,response) = to.call{value: value}(data);

Check failure on line 17 in contracts/test/TestExecutor.sol

View workflow job for this annotation

GitHub Actions / lint

Insert ·
if(!success) {

Check failure on line 18 in contracts/test/TestExecutor.sol

View workflow job for this annotation

GitHub Actions / lint

Insert ·
assembly {

Check warning on line 19 in contracts/test/TestExecutor.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use inline assembly. It is acceptable only in rare cases
revert(add(response, 0x20), mload(response))
}
}
}

function execTransactionFromModule(
address payable to,
uint256 value,
bytes calldata data,
uint8 operation
) external returns (bool success) {
require(msg.sender == module, "Not authorized");
if (operation == 1) (success, ) = to.delegatecall(data);
else (success, ) = to.call{value: value}(data);
}
}

Check failure on line 35 in contracts/test/TestExecutor.sol

View workflow job for this annotation

GitHub Actions / lint

Insert ⏎
21 changes: 21 additions & 0 deletions test/SafeProtocolMediator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import hre from "hardhat";
import { loadFixture, time } from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { expect } from "chai";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";

describe("SafeProtocolMediator", async () => {
let deployer: SignerWithAddress, owner: SignerWithAddress, user1: SignerWithAddress, user2: SignerWithAddress;

async function deployContractFixture() {
[deployer, owner, user1, user2]= await hre.ethers.getSigners();
const safeProtocolMediator = await (await hre.ethers.getContractFactory("SafeProtocolMediator")).deploy(owner.address);
return { safeProtocolMediator };
}

it.only("Should set mediator as a module for a safe", async () => {
const safe = await hre.ethers.deployContract("TestExecutor");

const { safeProtocolMediator } = await loadFixture(deployContractFixture);
await safe.setModule(await safeProtocolMediator.getAddress());
});
});

0 comments on commit 81efd68

Please sign in to comment.