-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from PaulRBerg/feat/deploy-and-execute-and-in…
…stall-plugin feat: deployAndExecuteAndInstallPlugin
- Loading branch information
Showing
11 changed files
with
219 additions
and
39 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
115 changes: 115 additions & 0 deletions
115
test/registry/deploy-and-execute-and-install-plugin/deployAndExecuteAndInstallPlugin.t.sol
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,115 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.19 <=0.9.0; | ||
|
||
import { IPRBProxy } from "src/interfaces/IPRBProxy.sol"; | ||
import { IPRBProxyPlugin } from "src/interfaces/IPRBProxyPlugin.sol"; | ||
import { IPRBProxyRegistry } from "src/interfaces/IPRBProxyRegistry.sol"; | ||
|
||
import { Registry_Test } from "../Registry.t.sol"; | ||
|
||
contract DeployAndExecuteAndInstallPlugin_Test is Registry_Test { | ||
bytes internal data; | ||
uint256 internal input = 1729; | ||
address internal target; | ||
|
||
function setUp() public override { | ||
Registry_Test.setUp(); | ||
|
||
data = abi.encodeWithSelector(targets.echo.echoUint256.selector, input); | ||
target = address(targets.echo); | ||
} | ||
|
||
function test_RevertWhen_OwnerHasProxy() external { | ||
IPRBProxy proxy = registry.deploy(); | ||
vm.expectRevert( | ||
abi.encodeWithSelector(IPRBProxyRegistry.PRBProxyRegistry_OwnerHasProxy.selector, users.alice, proxy) | ||
); | ||
registry.deployAndExecuteAndInstallPlugin(target, data, plugins.basic); | ||
} | ||
|
||
modifier whenOwnerDoesNotHaveProxy() { | ||
_; | ||
} | ||
|
||
function testFuzz_DeployAndExecuteAndInstallPlugin_ProxyAddress(address owner) external whenOwnerDoesNotHaveProxy { | ||
changePrank({ msgSender: owner }); | ||
IPRBProxy actualProxy = registry.deployAndExecuteAndInstallPlugin(target, data, plugins.basic); | ||
address expectedProxy = computeProxyAddress(owner); | ||
assertEq(address(actualProxy), expectedProxy, "deployed proxy address mismatch"); | ||
} | ||
|
||
function testFuzz_DeployAndExecuteAndInstallPlugin_ProxyOwner(address owner) external whenOwnerDoesNotHaveProxy { | ||
changePrank({ msgSender: owner }); | ||
IPRBProxy proxy = registry.deployAndExecuteAndInstallPlugin(target, data, plugins.basic); | ||
address actualOwner = proxy.owner(); | ||
address expectedOwner = owner; | ||
assertEq(actualOwner, expectedOwner, "proxy owner mismatch"); | ||
} | ||
|
||
function testFuzz_DeployAndExecuteAndInstallPlugin_UpdateProxies(address owner) | ||
external | ||
whenOwnerDoesNotHaveProxy | ||
{ | ||
changePrank({ msgSender: owner }); | ||
registry.deployAndExecuteAndInstallPlugin(target, data, plugins.basic); | ||
|
||
address actualProxyAddress = address(registry.getProxy(owner)); | ||
address expectedProxyAddress = computeProxyAddress(owner); | ||
assertEq(actualProxyAddress, expectedProxyAddress, "proxy address mismatch"); | ||
} | ||
|
||
function testFuzz_DeployAndExecuteAndInstallPlugin_Plugin() external whenOwnerDoesNotHaveProxy { | ||
registry.deployAndExecuteAndInstallPlugin(target, data, plugins.basic); | ||
bytes4[] memory pluginMethods = plugins.basic.getMethods(); | ||
for (uint256 i = 0; i < pluginMethods.length; ++i) { | ||
IPRBProxyPlugin actualPlugin = registry.getPluginByOwner({ owner: users.alice, method: pluginMethods[i] }); | ||
IPRBProxyPlugin expectedPlugin = plugins.basic; | ||
assertEq(actualPlugin, expectedPlugin, "plugin method not installed"); | ||
} | ||
} | ||
|
||
function testFuzz_DeployAndExecuteAndInstallPlugin_PluginReverseMapping() external whenOwnerDoesNotHaveProxy { | ||
registry.deployAndExecuteAndInstallPlugin(target, data, plugins.basic); | ||
bytes4[] memory actualMethods = registry.getMethodsByOwner({ owner: users.alice, plugin: plugins.basic }); | ||
bytes4[] memory expectedMethods = plugins.basic.getMethods(); | ||
assertEq(actualMethods, expectedMethods, "methods not saved in reverse mapping"); | ||
} | ||
|
||
function testFuzz_DeployAndExecuteAndInstallPlugin_Event_DeployProxy(address owner) | ||
external | ||
whenOwnerDoesNotHaveProxy | ||
{ | ||
changePrank({ msgSender: owner }); | ||
|
||
vm.expectEmit({ emitter: address(registry) }); | ||
emit DeployProxy({ operator: owner, owner: owner, proxy: IPRBProxy(computeProxyAddress(owner)) }); | ||
registry.deployAndExecuteAndInstallPlugin(target, data, plugins.basic); | ||
} | ||
|
||
function testFuzz_DeployAndExecuteAndInstallPlugin_Event_Execute(address owner) | ||
external | ||
whenOwnerDoesNotHaveProxy | ||
{ | ||
changePrank({ msgSender: owner }); | ||
|
||
vm.expectEmit({ emitter: computeProxyAddress(owner) }); | ||
emit Execute({ target: address(targets.echo), data: data, response: abi.encode(input) }); | ||
registry.deployAndExecuteAndInstallPlugin(target, data, plugins.basic); | ||
} | ||
|
||
function testFuzz_DeployAndExecuteAndInstallPlugin_Event_InstallPlugin(address owner) | ||
external | ||
whenOwnerDoesNotHaveProxy | ||
{ | ||
changePrank({ msgSender: owner }); | ||
|
||
vm.expectEmit({ emitter: address(registry) }); | ||
emit InstallPlugin({ | ||
owner: owner, | ||
proxy: IPRBProxy(computeProxyAddress(owner)), | ||
plugin: plugins.basic, | ||
methods: plugins.basic.getMethods() | ||
}); | ||
registry.deployAndExecuteAndInstallPlugin(target, data, plugins.basic); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/registry/deploy-and-execute-and-install-plugin/deployAndExecuteAndInstallPlugin.tree
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,12 @@ | ||
deployAndExecuteAndInstallPlugin.t.sol | ||
├── when the owner has a proxy | ||
│ └── it should revert | ||
└── when the owner does not have a proxy | ||
├── it should generate the correct proxy address | ||
├── it should set the owner | ||
├── it should update the proxies mapping | ||
├── it should install the plugin | ||
├── it should save the plugin methods in the reverse mapping | ||
├── it should emit a {DeployProxy} event | ||
├── it should emit a {Execute} event | ||
└── it should emit an {InstallPlugin} event |
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.