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

chore: migrate E2E deployment test to Foundry #225

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
109 changes: 109 additions & 0 deletions test/e2e/Deployment.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
pragma solidity ^0.8;

import {GPv2AllowListAuthentication} from "src/contracts/GPv2AllowListAuthentication.sol";

import {Helper} from "./Helper.sol";

interface IEIP173Proxy {
function owner() external view returns (address);
}

contract DeploymentTest is Helper(false) {
event Metadata(string, bytes);

function test__same_built_and_deployed_bytecode_metadata__authenticator() external {
_assertBuiltAndDeployedMetadataCoincide(address(allowListImpl), "GPv2AllowListAuthentication");
}

function test__same_built_and_deployed_bytecode_metadata__settlement() external {
_assertBuiltAndDeployedMetadataCoincide(address(settlement), "GPv2Settlement");
}

function test__same_built_and_deployed_bytecode_metadata__vault_relayer() external {
_assertBuiltAndDeployedMetadataCoincide(address(vaultRelayer), "GPv2VaultRelayer");
}

function test__determininstic_addresses__authenticator__proxy() external view {
assertEq(
_computeCreate2Addr(
abi.encodePacked(
vm.getCode("EIP173Proxy"),
abi.encode(
_implementationAddress(address(allowList)),
owner,
abi.encodeCall(GPv2AllowListAuthentication.initializeManager, (owner))
)
)
),
address(authenticator),
"authenticator address not as expected"
);
}

function test__determininstic_addresses__authenticator__implementation() external view {
assertEq(
_computeCreate2Addr(vm.getCode("GPv2AllowListAuthentication")),
_implementationAddress(address(allowList)),
"authenticator impl address not as expected"
);
}

function test__determininstic_addresses__settlement() external view {
assertEq(
_computeCreate2Addr(
abi.encodePacked(vm.getCode("GPv2Settlement"), abi.encode(address(authenticator), address(vault)))
),
address(settlement),
"settlement address not as expected"
);
}
meetmangukiya marked this conversation as resolved.
Show resolved Hide resolved

function test__authorization__authenticator_hash_dedicated_owner() external view {
meetmangukiya marked this conversation as resolved.
Show resolved Hide resolved
assertEq(IEIP173Proxy(address(allowList)).owner(), owner, "owner not as expected");
}

function test__authorization__authenticator_hash_dedicated_manager() external view {
meetmangukiya marked this conversation as resolved.
Show resolved Hide resolved
assertEq(allowList.manager(), owner, "manager not as expected");
}

function _assertBuiltAndDeployedMetadataCoincide(address addr, string memory artifactName) internal {
bytes memory deployedCode = vm.getDeployedCode(artifactName);
assertEq(
keccak256(_getMetadata(string(abi.encodePacked("deployed ", artifactName)), addr.code)),
keccak256(_getMetadata(artifactName, deployedCode)),
"metadata doesnt match"
);
}

function _getMetadata(string memory hint, bytes memory bytecode) internal returns (bytes memory metadata) {
assembly ("memory-safe") {
// the last two bytes encode the size of the cbor encoded metadata
let bytecodeSize := mload(bytecode)
let bytecodeStart := add(bytecode, 0x20)
let cborSizeOffset := add(bytecodeStart, sub(bytecodeSize, 0x20))
let cborSize := and(mload(cborSizeOffset), 0xffff)

// copy the metadata out
metadata := mload(0x40)
let metadataSize := add(cborSize, 0x02)
mstore(metadata, metadataSize)
let metadataOffset := add(bytecodeStart, sub(bytecodeSize, metadataSize))
mcopy(add(metadata, 0x20), metadataOffset, metadataSize)

// update free memory ptr
mstore(0x40, add(metadata, add(metadataSize, 0x20)))
}
emit Metadata(hint, metadata);
}

function _computeCreate2Addr(bytes memory initCode) internal view returns (address) {
return vm.computeCreate2Address(SALT, hashInitCode(initCode), deployer);
}

function _implementationAddress(address proxy) internal view returns (address) {
return address(
uint160(uint256(vm.load(proxy, 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)))
meetmangukiya marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
141 changes: 0 additions & 141 deletions test/e2e/deployment.test.ts

This file was deleted.

Loading