Skip to content

Commit

Permalink
test: test that "Execute" event gets emitted
Browse files Browse the repository at this point in the history
test: add error string in "assertEq" statements
  • Loading branch information
PaulRBerg committed Feb 13, 2023
1 parent 4b13c5c commit 7fa6e7f
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 34 deletions.
8 changes: 4 additions & 4 deletions test/prb-proxy-factory/deploy-for/deployFor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract DeployFor_Test is PRBProxyFactory_Test {
// Deploy the first proxy.
bytes memory actualRuntimeBytecode = address(factory.deployFor(deployer)).code;
bytes memory expectedRuntimeBytecode = address(deployProxy()).code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

modifier txOriginNotSameAsOwner() {
Expand All @@ -33,7 +33,7 @@ contract DeployFor_Test is PRBProxyFactory_Test {
owner = users.bob;
bytes memory actualRuntimeBytecode = address(factory.deployFor(owner)).code;
bytes memory expectedRuntimeBytecode = address(deployProxy()).code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

modifier notFirstProxy() {
Expand All @@ -49,7 +49,7 @@ contract DeployFor_Test is PRBProxyFactory_Test {
bytes memory actualRuntimeBytecode = factoryProxyAddress.code;
address testProxyAddress = address(deployProxy());
bytes memory expectedRuntimeBytecode = testProxyAddress.code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

/// @dev it should update the next seeds mapping.
Expand All @@ -61,7 +61,7 @@ contract DeployFor_Test is PRBProxyFactory_Test {
factory.deployFor(owner);
bytes32 actualNextSeed = factory.getNextSeed(deployer);
bytes32 expectedNextSeed = SEED_TWO;
assertEq(actualNextSeed, expectedNextSeed);
assertEq(actualNextSeed, expectedNextSeed, "nextSeed");
}

/// @dev it should update the proxies mapping.
Expand Down
4 changes: 2 additions & 2 deletions test/prb-proxy-factory/deploy/deploy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ contract Deploy_Test is PRBProxyFactory_Test {
function test_Deploy() external {
bytes memory actualRuntimeBytecode = address(factory.deploy()).code;
bytes memory expectedRuntimeBytecode = address(deployProxy()).code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

/// @dev it should update the next seeds mapping.
function test_Deploy_UpdateNextSeeds() external {
factory.deploy();
bytes32 actualNextSeed = factory.getNextSeed(deployer);
bytes32 expectedNextSeed = SEED_ONE;
assertEq(actualNextSeed, expectedNextSeed);
assertEq(actualNextSeed, expectedNextSeed, "nextSeed");
}

/// @dev it should update the proxies mapping.
Expand Down
2 changes: 1 addition & 1 deletion test/prb-proxy-factory/version/version.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ contract Version_Test is PRBProxyFactory_Test {
function test_Version() external {
uint256 actualVersion = factory.version();
uint256 expectedVersion = 3;
assertEq(actualVersion, expectedVersion);
assertEq(actualVersion, expectedVersion, "version");
}
}
12 changes: 6 additions & 6 deletions test/prb-proxy-registry/deploy-for/deployFor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract DeployFor_Test is PRBProxyRegistry_Test {
proxy.transferOwnership(address(1729));
bytes memory actualRuntimeBytecode = address(registry.deployFor(deployer)).code;
bytes memory expectedRuntimeBytecode = address(deployProxy()).code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

modifier ownerDoesNotHaveProxyInRegistry() {
Expand All @@ -46,7 +46,7 @@ contract DeployFor_Test is PRBProxyRegistry_Test {
function test_DeployFor_DeployerSameAsOwner() external ownerDoesNotHaveProxyInRegistry {
bytes memory actualRuntimeBytecode = address(registry.deployFor(deployer)).code;
bytes memory expectedRuntimeBytecode = address(deployProxy()).code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

modifier deployerNotSameAsOwner() {
Expand All @@ -61,7 +61,7 @@ contract DeployFor_Test is PRBProxyRegistry_Test {
{
bytes memory actualRuntimeBytecode = address(registry.deployFor(owner)).code;
bytes memory expectedRuntimeBytecode = address(deployProxy()).code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

modifier deployerDeployedAnotherProxyForTheOwnerViaFactory() {
Expand All @@ -78,7 +78,7 @@ contract DeployFor_Test is PRBProxyRegistry_Test {
{
bytes memory actualRuntimeBytecode = address(registry.deployFor(owner)).code;
bytes memory expectedRuntimeBytecode = address(deployProxy()).code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

modifier deployerDeployedAnotherProxyForHimselfViaFactory() {
Expand All @@ -96,7 +96,7 @@ contract DeployFor_Test is PRBProxyRegistry_Test {
{
bytes memory actualRuntimeBytecode = address(registry.deployFor(owner)).code;
bytes memory expectedRuntimeBytecode = address(deployProxy()).code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

/// @dev it should update the current proxies mapping.
Expand All @@ -110,6 +110,6 @@ contract DeployFor_Test is PRBProxyRegistry_Test {
registry.deployFor(owner);
address actualProxyAddress = address(registry.getCurrentProxy(owner));
address expectedProxyAddress = computeProxyAddress(deployer, SEED_TWO);
assertEq(actualProxyAddress, expectedProxyAddress);
assertEq(actualProxyAddress, expectedProxyAddress, "proxy address");
}
}
4 changes: 2 additions & 2 deletions test/prb-proxy-registry/deploy/deploy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ contract Deploy_Test is PRBProxyRegistry_Test {
function test_Deploy() external {
bytes memory actualRuntimeBytecode = address(registry.deploy()).code;
bytes memory expectedRuntimeBytecode = address(deployProxy()).code;
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode);
assertEq(actualRuntimeBytecode, expectedRuntimeBytecode, "runtime bytecode");
}

/// @dev it should update the current proxies mapping.
function test_Deploy_UpdateCurrentProxies() external {
registry.deploy();
address actualProxyAddress = address(registry.getCurrentProxy(deployer));
address expectedProxyAddress = computeProxyAddress(deployer, SEED_ZERO);
assertEq(actualProxyAddress, expectedProxyAddress);
assertEq(actualProxyAddress, expectedProxyAddress, "proxy address");
}
}
52 changes: 36 additions & 16 deletions test/prb-proxy/execute/execute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ contract Execute_Test is PRBProxy_Test {
bytes memory data = bytes.concat(targets.echo.echoMsgValue.selector);
bytes memory actualResponse = proxy.execute{ value: amount }(address(targets.echo), data);
bytes memory expectedResponse = abi.encode(amount);
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "echo.echoMsgValue response");
}

modifier noEtherSent() {
Expand All @@ -284,18 +284,18 @@ contract Execute_Test is PRBProxy_Test {
delegateCallDoesNotRevert
noEtherSent
{
uint256 previousAliceBalance = users.bob.balance;
uint256 contractBalance = 3.14 ether;
vm.deal({ account: address(proxy), newBalance: contractBalance });
uint256 initialBobBalance = users.bob.balance;
uint256 proxyBalance = 3.14 ether;
vm.deal({ account: address(proxy), newBalance: proxyBalance });

bytes memory data = abi.encodeCall(targets.selfDestruct.destroyMe, (users.bob));
bytes memory actualResponse = proxy.execute(address(targets.selfDestruct), data);
bytes memory expectedResponse = "";
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "selfDestruct.destroyMe response");

uint256 actualAliceBalance = users.bob.balance;
uint256 expectedAliceBalance = previousAliceBalance + contractBalance;
assertEq(actualAliceBalance, expectedAliceBalance);
uint256 actualBobBalance = users.bob.balance;
uint256 expectedBobBalance = initialBobBalance + proxyBalance;
assertEq(actualBobBalance, expectedBobBalance, "Bob's balance");
}

modifier targetDoesNotSelfDestruct() {
Expand Down Expand Up @@ -335,7 +335,7 @@ contract Execute_Test is PRBProxy_Test {
bytes memory data = abi.encodeCall(targets.echo.echoAddress, (input));
bytes memory actualResponse = proxy.execute(address(targets.echo), data);
bytes memory expectedResponse = abi.encode(input);
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "echo.echoAddress response");
}

/// @dev it should return the bytes array.
Expand All @@ -355,7 +355,7 @@ contract Execute_Test is PRBProxy_Test {
bytes memory data = abi.encodeCall(targets.echo.echoBytesArray, (input));
bytes memory actualResponse = proxy.execute(address(targets.echo), data);
bytes memory expectedResponse = abi.encode(input);
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "echo.echoBytesArray response");
}

/// @dev it should return the bytes32.
Expand All @@ -375,7 +375,7 @@ contract Execute_Test is PRBProxy_Test {
bytes memory data = abi.encodeCall(targets.echo.echoBytes32, (input));
bytes memory actualResponse = proxy.execute(address(targets.echo), data);
bytes memory expectedResponse = abi.encode(input);
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "echo.echoBytes32 response");
}

/// @dev it should return the string.
Expand All @@ -395,7 +395,7 @@ contract Execute_Test is PRBProxy_Test {
bytes memory data = abi.encodeCall(targets.echo.echoString, (input));
bytes memory actualResponse = proxy.execute(address(targets.echo), data);
bytes memory expectedResponse = abi.encode(input);
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "echo.echoString response");
}

/// @dev it should return the string.
Expand All @@ -415,7 +415,7 @@ contract Execute_Test is PRBProxy_Test {
bytes memory data = abi.encodeCall(targets.echo.echoStruct, (input));
bytes memory actualResponse = proxy.execute(address(targets.echo), data);
bytes memory expectedResponse = abi.encode(input);
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "echo.echoStruct response");
}

/// @dev it should return the string.
Expand All @@ -435,7 +435,7 @@ contract Execute_Test is PRBProxy_Test {
bytes memory data = abi.encodeCall(targets.echo.echoUint8, (input));
bytes memory actualResponse = proxy.execute(address(targets.echo), data);
bytes memory expectedResponse = abi.encode(input);
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "echo.echoUint8 response");
}

/// @dev it should return the string.
Expand All @@ -455,7 +455,7 @@ contract Execute_Test is PRBProxy_Test {
bytes memory data = abi.encodeCall(targets.echo.echoUint256, (input));
bytes memory actualResponse = proxy.execute(address(targets.echo), data);
bytes memory expectedResponse = abi.encode(input);
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "echo.echoUint256 response");
}

/// @dev it should return the string.
Expand All @@ -475,6 +475,26 @@ contract Execute_Test is PRBProxy_Test {
bytes memory data = abi.encodeCall(targets.echo.echoUint256Array, (input));
bytes memory actualResponse = proxy.execute(address(targets.echo), data);
bytes memory expectedResponse = abi.encode(input);
assertEq(actualResponse, expectedResponse);
assertEq(actualResponse, expectedResponse, "echo.echoUint256Array response");
}

/// @dev it should return the string.
function testFuzz_Execute_Event(
uint256 input
)
external
callerAuthorized
targetContract
gasStipendCalculationDoesNotUnderflow
ownerNotChangedDuringDelegateCall
delegateCallDoesNotRevert
noEtherSent
targetDoesNotSelfDestruct
callerOwnerOrEnvoy
{
vm.expectEmit({ checkTopic1: true, checkTopic2: false, checkTopic3: false, checkData: true });
bytes memory data = abi.encodeCall(targets.echo.echoUint256, (input));
emit Execute({ target: address(targets.echo), data: data, response: abi.encode(input) });
proxy.execute(address(targets.echo), data);
}
}
2 changes: 1 addition & 1 deletion test/prb-proxy/receive/receive.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ contract Receive_Test is PRBProxy_Test {

uint256 actualBalance = address(proxy).balance;
uint256 expectedBalance = value;
assertEq(actualBalance, expectedBalance);
assertEq(actualBalance, expectedBalance, "proxy balance");
}
}
4 changes: 2 additions & 2 deletions test/prb-proxy/transfer-ownership/transferOwnership.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract TransferOwnership_Test is PRBProxy_Test {
proxy.transferOwnership(address(0));
address actualOwner = proxy.owner();
address expectedOwner = address(0);
assertEq(actualOwner, expectedOwner);
assertEq(actualOwner, expectedOwner, "proxy owner");
}

modifier toNonZeroAddress() {
Expand All @@ -39,7 +39,7 @@ contract TransferOwnership_Test is PRBProxy_Test {
proxy.transferOwnership(newOwner);
address actualOwner = proxy.owner();
address expectedOwner = newOwner;
assertEq(actualOwner, expectedOwner);
assertEq(actualOwner, expectedOwner, "proxy owner");
}

/// @dev it should emit a TransferOwnership event.
Expand Down

0 comments on commit 7fa6e7f

Please sign in to comment.