Skip to content

Commit 935160c

Browse files
committed
feat: formalize ethereum test for variables/helper
1 parent 0ddbeec commit 935160c

File tree

1 file changed

+62
-3
lines changed

1 file changed

+62
-3
lines changed

packages/client/src/test-utils.ts

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
import { local, staging } from '@aave/env';
44
import type { AnyVariables } from '@aave/graphql';
55
import { schema } from '@aave/graphql/test-utils';
6-
import { chainId } from '@aave/types';
6+
import {
7+
type BigDecimal,
8+
bigDecimal,
9+
chainId,
10+
type EvmAddress,
11+
} from '@aave/types';
712
import type { TypedDocumentNode } from '@urql/core';
813
import { validate } from 'graphql';
914
import type { ValidationRule } from 'graphql/validation/ValidationContext';
10-
import { createWalletClient, http, type WalletClient } from 'viem';
15+
import {
16+
createPublicClient,
17+
createWalletClient,
18+
http,
19+
parseEther,
20+
type WalletClient,
21+
} from 'viem';
1122
import { privateKeyToAccount } from 'viem/accounts';
1223
import { sepolia } from 'viem/chains';
1324
import { expect } from 'vitest';
@@ -18,7 +29,13 @@ export const signer = privateKeyToAccount(import.meta.env.PRIVATE_KEY);
1829
export const environment =
1930
import.meta.env.ENVIRONMENT === 'local' ? local : staging;
2031

21-
export const tenderlyFork = chainId(99999999);
32+
export const ETHEREUM_FORK_ID = chainId(99999999);
33+
34+
export const ETHEREUM_FORK_RPC_URL =
35+
'https://virtual.mainnet.rpc.tenderly.co/27ff3c60-0e2c-4d46-8190-f5170dc7da8c';
36+
37+
// Re-export for convenience
38+
export { bigDecimal } from '@aave/types';
2239

2340
export const client = AaveClient.create({
2441
environment,
@@ -30,6 +47,48 @@ export const wallet: WalletClient = createWalletClient({
3047
transport: http(),
3148
});
3249

50+
// Tenderly RPC type for setBalance
51+
type TSetBalanceRpc = {
52+
Method: 'tenderly_setBalance';
53+
Parameters: [addresses: string[], amount: string];
54+
ReturnType: string;
55+
};
56+
57+
/**
58+
* Fund an address on Tenderly fork with specified ETH amount
59+
* @param address - Address to fund
60+
* @param amount - Amount in ETH (BigDecimal string, e.g., "1.5" for 1.5 ETH)
61+
* @returns Transaction hash
62+
*/
63+
export async function fundAddress(
64+
address: EvmAddress,
65+
amount: BigDecimal = bigDecimal('1.0'), // 1 ETH
66+
): Promise<string> {
67+
// Create client with fork chain - you'll need to replace this with your actual fork chain config
68+
const publicClient = createPublicClient({
69+
chain: {
70+
id: ETHEREUM_FORK_ID,
71+
name: 'Tenderly Fork',
72+
network: 'tenderly-fork',
73+
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
74+
rpcUrls: {
75+
default: { http: [ETHEREUM_FORK_RPC_URL] },
76+
},
77+
},
78+
transport: http(ETHEREUM_FORK_RPC_URL),
79+
});
80+
81+
const amountInWei = parseEther(amount);
82+
const amountHex = `0x${amountInWei.toString(16)}`;
83+
84+
const txHash = await publicClient.request<TSetBalanceRpc>({
85+
method: 'tenderly_setBalance',
86+
params: [[address], amountHex],
87+
});
88+
89+
return txHash;
90+
}
91+
3392
const messages: Record<GraphQLErrorCode, string> = {
3493
[GraphQLErrorCode.UNAUTHENTICATED]:
3594
"Unauthenticated - Authentication is required to access '<operation>'",

0 commit comments

Comments
 (0)