Skip to content

Commit

Permalink
chore(contracts): apply linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsadface committed Oct 15, 2024
1 parent 7f42ecf commit 4a33cab
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 74 deletions.
15 changes: 9 additions & 6 deletions contracts/script/GenerateAlloc.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,15 @@ contract GenerateAlloc is Script {
function setStaking() internal {
address impl = Predeploys.getImplAddress(Predeploys.Staking);

address tmp = address(new IPTokenStaking(
1 gwei, // stakingRounding
1000, // defaultCommissionRate, 10%
5000, // defaultMaxCommissionRate, 50%
500 // defaultMaxCommissionChangeRate, 5%
));
address tmp = address(
new IPTokenStaking(
1 gwei, // stakingRounding
1000, // defaultCommissionRate, 10%
5000, // defaultMaxCommissionRate, 50%
500 // defaultMaxCommissionChangeRate, 5%
)
);

console2.log("tpm", tmp);
vm.etch(impl, tmp.code);

Expand Down
57 changes: 19 additions & 38 deletions contracts/script/TestPrecompileUpgrades.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { EIP1967Helper } from "./utils/EIP1967Helper.sol";
import { Predeploys } from "../src/libraries/Predeploys.sol";

abstract contract MockNewFeatures {
function foo() external pure returns(string memory) {
function foo() external pure returns (string memory) {
return "bar";
}
}
Expand All @@ -27,17 +27,16 @@ contract IPTokenStakingV2 is IPTokenStaking, MockNewFeatures {
uint32 defaultCommissionRate,
uint32 defaultMaxCommissionRate,
uint32 defaultMaxCommissionChangeRate
) IPTokenStaking(stakingRounding, defaultCommissionRate, defaultMaxCommissionRate, defaultMaxCommissionChangeRate) {

}
)
IPTokenStaking(stakingRounding, defaultCommissionRate, defaultMaxCommissionRate, defaultMaxCommissionChangeRate)
{}
}

contract IPTokenSlashingV2 is IPTokenSlashing, MockNewFeatures {
constructor(address ipTokenStaking) IPTokenSlashing(ipTokenStaking) {}
}

contract UpgradeEntrypointV2 is UpgradeEntrypoint, MockNewFeatures {
}
contract UpgradeEntrypointV2 is UpgradeEntrypoint, MockNewFeatures {}

/**
* @title TestPrecompileUpgrades
Expand All @@ -60,22 +59,18 @@ contract TestPrecompileUpgrades is Script {
vm.startBroadcast(upgradeKey);

// ---- Staking
address newImpl = address(new IPTokenStakingV2(
1 gwei, // stakingRounding
1000, // defaultCommissionRate, 10%
5000, // defaultMaxCommissionRate, 50%
500 // defaultMaxCommissionChangeRate, 5%
));
ProxyAdmin proxyAdmin = ProxyAdmin(
EIP1967Helper.getAdmin(Predeploys.Staking)
address newImpl = address(
new IPTokenStakingV2(
1 gwei, // stakingRounding
1000, // defaultCommissionRate, 10%
5000, // defaultMaxCommissionRate, 50%
500 // defaultMaxCommissionChangeRate, 5%
)
);
ProxyAdmin proxyAdmin = ProxyAdmin(EIP1967Helper.getAdmin(Predeploys.Staking));
console2.log("staking proxy admin", address(proxyAdmin));
console2.log("staking proxy admin owner", proxyAdmin.owner());
proxyAdmin.upgradeAndCall(
ITransparentUpgradeableProxy(Predeploys.Staking),
newImpl,
""
);
proxyAdmin.upgradeAndCall(ITransparentUpgradeableProxy(Predeploys.Staking), newImpl, "");
if (EIP1967Helper.getImplementation(Predeploys.Staking) != newImpl) {
revert("Staking not upgraded");
}
Expand All @@ -84,19 +79,11 @@ contract TestPrecompileUpgrades is Script {
}

// ---- Slashing
newImpl = address(new IPTokenSlashingV2(
Predeploys.Staking
));
proxyAdmin = ProxyAdmin(
EIP1967Helper.getAdmin(Predeploys.Slashing)
);
newImpl = address(new IPTokenSlashingV2(Predeploys.Staking));
proxyAdmin = ProxyAdmin(EIP1967Helper.getAdmin(Predeploys.Slashing));
console2.log("slashing proxy admin", address(proxyAdmin));
console2.log("slashing proxy admin owner", proxyAdmin.owner());
proxyAdmin.upgradeAndCall(
ITransparentUpgradeableProxy(Predeploys.Slashing),
newImpl,
""
);
proxyAdmin.upgradeAndCall(ITransparentUpgradeableProxy(Predeploys.Slashing), newImpl, "");
if (EIP1967Helper.getImplementation(Predeploys.Slashing) != newImpl) {
revert("Slashing not upgraded");
}
Expand All @@ -106,17 +93,11 @@ contract TestPrecompileUpgrades is Script {

// ---- Upgrades
newImpl = address(new UpgradeEntrypointV2());
proxyAdmin = ProxyAdmin(
EIP1967Helper.getAdmin(Predeploys.Upgrades)
);
proxyAdmin = ProxyAdmin(EIP1967Helper.getAdmin(Predeploys.Upgrades));
console2.log("upgrades proxy admin", address(proxyAdmin));
console2.log("upgrades proxy admin owner", proxyAdmin.owner());

proxyAdmin.upgradeAndCall(
ITransparentUpgradeableProxy(Predeploys.Upgrades),
newImpl,
""
);
proxyAdmin.upgradeAndCall(ITransparentUpgradeableProxy(Predeploys.Upgrades), newImpl, "");
if (keccak256(abi.encode(UpgradeEntrypointV2(Predeploys.Upgrades).foo())) != keccak256(abi.encode("bar"))) {
revert("Upgraded to wrong iface");
}
Expand Down
45 changes: 21 additions & 24 deletions contracts/test/script/DeployCore.t.sol
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
// // SPDX-License-Identifier: BUSL-1.1
// pragma solidity ^0.8.23;
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.23;
// /* solhint-disable no-console */
// /* solhint-disable max-line-length */
// /// NOTE: pragma allowlist-secret must be inline (same line as the pubkey hex string) to avoid false positive
// /// flag "Hex High Entropy String" in CI run detect-secrets
/// NOTE: pragma allowlist-secret must be inline (same line as the pubkey hex string) to avoid false positive
/// flag "Hex High Entropy String" in CI run detect-secrets

// import { Test } from "forge-std/Test.sol";
import { Test } from "forge-std/Test.sol";

// import { DeployCore } from "../../script/DeployCore.s.sol";

// contract DeployCoreTest is Test {
// DeployCore private deployCore;

// function setUp() public {
// deployCore = new DeployCore();
// }

// function testDeployDeployCore_run() public {
// // Network shall not deploy the IPTokenStaking contract if IPTOKENSTAKING_DEPLOYER_KEY not set.
// vm.chainId(1513);
// // solhint-disable
// vm.expectRevert('vm.envUint: environment variable "IPTOKENSTAKING_DEPLOYER_KEY" not found');
// deployCore.run();

// // Network shall deploy the IPTokenStaking contract.
// vm.setEnv("IPTOKENSTAKING_DEPLOYER_KEY", "0x123456789abcdef");
// deployCore.run();
// }
// }
contract DeployCoreTest is Test {
// DeployCore private deployCore;
// function setUp() public {
// deployCore = new DeployCore();
// }
// function testDeployDeployCore_run() public {
// // Network shall not deploy the IPTokenStaking contract if IPTOKENSTAKING_DEPLOYER_KEY not set.
// vm.chainId(1513);
// // solhint-disable
// vm.expectRevert('vm.envUint: environment variable "IPTOKENSTAKING_DEPLOYER_KEY" not found');
// deployCore.run();
// // Network shall deploy the IPTokenStaking contract.
// vm.setEnv("IPTOKENSTAKING_DEPLOYER_KEY", "0x123456789abcdef");
// deployCore.run();
// }
}
4 changes: 1 addition & 3 deletions contracts/test/upgrade/UpgradeEntryPoint.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ pragma solidity ^0.8.23;
/// NOTE: pragma allowlist-secret must be inline (same line as the pubkey hex string) to avoid false positive
/// flag "Hex High Entropy String" in CI run detect-secrets

import { UpgradeEntrypoint, IUpgradeEntrypoint } from "../../src/protocol/UpgradeEntrypoint.sol";
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import { IUpgradeEntrypoint } from "../../src/protocol/UpgradeEntrypoint.sol";

import { Test } from "../utils/Test.sol";

contract UpgradeEntrypointTest is Test {

function testUpgradeEntrypoint_planUpgrade() public {
// Network shall allow the protocol owner to submit an upgrade plan.
string memory name = "upgrade";
Expand Down
4 changes: 1 addition & 3 deletions contracts/test/utils/Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ pragma solidity ^0.8.23;
/* solhint-disable no-console */
/* solhint-disable max-line-length */

import { console2 } from "forge-std/console2.sol";
import { Test as ForgeTest } from "forge-std/Test.sol";
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import { IPTokenStaking } from "../../src/protocol/IPTokenStaking.sol";
import { IPTokenSlashing } from "../../src/protocol/IPTokenSlashing.sol";
Expand All @@ -22,7 +20,7 @@ contract Test is ForgeTest {
IPTokenSlashing internal ipTokenSlashing;
UpgradeEntrypoint internal upgradeEntrypoint;

function setUp() virtual public {
function setUp() public virtual {
GenerateAlloc initializer = new GenerateAlloc();
initializer.disableStateDump(); // Faster tests. Don't call to verify JSON output
initializer.setAdminAddresses(upgradeAdmin, admin);
Expand Down

0 comments on commit 4a33cab

Please sign in to comment.