Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions packages/contracts-bedrock/test/Safe/LivenessGuard.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ contract LivenessGuard_FuzzOwnerManagement_Test is StdCheats, StdUtils, Liveness
privateKeys[ownerAddrs[i]] = ownerkeys[i];
}

// Override the saltNonce to ensure prevent a create2 collision.
saltNonce = uint256(keccak256(bytes("LIVENESS GUARD OWNER MANAGEMENT TEST")));
// Create the new safe and register the guard.
SafeInstance memory safeInstance = _setupSafe(ownerkeys, threshold);
livenessGuard = new WrappedGuard(safeInstance.safe);
Expand Down
30 changes: 27 additions & 3 deletions packages/contracts-bedrock/test/safe-tools/SafeTestTools.sol
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,21 @@ contract SafeTestTools {

SafeInstance[] internal instances;

uint256 internal saltNonce = uint256(keccak256(bytes("SAFE TEST")));

/// @dev can be called to reinitialize the singleton, proxyFactory and handler. Useful for forking.
function _initializeSafeTools() internal {
singleton = new GnosisSafe();
proxyFactory = new GnosisSafeProxyFactory();
handler = new CompatibilityFallbackHandler();
}

/// @dev Sets up a Safe with the given parameters.
/// @param ownerPKs The public keys of the owners.
/// @param threshold The threshold for the Safe.
/// @param initialBalance The initial balance of the Safe.
/// @param advancedParams The advanced parameters for the Safe initialization.
/// @return The initialized Safe instance.
function _setupSafe(
uint256[] memory ownerPKs,
uint256 threshold,
Expand Down Expand Up @@ -560,6 +568,11 @@ contract SafeTestTools {
return instance0;
}

/// @dev Sets up a Safe with the given parameters.
/// @param ownerPKs The public keys of the owners.
/// @param threshold The threshold for the Safe.
/// @param initialBalance The initial balance of the Safe.
/// @return The initialized Safe instance.
function _setupSafe(
uint256[] memory ownerPKs,
uint256 threshold,
Expand All @@ -575,7 +588,7 @@ contract SafeTestTools {
AdvancedSafeInitParams({
includeFallbackHandler: true,
initData: "",
saltNonce: 0,
saltNonce: saltNonce,
setupModulesCall_to: address(0),
setupModulesCall_data: "",
refundAmount: 0,
Expand All @@ -585,6 +598,10 @@ contract SafeTestTools {
);
}

/// @dev Sets up a Safe with the given parameters.
/// @param ownerPKs The public keys of the owners.
/// @param threshold The threshold for the Safe.
/// @return The initialized Safe instance.
function _setupSafe(uint256[] memory ownerPKs, uint256 threshold) public returns (SafeInstance memory) {
return _setupSafe(
ownerPKs,
Expand All @@ -593,7 +610,7 @@ contract SafeTestTools {
AdvancedSafeInitParams({
includeFallbackHandler: true,
initData: "",
saltNonce: 0,
saltNonce: saltNonce,
setupModulesCall_to: address(0),
setupModulesCall_data: "",
refundAmount: 0,
Expand All @@ -603,6 +620,8 @@ contract SafeTestTools {
);
}

/// @dev Sets up a Safe with default parameters. The SafeInstance will have 3 owners and a threshold of 2.
/// @return The initialized Safe instance.
function _setupSafe() public returns (SafeInstance memory) {
(, uint256[] memory defaultPKs) = SafeTestLib.makeAddrsAndKeys("default", 3);

Expand All @@ -613,7 +632,7 @@ contract SafeTestTools {
AdvancedSafeInitParams({
includeFallbackHandler: true,
initData: "",
saltNonce: uint256(keccak256(bytes("SAFE TEST"))),
saltNonce: saltNonce,
setupModulesCall_to: address(0),
setupModulesCall_data: "",
refundAmount: 0,
Expand All @@ -623,13 +642,18 @@ contract SafeTestTools {
);
}

/// @dev Returns the first Safe instance.
/// @return The first Safe instance.
function getSafe() public view returns (SafeInstance memory) {
if (instances.length == 0) {
revert("SAFETESTTOOLS: Test Safe has not been deployed, use _setupSafe() calling safe()");
}
return instances[0];
}

/// @dev Returns the Safe instance with the given address.
/// @param _safe The address of the Safe instance to return.
/// @return The Safe instance with the given address.
function getSafe(address _safe) public view returns (SafeInstance memory) {
for (uint256 i; i < instances.length; ++i) {
if (address(instances[i].safe) == _safe) return instances[i];
Expand Down