Skip to content

Commit 0cea950

Browse files
committed
fix: parsing error && node config usage
1 parent 927c9a1 commit 0cea950

8 files changed

Lines changed: 76 additions & 16 deletions

File tree

tests/base/config/env.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const STAND_CONFIGS = new Map<string, StandConfig>([
7575
: NETWORKS_CONFIG.testnet.ETHEREUM_HOODI.rpcUrl,
7676
},
7777
nodeConfig: {
78-
rpcUrlToMock: `**/api/rpc?chainId=560048`,
78+
rpcUrlToMock: `**/api/rpc?chainId=560048`, // not required
7979
rpcUrl: process.env.RPC_URL as string,
8080
host: '127.0.0.1',
8181
port: 8545,

tests/base/contracts/stethContract.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { formatEther, getContract } from 'viem';
1+
import { Address, formatEther, getContract } from 'viem';
22

33
import { callReadMethodSilent, getClient } from '../providers';
44
import { getLocatorContract } from './lidoLocator';
@@ -23,6 +23,13 @@ export const getPooledEthByShares = async (shares: bigint) => {
2323
);
2424
};
2525

26+
export const getStEthBalance = async (address: Address) => {
27+
const contract = await getStethContract();
28+
return formatEther(
29+
await callReadMethodSilent(contract, 'balanceOf', [address]),
30+
);
31+
};
32+
2633
export const getPooledEthBySharesRoundUp = async (shares: bigint) => {
2734
const contract = await getStethContract();
2835

tests/base/providers/clients.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Address,
33
createPublicClient,
44
createTestClient,
5+
formatEther,
56
http,
67
publicActions,
78
walletActions,
@@ -19,7 +20,7 @@ export const getTestClient = () =>
1920

2021
export const getBalanceEth = async (address: Address) => {
2122
const testClient = getTestClient();
22-
return await testClient.getBalance({ address: address });
23+
return formatEther(await testClient.getBalance({ address: address }));
2324
};
2425

2526
export const getClient = () =>

tests/base/tests/scenarios/oneStepProcess.spec.ts

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import {
2121
getTotalMintingCapacityShares,
2222
getPooledEthBySharesRoundUp,
2323
getWithdrawValue,
24+
getStEthBalance,
2425
} from '../../contracts';
2526
import process from 'node:process';
26-
import { getBalanceEth } from '../../providers';
27+
import { getBalanceEth, getClient } from '../../providers';
2728

2829
const CONFIRM_EXPIRY = 86400;
2930
const NO_FEE_RATE = 100;
@@ -72,12 +73,17 @@ test.describe.serial('One step process', () => {
7273
test('Create vault connected to vault hub && configure with all roles ', async ({
7374
ethereumNodeService,
7475
}) => {
76+
const vaultCreatorAccount = ethereumNodeService.getAccount(
77+
getPermissionRole(ROLES.DEFAULT_ADMIN).index,
78+
);
79+
const publicClient = getClient();
80+
const vaultCreatorBalanceBeforeCreate = await publicClient.getBalance({
81+
address: vaultCreatorAccount.address as Address,
82+
});
83+
7584
const vaultData =
7685
await test.step('Create vault connected to VaultHub && grant all VM roles', async () => {
7786
const additionalRoles = buildAdditionalRoles(ethereumNodeService);
78-
const vaultCreatorPK = ethereumNodeService.getAccount(
79-
getPermissionRole(ROLES.DEFAULT_ADMIN).index,
80-
).secretKey;
8187

8288
return await lsvCLI.factory.createVaultConnectedToVh({
8389
defaultAdmin: roles.defaultAdmin.address,
@@ -86,7 +92,7 @@ test.describe.serial('One step process', () => {
8692
confirmExpiry: CONFIRM_EXPIRY,
8793
nodeOperatorFeeRate: NO_FEE_RATE,
8894
roles: additionalRoles,
89-
privateKey: vaultCreatorPK,
95+
privateKey: vaultCreatorAccount.secretKey,
9096
});
9197
});
9298

@@ -105,10 +111,29 @@ test.describe.serial('One step process', () => {
105111
).toBe(expectedVaultConnection);
106112
});
107113

108-
await test.step('Check vault metrics', async () => {
114+
await test.step('Check collateral', async () => {
115+
const receipt =
116+
(await publicClient
117+
.getTransactionReceipt({ hash: vaultData.txHash })
118+
.catch(() => undefined)) ||
119+
(await publicClient.waitForTransactionReceipt({
120+
hash: vaultData.txHash,
121+
}));
122+
const vaultCreatorBalanceAfterCreation = await publicClient.getBalance({
123+
address: vaultCreatorAccount.address as Address,
124+
});
125+
const txFee = receipt.gasUsed * receipt.effectiveGasPrice;
126+
const vaultCreatorBalanceDifference =
127+
vaultCreatorBalanceBeforeCreate -
128+
vaultCreatorBalanceAfterCreation -
129+
txFee;
109130
const { totalValueEth, collateralEth } =
110131
await lsvCLI.dashboard.overview(dashboardAddress);
111132

133+
expect(
134+
vaultCreatorBalanceDifference,
135+
`Vault creation requires collateral of ${LIDO_CONNECTION_COLLATERAL} ETH`,
136+
).toBe(parseEther(LIDO_CONNECTION_COLLATERAL));
112137
expect(
113138
collateralEth,
114139
`Vault creation requires collateral of ${LIDO_CONNECTION_COLLATERAL} ETH`,
@@ -289,6 +314,9 @@ test.describe.serial('One step process', () => {
289314
ethereumNodeService.getAccount(getPermissionRole(ROLES.BURN).index)
290315
.address,
291316
);
317+
const recipientStEthBalanceBeforeMint = await getStEthBalance(
318+
recipientRepayRoleAddress,
319+
);
292320

293321
await lsvCLI.vo.mintStEth(
294322
vaultAddress,
@@ -304,6 +332,11 @@ test.describe.serial('One step process', () => {
304332
const liabilityShares = await getLiabilityShares(dashboardAddress);
305333
const contractLiabilityStEth =
306334
await getPooledEthBySharesRoundUp(liabilityShares);
335+
const calculatedRecipientStEthBalanceAfterMint =
336+
parseFloat(recipientStEthBalanceBeforeMint) + parseFloat(mintAmount);
337+
const recipientStEthBalanceAfterMint = parseFloat(
338+
await getStEthBalance(recipientRepayRoleAddress),
339+
);
307340

308341
expect(
309342
dashboardLiabilityShares,
@@ -313,7 +346,10 @@ test.describe.serial('One step process', () => {
313346
dashboardLiabilityStEth,
314347
'Expect dashboard liability stETH to be correct with contract',
315348
).toBe(contractLiabilityStEth);
316-
// add check for stETH to be mint to recipient
349+
expect(
350+
recipientStEthBalanceAfterMint,
351+
'Expect recipient stEth address receives correct amount',
352+
).toBe(calculatedRecipientStEthBalanceAfterMint);
317353
});
318354

319355
test(`Burn stETH as ${ROLES.BURN}`, async ({ ethereumNodeService }) => {
@@ -376,10 +412,10 @@ test.describe.serial('One step process', () => {
376412
await lsvCLI.dashboard.overview(dashboardAddress);
377413

378414
const withdrawRecipientBalanceAfterWithdraw = parseFloat(
379-
formatEther(await getBalanceEth(withdrawRecipientAddress)),
415+
await getBalanceEth(withdrawRecipientAddress),
380416
);
381417
const calculatedWithdrawRecipientBalanceAfter =
382-
parseFloat(formatEther(withdrawRecipientBalanceBeforeWithdraw)) +
418+
parseFloat(withdrawRecipientBalanceBeforeWithdraw) +
383419
parseFloat(availableToWithdrawalEthBefore);
384420

385421
const contractWithdrawableValue = formatEther(

tests/base/tests/test.fixture.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ export const test = base.extend<
2020
],
2121
ethereumNodeService: [
2222
async ({ nodeRunOptions }, use) => {
23-
const nodeConfig = getStandConfig().nodeConfig;
23+
const { networkConfig, nodeConfig } = getStandConfig();
2424
const ethereumNodeService = new EthereumNodeService({
2525
...nodeConfig,
2626
runOptions: nodeRunOptions,
27+
rpcUrl: networkConfig.rpcUrl,
2728
});
2829
await ethereumNodeService.startNode();
2930

tests/base/utils/lsvCLI/programs/dashboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const overview = async (
106106
case 'Reserve Ratio, %':
107107
reserveRatioPercent = value;
108108
break;
109-
case 'Force Rebalance Threshold':
109+
case 'Force Rebalance Threshold, %':
110110
forceRebalanceThreshold = value;
111111
break;
112112
case 'stVault Share Limit, stETH':

tests/base/utils/lsvCLI/programs/factory.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawn } from 'child_process';
2-
import { Address } from 'viem';
2+
import { Address, Hex } from 'viem';
33
import type { CreateVaultParams, VaultCreationResult } from '../types';
44

55
export const createVaultConnectedToVh = async (
@@ -68,6 +68,13 @@ export const createVaultConnectedToVh = async (
6868
(line) => line.includes('Dashboard Address') && line.includes('0x'),
6969
);
7070

71+
const txHashLine = stdout
72+
.split('\n')
73+
.find(
74+
(line) => line.includes('Transaction Hash ') && line.includes('0x'),
75+
);
76+
const txHashMatch = txHashLine?.match(/(0x[a-fA-F0-9]{64})/);
77+
7178
const vaultAddressMatch = vaultLine?.match(/(0x[a-fA-F0-9]{40})/);
7279
const dashboardAddressMatch = dashboardLine?.match(/(0x[a-fA-F0-9]{40})/);
7380

@@ -83,9 +90,16 @@ export const createVaultConnectedToVh = async (
8390
);
8491
}
8592

93+
if (!txHashMatch?.[1]) {
94+
return reject(
95+
new Error('Transaction hash not found in CLI output:\n' + stdout),
96+
);
97+
}
98+
8699
resolve({
87100
vaultAddress: vaultAddressMatch[1] as Address,
88101
dashboardAddress: dashboardAddressMatch[1] as Address,
102+
txHash: txHashMatch[1] as Hex,
89103
});
90104
});
91105

tests/base/utils/lsvCLI/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Address } from 'viem';
1+
import { Address, Hex } from 'viem';
22

33
export type RoleAssignment = {
44
account: string;
@@ -20,6 +20,7 @@ export type CreateVaultParams = {
2020
export type VaultCreationResult = {
2121
vaultAddress: Address;
2222
dashboardAddress: Address;
23+
txHash: Hex;
2324
};
2425

2526
export type VaultInfo = {

0 commit comments

Comments
 (0)