-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
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); | ||
if(!success) { | ||
assembly { | ||
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); | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
}); |