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

test: deploy vault factory with hardcoded salt #1138

Merged
merged 8 commits into from
Dec 30, 2024
42 changes: 40 additions & 2 deletions pkg/vault/test/foundry/VaultFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ contract VaultFactoryTest is Test, VaultContractsDeployer {
// Should match the "PRODUCTION" limits in BaseVaultTest.
uint256 private constant _MIN_TRADE_AMOUNT = 1e6;
uint256 private constant _MIN_WRAP_AMOUNT = 1e4;
bytes32 private constant _HARDCODED_SALT =
bytes32(0xae0bdc4eeac5e950b67c6819b118761caaf619464ad74a6048c67c03598dc543);
address private constant _HARDCODED_VAULT_ADDRESS = address(0xbA133381ef63946fF77A7D009DFcdBdE5c77b92F);

address deployer;
address other;
Expand All @@ -30,7 +33,7 @@ contract VaultFactoryTest is Test, VaultContractsDeployer {
deployer = makeAddr("deployer");
other = makeAddr("other");
authorizer = deployBasicAuthorizerMock();
vm.startPrank(deployer);
vm.prank(deployer);
factory = deployVaultFactory(
authorizer,
90 days,
Expand All @@ -41,7 +44,42 @@ contract VaultFactoryTest is Test, VaultContractsDeployer {
keccak256(type(VaultExtension).creationCode),
keccak256(type(VaultAdmin).creationCode)
);
vm.stopPrank();
}

function testCreateVaultHardcodedSalt() public {
vm.prank(deployer);
factory.create(
_HARDCODED_SALT,
_HARDCODED_VAULT_ADDRESS,
type(Vault).creationCode,
type(VaultExtension).creationCode,
type(VaultAdmin).creationCode
);
}

function testCreateVaultHardcodedSaltWrongDeployer() public {
address wrongDeployer = makeAddr("wrongDeployer");
vm.prank(wrongDeployer);
VaultFactory wrongFactory = deployVaultFactory(
authorizer,
90 days,
30 days,
_MIN_TRADE_AMOUNT,
_MIN_WRAP_AMOUNT,
keccak256(type(Vault).creationCode),
keccak256(type(VaultExtension).creationCode),
keccak256(type(VaultAdmin).creationCode)
);

vm.prank(wrongDeployer);
vm.expectRevert(VaultFactory.VaultAddressMismatch.selector);
wrongFactory.create(
_HARDCODED_SALT,
_HARDCODED_VAULT_ADDRESS,
type(Vault).creationCode,
type(VaultExtension).creationCode,
type(VaultAdmin).creationCode
);
}

/// forge-config: default.fuzz.runs = 100
Expand Down
Loading