Initial commit: add .gitignore and README
This commit is contained in:
94
tests/utils/test-helpers.ts
Normal file
94
tests/utils/test-helpers.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { JsonRpcProvider, Wallet } from "ethers";
|
||||
import { Strategy } from "../../src/strategy.schema.js";
|
||||
|
||||
/**
|
||||
* Create a mock JSON-RPC provider for testing
|
||||
*/
|
||||
export function createMockProvider(): JsonRpcProvider {
|
||||
const provider = new JsonRpcProvider("http://localhost:8545");
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mock wallet for testing
|
||||
*/
|
||||
export function createMockSigner(privateKey?: string): Wallet {
|
||||
const key = privateKey || "0x" + "1".repeat(64);
|
||||
return new Wallet(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mock strategy for testing
|
||||
*/
|
||||
export function createMockStrategy(overrides?: Partial<Strategy>): Strategy {
|
||||
return {
|
||||
name: "Test Strategy",
|
||||
chain: "mainnet",
|
||||
steps: [
|
||||
{
|
||||
id: "step1",
|
||||
action: {
|
||||
type: "aaveV3.supply",
|
||||
asset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||
amount: "1000000",
|
||||
},
|
||||
},
|
||||
],
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mock adapter (generic helper)
|
||||
*/
|
||||
export function createMockAdapter(adapterName: string): any {
|
||||
return {
|
||||
name: adapterName,
|
||||
provider: createMockProvider(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a fork for testing (requires Anvil or similar)
|
||||
*/
|
||||
export async function setupFork(
|
||||
rpcUrl: string,
|
||||
blockNumber?: number
|
||||
): Promise<JsonRpcProvider> {
|
||||
const provider = new JsonRpcProvider(rpcUrl);
|
||||
|
||||
if (blockNumber) {
|
||||
// In a real implementation, you'd use anvil_reset or similar
|
||||
// For now, just return the provider
|
||||
}
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a specific number of blocks
|
||||
*/
|
||||
export async function waitForBlocks(
|
||||
provider: JsonRpcProvider,
|
||||
blocks: number
|
||||
): Promise<void> {
|
||||
const currentBlock = await provider.getBlockNumber();
|
||||
const targetBlock = currentBlock + blocks;
|
||||
|
||||
while ((await provider.getBlockNumber()) < targetBlock) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create test addresses
|
||||
*/
|
||||
export const TEST_ADDRESSES = {
|
||||
USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||
USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
||||
DAI: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
||||
WETH: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
EXECUTOR: "0x1234567890123456789012345678901234567890",
|
||||
USER: "0x1111111111111111111111111111111111111111",
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user