Skip to content

Commit 90f948b

Browse files
authored
Merge pull request #605 from anoma/heueristik/cover-the-deploy-script-predictions
test(contracts): cover the deploy script predictions
2 parents 93ba81f + 8290e26 commit 90f948b

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

contracts/test/scripts/DeployProtocolAdapterImplementation.t.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import {RiscZeroRouterFixture} from "../fixtures/RiscZeroRouterFixture.sol";
1010

1111
/// @notice Checks the implementation deploy script.
1212
contract DeployProtocolAdapterImplementationTest is RiscZeroRouterFixture {
13+
/// @dev The local development chain, which has no RISC Zero deployment.
14+
uint256 internal constant _UNSUPPORTED_CHAIN_ID = 31337;
15+
1316
function test_run_deploys_deterministically() public {
1417
_deployRiscZeroRouter();
1518

@@ -44,4 +47,20 @@ contract DeployProtocolAdapterImplementationTest is RiscZeroRouterFixture {
4447
);
4548
script.run();
4649
}
50+
51+
function test_predict_matches_the_address_run_deploys() public {
52+
_deployRiscZeroRouter();
53+
54+
DeployProtocolAdapterImplementation script = new DeployProtocolAdapterImplementation();
55+
(address predicted,) = script.predict(block.chainid);
56+
57+
assertEq(script.run(), predicted, "prediction differs from the deployed implementation");
58+
}
59+
60+
function test_predict_reverts_on_an_unsupported_network() public {
61+
DeployProtocolAdapterImplementation script = new DeployProtocolAdapterImplementation();
62+
63+
vm.expectRevert(abi.encodeWithSelector(SupportedNetworks.UnsupportedNetwork.selector, _UNSUPPORTED_CHAIN_ID));
64+
script.predict(_UNSUPPORTED_CHAIN_ID);
65+
}
4766
}

contracts/test/scripts/DeployProtocolAdapterProxy.t.sol

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,32 @@ contract DeployProtocolAdapterProxyTest is RiscZeroRouterFixture, DeploymentsFix
6363
script.run({isProduction: false});
6464
}
6565

66+
function test_predict_matches_the_addresses_run_deploys() public {
67+
_deployRiscZeroRouter();
68+
69+
DeployProtocolAdapterProxy script = new DeployProtocolAdapterProxy();
70+
71+
(address predictedProxy, address predictedImplementation) = script.predict({isProduction: false});
72+
(address proxy, address implementation,,) = script.run({isProduction: false});
73+
74+
assertEq(proxy, predictedProxy, "staging: prediction differs from the deployed proxy");
75+
assertEq(
76+
implementation, predictedImplementation, "staging: prediction differs from the deployed implementation"
77+
);
78+
79+
(address predictedProductionProxy,) = script.predict({isProduction: true});
80+
(address productionProxy,,,) = script.run({isProduction: true});
81+
82+
assertEq(productionProxy, predictedProductionProxy, "production: prediction differs from the deployed proxy");
83+
}
84+
85+
function test_environmentName_names_the_environments() public {
86+
DeployProtocolAdapterProxy script = new DeployProtocolAdapterProxy();
87+
88+
assertEq(script.environmentName({isProduction: false}), "staging", "staging environment name differs");
89+
assertEq(script.environmentName({isProduction: true}), "production", "production environment name differs");
90+
}
91+
6692
/// @notice Runs the deploy script for the environment and checks that the proxy lands at the predicted
6793
/// deterministic address, delegates to a deployed implementation, and is initialized with the environment owner.
6894
/// @param isProduction Whether to deploy the production or the staging environment proxy.

0 commit comments

Comments
 (0)