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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
42 changes: 42 additions & 0 deletions pkg/vault/test/foundry/VaultFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 =
gosuto-inzasheru marked this conversation as resolved.
Show resolved Hide resolved
bytes32(0xae0bdc4eeac5e950b67c6819b118761caaf619464ad74a6048c67c03598dc543);
address private constant HARDCODED_VAULT_ADDRESS = address(0xbA133381ef63946fF77A7D009DFcdBdE5c77b92F);
gosuto-inzasheru marked this conversation as resolved.
Show resolved Hide resolved

address deployer;
BasicAuthorizerMock authorizer;
Expand All @@ -26,6 +29,7 @@ contract VaultFactoryTest is Test, VaultContractsDeployer {
function setUp() public virtual {
deployer = makeAddr("deployer");
authorizer = deployBasicAuthorizerMock();
vm.prank(deployer);
factory = deployVaultFactory(
authorizer,
90 days,
Expand All @@ -38,6 +42,44 @@ contract VaultFactoryTest is Test, VaultContractsDeployer {
);
}

function testCreateVaultHardcodedSalt() public {
authorizer.grantRole(factory.getActionId(VaultFactory.create.selector), deployer);
vm.prank(deployer);
factory.create(
HARDCODED_SALT,
HARDCODED_VAULT_ADDRESS,
gosuto-inzasheru marked this conversation as resolved.
Show resolved Hide resolved
type(Vault).creationCode,
type(VaultAdmin).creationCode,
type(VaultExtension).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(VaultAdmin).creationCode),
keccak256(type(VaultExtension).creationCode)
);

authorizer.grantRole(wrongFactory.getActionId(VaultFactory.create.selector), wrongDeployer);
vm.prank(wrongDeployer);
vm.expectRevert(VaultFactory.VaultAddressMismatch.selector);
wrongFactory.create(
HARDCODED_SALT,
HARDCODED_VAULT_ADDRESS,
type(Vault).creationCode,
type(VaultAdmin).creationCode,
type(VaultExtension).creationCode
);
}

/// forge-config: default.fuzz.runs = 100
function testCreateVault__Fuzz(bytes32 salt) public {
authorizer.grantRole(factory.getActionId(VaultFactory.create.selector), deployer);
Expand Down