Skip to content

Commit aab52bb

Browse files
committed
Fixed unit tests
1 parent e3a4ed6 commit aab52bb

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

contracts/hardhat.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const SONIC_DEPLOYER = MAINNET_DEPLOYER;
7373
const SONIC_ADMIN = "0xAdDEA7933Db7d83855786EB43a238111C69B00b6";
7474
// 2/8 multi-sig that controls fund allocations. Aka "Guardian".
7575
const SONIC_STRATEGIST = "0x63cdd3072F25664eeC6FAEFf6dAeB668Ea4de94a";
76+
const MAINNET_RELAYER = "0x4b91827516f79d6F6a1F292eD99671663b09169a";
7677

7778
const MULTICHAIN_STRATEGIST = "0x4FF1b9D9ba8558F5EAfCec096318eA0d8b541971";
7879

@@ -201,6 +202,13 @@ const localEnvStrategist =
201202
: MULTICHAIN_STRATEGIST
202203
: 0;
203204

205+
const localEnvRegistrator =
206+
process.env.FORK === "true"
207+
? isHoodiFork
208+
? HOODI_RELAYER
209+
: MAINNET_RELAYER
210+
: 1; // signer at index 2
211+
204212
module.exports = {
205213
solidity: {
206214
version: "0.8.28",
@@ -407,6 +415,12 @@ module.exports = {
407415
multichainStrategistAddr: {
408416
default: MULTICHAIN_STRATEGIST,
409417
},
418+
registratorAddr: {
419+
default: 2,
420+
localhost: localEnvRegistrator,
421+
mainnet: MAINNET_RELAYER,
422+
hoodi: HOODI_RELAYER,
423+
},
410424
},
411425
contractSizer: {
412426
alphaSort: true,

contracts/test/_fixture.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,9 +2034,10 @@ async function compoundingStakingSSVStrategyFixture() {
20342034
*/
20352035
} else {
20362036
fixture.ssvNetwork = await ethers.getContract("MockSSVNetwork");
2037-
const { governorAddr } = await getNamedAccounts();
2037+
const { governorAddr, registratorAddr } = await getNamedAccounts();
20382038
const { oethVault, weth } = fixture;
20392039
const sGovernor = await ethers.provider.getSigner(governorAddr);
2040+
const sRegistrator = await ethers.provider.getSigner(registratorAddr);
20402041

20412042
// Approve Strategy
20422043
await oethVault
@@ -2053,13 +2054,13 @@ async function compoundingStakingSSVStrategyFixture() {
20532054

20542055
await compoundingStakingSSVStrategy
20552056
.connect(sGovernor)
2056-
.setRegistrator(governorAddr);
2057+
.setRegistrator(registratorAddr);
20572058

20582059
await compoundingStakingSSVStrategy
20592060
.connect(sGovernor)
20602061
.setHarvesterAddress(fixture.oethHarvester.address);
20612062

2062-
fixture.validatorRegistrator = sGovernor;
2063+
fixture.validatorRegistrator = sRegistrator;
20632064
}
20642065

20652066
return fixture;

contracts/test/behaviour/strategy.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,18 @@ const shouldBehaveLikeStrategy = (context) => {
218218

219219
const harvesterSigner = await impersonateAndFund(harvester.address);
220220
for (const signer of [harvesterSigner, governor, strategist, matt]) {
221-
await expect(
222-
strategy
221+
try {
222+
await strategy
223223
.connect(signer)
224-
.withdraw(vault.address, assets[0].address, parseUnits("10"))
225-
).to.revertedWith("Caller is not the Vault");
224+
.withdraw(vault.address, assets[0].address, parseUnits("1"));
225+
expect.fail("Expected transaction to revert");
226+
} catch (error) {
227+
console.log("Error message:", error.message);
228+
expect(error.message).to.be.oneOf([
229+
"VM Exception while processing transaction: reverted with reason string 'Caller is not the Vault'",
230+
"VM Exception while processing transaction: reverted with reason string 'Caller not Vault or Registrator'",
231+
]);
232+
}
226233
}
227234
});
228235
it("Should be able to call withdraw all by vault", async () => {

contracts/test/strategies/compoundingSSVStaking.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const {
88
setBalance,
99
setStorageAt,
1010
} = require("@nomicfoundation/hardhat-network-helpers");
11-
const { isCI } = require("../helpers");
11+
const { isCI, getAssetAddresses } = require("../helpers");
1212
const { shouldBehaveLikeGovernable } = require("../behaviour/governable");
1313
const { shouldBehaveLikeStrategy } = require("../behaviour/strategy");
1414
const { MAX_UINT256, ZERO_BYTES32 } = require("../../utils/constants");
@@ -143,12 +143,11 @@ describe("Unit test: Compounding SSV Staking Strategy", function () {
143143
it("SSV network should have allowance to spend SSV tokens of the strategy", async () => {
144144
const { compoundingStakingSSVStrategy, ssv } = fixture;
145145

146-
const ssvNetworkAddress =
147-
await compoundingStakingSSVStrategy.SSV_NETWORK();
146+
const ssvNetworkAddress = await getAssetAddresses(deployments);
148147
await expect(
149148
await ssv.allowance(
150149
compoundingStakingSSVStrategy.address,
151-
ssvNetworkAddress
150+
ssvNetworkAddress.SSVNetwork
152151
)
153152
).to.equal(MAX_UINT256);
154153
});
@@ -1864,7 +1863,7 @@ describe("Unit test: Compounding SSV Staking Strategy", function () {
18641863
});
18651864

18661865
it("Should withdraw ETH from the strategy, no ETH", async () => {
1867-
const { compoundingStakingSSVStrategy, weth, josh } = fixture;
1866+
const { compoundingStakingSSVStrategy, weth, josh, oethVault } = fixture;
18681867

18691868
const depositAmount = parseEther("10");
18701869
await weth
@@ -1879,7 +1878,7 @@ describe("Unit test: Compounding SSV Staking Strategy", function () {
18791878

18801879
const withdrawTx = compoundingStakingSSVStrategy
18811880
.connect(sVault)
1882-
.withdraw(josh.address, weth.address, depositAmount);
1881+
.withdraw(oethVault.address, weth.address, depositAmount);
18831882

18841883
await expect(withdrawTx)
18851884
.to.emit(compoundingStakingSSVStrategy, "Withdrawal")
@@ -1898,7 +1897,13 @@ describe("Unit test: Compounding SSV Staking Strategy", function () {
18981897
});
18991898

19001899
it("Should withdraw ETH from the strategy, withdraw some ETH", async () => {
1901-
const { compoundingStakingSSVStrategy, weth, josh } = fixture;
1900+
const {
1901+
compoundingStakingSSVStrategy,
1902+
weth,
1903+
josh,
1904+
oethVault,
1905+
validatorRegistrator,
1906+
} = fixture;
19021907

19031908
const depositAmount = parseEther("10");
19041909
await weth
@@ -1915,9 +1920,9 @@ describe("Unit test: Compounding SSV Staking Strategy", function () {
19151920
await compoundingStakingSSVStrategy.checkBalance(weth.address);
19161921

19171922
const withdrawTx = compoundingStakingSSVStrategy
1918-
.connect(sVault)
1923+
.connect(validatorRegistrator)
19191924
.withdraw(
1920-
josh.address,
1925+
oethVault.address,
19211926
weth.address,
19221927
depositAmount.add(parseEther("5"))
19231928
);
@@ -1970,7 +1975,17 @@ describe("Unit test: Compounding SSV Staking Strategy", function () {
19701975
weth.address,
19711976
parseEther("10")
19721977
)
1973-
).to.be.revertedWith("Must specify recipient");
1978+
).to.be.revertedWith("Recipient not Vault");
1979+
});
1980+
1981+
it("Should revert when withdrawing to a user", async () => {
1982+
const { compoundingStakingSSVStrategy, weth, josh } = fixture;
1983+
1984+
await expect(
1985+
compoundingStakingSSVStrategy
1986+
.connect(sVault)
1987+
.withdraw(josh.address, weth.address, parseEther("10"))
1988+
).to.be.revertedWith("Recipient not Vault");
19741989
});
19751990

19761991
it("Should withdrawAll ETH from the strategy, no ETH", async () => {

0 commit comments

Comments
 (0)