Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: research delegation of task to factory - failed #101

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/RoboSaverVirtualModuleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ contract RoboSaverVirtualModuleFactory is
EXTERNAL METHODS
//////////////////////////////////////////////////////////////////////////*/

/// @dev wip - on r&d phase
function installation(address _delayModule) external {
bytes memory payload = abi.encodeWithSignature("enableModule(address)", address(this));
// allow the factory to be a vmod, queue tx since it is not owner
(bool success,) = _delayModule.delegatecall(
abi.encodeWithSignature(
"execTransactionFromModule(address,uint256,bytes,uint8)", _delayModule, 0, payload, 1
)
);
// catch revert early on the r&d
require(success, "Factory: installation queue failed!");
}

/// @notice Creates a virtual module for a card
/// @param _delayModule The address of the delay module
/// @param _rolesModule The address of the roles module
Expand Down
3 changes: 3 additions & 0 deletions test/BaseFixture.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ contract BaseFixture is Test, Constants {

delayModule.enableModule(address(roboModule));
delayModule.enableModule(address(safe));
// eoa also should be a module here for setup replication
delayModule.enableModule(SAFE_EOA_SIGNER);

safe.enableModule(address(delayModule));
safe.enableModule(address(rolesModule));
Expand Down Expand Up @@ -114,6 +116,7 @@ contract BaseFixture is Test, Constants {

/// @dev Labels key contracts for tracing
function _labelKeyContracts() internal {
vm.label(SAFE_EOA_SIGNER, "SAFE_EOA_SIGNER");
vm.label(address(safe), "GNOSIS_SAFE");
// robosaver module factory
vm.label(address(roboModuleFactory), "ROBO_MODULE_FACTORY");
Expand Down
25 changes: 25 additions & 0 deletions test/integration/FactoryTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {BaseFixture} from "../BaseFixture.sol";
import {Delay} from "@delay-module/Delay.sol";
import {Roles} from "@roles-module/Roles.sol";

import {Enum} from "../../lib/delay-module/node_modules/@gnosis.pm/safe-contracts/contracts/common/Enum.sol";

import {IKeeperRegistrar} from "../../src/interfaces/chainlink/IKeeperRegistrar.sol";

import {Errors} from ".../../src/libraries/Errors.sol";
Expand All @@ -32,6 +34,29 @@ contract FactoryTest is BaseFixture {
vm.stopPrank();
}

function test_delegationSuccesful() public {
// check: is the eoa actually a module before anything?
assertTrue(delayModule.isModuleEnabled(SAFE_EOA_SIGNER));

uint256 txNonceBeforeInstallationCall = delayModule.queueNonce();
// queues the tx, abstracting away the complexity of the delay module
vm.prank(SAFE_EOA_SIGNER);
roboModuleFactory.installation(address(delayModule));

// check: actually new tx is queued up?
assertGt(delayModule.queueNonce(), txNonceBeforeInstallationCall, "No new tx queued up");

// push time fwd
skip(COOLDOWN_PERIOD + 1);

// exec: queue tx after cooldown is ok to be executed
bytes memory payload = abi.encodeWithSignature("enableModule(address)", address(this));
delayModule.executeNextTx(address(delayModule), 0, payload, Enum.Operation.Call);

// check: did the factory become a module?
assertTrue(delayModule.isModuleEnabled(address(roboModuleFactory)), "Factory not enabled as module");
}

/// @todo pendant of implementing properly in another PR ensuring proper storage manipulation
// function test_RevertWhen_UpkeepReturnsZero() public {
// bytes memory creationCode = abi.encodePacked(type(RoboSaverVirtualModule).creationCode);
Expand Down
Loading