Skip to content

Commit

Permalink
Foolproof scripts against zero address
Browse files Browse the repository at this point in the history
  • Loading branch information
rookmate committed Dec 5, 2024
1 parent f2439b3 commit 77bb303
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/socket-poc
89 changes: 67 additions & 22 deletions script/checkCounters.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,74 @@ contract CheckCounters is Script {
// bytes32 public counter = keccak256(abi.encode("counter"));

function run() external {

CounterDeployer deployer = CounterDeployer(vm.envAddress("COUNTER_DEPLOYER"));
CounterDeployer deployer = CounterDeployer(
vm.envAddress("COUNTER_DEPLOYER")
);

vm.createSelectFork(vm.envString("SOCKET_RPC"));
address counterInstanceArbitrumSepolia = deployer.getOnChainAddress(deployer.counter(), 421614);
address counterInstanceOptimismSepolia = deployer.getOnChainAddress(deployer.counter(), 11155420);
address counterInstanceBaseSepolia = deployer.getOnChainAddress(deployer.counter(), 84532);
address counterInstanceSepolia = deployer.getOnChainAddress(deployer.counter(), 11155111);

vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC"));
uint256 counterValueArbitrumSepolia = Counter(counterInstanceArbitrumSepolia).counter();
console.log("Counter value on Arbitrum Sepolia: ", counterValueArbitrumSepolia);

vm.createSelectFork(vm.envString("OPTIMISM_SEPOLIA_RPC"));
uint256 counterValueOptimismSepolia = Counter(counterInstanceOptimismSepolia).counter();
console.log("Counter value on Optimism Sepolia: ", counterValueOptimismSepolia);

vm.createSelectFork(vm.envString("BASE_SEPOLIA_RPC"));
uint256 counterValueBaseSepolia = Counter(counterInstanceBaseSepolia).counter();
console.log("Counter value on Base Sepolia: ", counterValueBaseSepolia);

vm.createSelectFork(vm.envString("SEPOLIA_RPC"));
uint256 counterValueSepolia = Counter(counterInstanceSepolia).counter();
console.log("Counter value on Sepolia: ", counterValueSepolia);
address counterInstanceArbitrumSepolia = deployer.getOnChainAddress(
deployer.counter(),
421614
);
address counterInstanceOptimismSepolia = deployer.getOnChainAddress(
deployer.counter(),
11155420
);
address counterInstanceBaseSepolia = deployer.getOnChainAddress(
deployer.counter(),
84532
);
address counterInstanceSepolia = deployer.getOnChainAddress(
deployer.counter(),
11155111
);

if (counterInstanceArbitrumSepolia != address(0)) {
vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC"));
uint256 counterValueArbitrumSepolia = Counter(
counterInstanceArbitrumSepolia
).counter();
console.log(
"Counter value on Arbitrum Sepolia: ",
counterValueArbitrumSepolia
);
} else {
console.log("Counter not yet deployed on Arbitrum Sepolia");
}

if (counterInstanceOptimismSepolia != address(0)) {
vm.createSelectFork(vm.envString("OPTIMISM_SEPOLIA_RPC"));
uint256 counterValueOptimismSepolia = Counter(
counterInstanceOptimismSepolia
).counter();
console.log(
"Counter value on Optimism Sepolia: ",
counterValueOptimismSepolia
);
} else {
console.log("Counter not yet deployed on Optimism Sepolia");
}

if (counterInstanceBaseSepolia != address(0)) {
vm.createSelectFork(vm.envString("BASE_SEPOLIA_RPC"));
uint256 counterValueBaseSepolia = Counter(
counterInstanceBaseSepolia
).counter();
console.log(
"Counter value on Base Sepolia: ",
counterValueBaseSepolia
);
} else {
console.log("Counter not yet deployed on Base Sepolia");
}

if (counterInstanceSepolia != address(0)) {
vm.createSelectFork(vm.envString("SEPOLIA_RPC"));
uint256 counterValueSepolia = Counter(counterInstanceSepolia)
.counter();
console.log("Counter value on Sepolia: ", counterValueSepolia);
} else {
console.log("Counter not yet deployed on Sepolia");
}
}
}
38 changes: 33 additions & 5 deletions script/incrementCounters.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,39 @@ contract IncrementCounters is Script {
11155111
);

address[] memory instances = new address[](4);
instances[0] = counterForwarderArbitrumSepolia;
instances[1] = counterForwarderOptimismSepolia;
instances[2] = counterForwarderBaseSepolia;
instances[3] = counterForwarderSepolia;
// Count non-zero addresses
uint256 nonZeroCount = 0;
if (counterForwarderArbitrumSepolia != address(0)) nonZeroCount++;
if (counterForwarderOptimismSepolia != address(0)) nonZeroCount++;
if (counterForwarderBaseSepolia != address(0)) nonZeroCount++;
if (counterForwarderSepolia != address(0)) nonZeroCount++;

address[] memory instances = new address[](nonZeroCount);
uint256 index = 0;
if (counterForwarderArbitrumSepolia != address(0)) {
instances[index] = counterForwarderArbitrumSepolia;
index++;
} else {
console.log("Arbitrum Sepolia forwarder not yet deployed");
}
if (counterForwarderOptimismSepolia != address(0)) {
instances[index] = counterForwarderOptimismSepolia;
index++;
} else {
console.log("Optimism Sepolia forwarder not yet deployed");
}
if (counterForwarderBaseSepolia != address(0)) {
instances[index] = counterForwarderBaseSepolia;
index++;
} else {
console.log("Base Sepolia forwarder not yet deployed");
}
if (counterForwarderSepolia != address(0)) {
instances[index] = counterForwarderSepolia;
index++;
} else {
console.log("Sepolia forwarder not yet deployed");
}

vm.startBroadcast(deployerPrivateKey);
gateway.incrementCounters(instances);
Expand Down

0 comments on commit 77bb303

Please sign in to comment.