Skip to content

Commit 27cdcd0

Browse files
committed
Replace _loadConfig with _loadDeployedContractsInSimulation
1 parent b661a01 commit 27cdcd0

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

script/BaseScript.sol

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ abstract contract BaseScript is Script {
4949

5050
constructor() {
5151
_loadChains();
52-
_loadContracts(false);
52+
_loadDeployedContracts(false);
5353
}
5454

5555
function _loadChains() private {
@@ -69,6 +69,28 @@ abstract contract BaseScript is Script {
6969
}
7070
}
7171

72+
/**
73+
* @notice _loadDeployedContractsInSimulation - Load deployed contracts in simulation
74+
* too.
75+
*/
76+
function _loadDeployedContractsInSimulation() internal {
77+
_loadDeployedContracts(true);
78+
}
79+
80+
function _loadDeployedContracts(bool _loadInSimulation) private {
81+
if (!_loadInSimulation && _isSimulation()) return;
82+
83+
Deployment[] memory deployments = _getDeployedContracts(_getNetwork());
84+
85+
Deployment memory cached;
86+
uint256 length = deployments.length;
87+
for (uint256 i = 0; i < length; ++i) {
88+
cached = deployments[i];
89+
contracts[cached.contractName] = cached.contractAddress;
90+
vm.label(cached.contractAddress, cached.contractName);
91+
}
92+
}
93+
7294
//Entrypoint for the script
7395
function run() external virtual;
7496

@@ -272,25 +294,6 @@ abstract contract BaseScript is Script {
272294
return currentNetwork == localNetwork;
273295
}
274296

275-
/**
276-
* @notice _loadContracts - Loads the deployed contracts from the current network inside
277-
* the mapping "contracts"
278-
* @param _loadInSimulation If it should load in simulation
279-
*/
280-
function _loadContracts(bool _loadInSimulation) internal {
281-
if (!_loadInSimulation && _isSimulation()) return;
282-
283-
Deployment[] memory deployments = _getDeployedContracts(_getNetwork());
284-
285-
Deployment memory cached;
286-
uint256 length = deployments.length;
287-
for (uint256 i = 0; i < length; ++i) {
288-
cached = deployments[i];
289-
contracts[cached.contractName] = cached.contractAddress;
290-
vm.label(cached.contractAddress, cached.contractName);
291-
}
292-
}
293-
294297
/**
295298
* @notice _loadOtherContractNetwork - Loads the deployed contracts from a network
296299
* inside the mapping "contractsOtherNetworks"

script/deploy/HelloWorld.s.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ contract HelloWorldScript is BaseScript {
3535
Config memory config =
3636
abi.decode(vm.parseJson(file, string.concat(".", _getNetwork())), (Config));
3737

38+
// Load contracts in simulation
39+
// _loadDeployedContractsInSimulation();
40+
3841
// Asserts are there as an example to showcase the config is functionnal
3942
assert(
4043
keccak256(abi.encode(config.exampleString)) == keccak256(abi.encode("HelloWorld"))

script/deploy/diamond-example/DiamondExample.s.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ contract DiamondExample is BaseScript, DiamondHelper {
2222
string private constant DIAMOND_LOUPE_INTERFACE = "IDiamondLoupe";
2323

2424
function run() external override {
25-
_loadContracts(false);
2625
IDiamondCut.FacetCut[] memory facetCuts = new IDiamondCut.FacetCut[](0);
2726

2827
//Deploy Implementation of Core Diamond Proxy (DiamondCutFacet & DiamondLoupeFacet)

script/utils/diamond/FacetDeployer.sol

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ abstract contract FacetDeployerScript is BaseScript, DiamondHelper {
1515
}
1616

1717
function run() external override {
18-
_loadContracts(false);
1918
tryToDeploy(contracts[FACET_NAME]);
2019
}
2120

@@ -25,9 +24,7 @@ abstract contract FacetDeployerScript is BaseScript, DiamondHelper {
2524

2625
function tryToDeploy(address _cachedContract) public virtual returns (address);
2726

28-
function getFacetCuts() external returns (IDiamondCut.FacetCut[] memory) {
29-
_loadContracts(false);
30-
27+
function getFacetCuts() external view returns (IDiamondCut.FacetCut[] memory) {
3128
address facet = contracts[FACET_NAME];
3229
require(facet != address(0), "Facet not deployed.");
3330

0 commit comments

Comments
 (0)