Files
Heyue_test/frontend/scripts/verify-all-lending-functions.js
Sofio 5cb64f881e feat: 添加多链支持和 Lending 借贷系统
- 新增 ARB Sepolia + BNB Testnet 多链支持
- 添加 LendingPanel 借贷系统组件
- 添加 LendingAdminPanel 管理面板
- 添加 USDCPanel USDC 操作组件
- 添加 HoldersPanel 持有人信息组件
- 添加 AutoTestPanel 自动化测试组件
- 重构 LP 组件为模块化结构 (LP/)
- 添加多个调试和测试脚本
- 修复 USDC 精度动态配置
- 优化合约配置支持多链切换

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 23:32:29 +08:00

170 lines
6.1 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createPublicClient, http, formatUnits } from 'viem';
import { arbitrumSepolia } from 'viem/chains';
const RPC_URL = 'https://sepolia-rollup.arbitrum.io/rpc';
const LENDING_PROXY = '0xCb4E7B1069F6C26A1c27523ce4c8dfD884552d1D';
const TEST_USER = '0xa013422A5918CD099C63c8CC35283EACa99a705d'; // 有抵押品的用户
const YT_A = '0x97204190B35D9895a7a47aa7BaC61ac08De3cF05';
const client = createPublicClient({
chain: arbitrumSepolia,
transport: http(RPC_URL)
});
const testResults = {
success: [],
failed: []
};
async function testFunction(name, abi, params = []) {
try {
const result = await client.readContract({
address: LENDING_PROXY,
abi: [abi],
functionName: name,
args: params
});
testResults.success.push(name);
return { success: true, value: result };
} catch (error) {
testResults.failed.push(name);
return { success: false, error: error.message.split('\n')[0] };
}
}
async function runAllTests() {
console.log('\n=== 验证所有前端 LENDING ABI 函数 ===\n');
// 1. getCollateral - 用户查询
console.log('1⃣ getCollateral(account, asset):');
const r1 = await testFunction('getCollateral', {
inputs: [
{ internalType: 'address', name: 'account', type: 'address' },
{ internalType: 'address', name: 'asset', type: 'address' }
],
name: 'getCollateral',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function'
}, [TEST_USER, YT_A]);
console.log(r1.success ? ` ✅ 成功 - 抵押量: ${formatUnits(r1.value, 18)}` : ` ❌ 失败 - ${r1.error}`);
// 2. getBalance - 用户余额
console.log('\n2⃣ getBalance(account):');
const r2 = await testFunction('getBalance', {
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
name: 'getBalance',
outputs: [{ internalType: 'int256', name: '', type: 'int256' }],
stateMutability: 'view',
type: 'function'
}, [TEST_USER]);
console.log(r2.success ? ` ✅ 成功 - 余额: ${r2.value.toString()}` : ` ❌ 失败 - ${r2.error}`);
// 3. borrowBalanceOf - 借款余额
console.log('\n3⃣ borrowBalanceOf(account):');
const r3 = await testFunction('borrowBalanceOf', {
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
name: 'borrowBalanceOf',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function'
}, [TEST_USER]);
console.log(r3.success ? ` ✅ 成功 - 借款: ${formatUnits(r3.value, 6)} USDC` : ` ❌ 失败 - ${r3.error}`);
// 4. getTotalBorrow - 系统总借款
console.log('\n4⃣ getTotalBorrow():');
const r4 = await testFunction('getTotalBorrow', {
inputs: [],
name: 'getTotalBorrow',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function'
});
console.log(r4.success ? ` ✅ 成功 - 总借款: ${formatUnits(r4.value, 6)} USDC` : ` ❌ 失败 - ${r4.error}`);
// 5. getTotalSupply - 系统总供应
console.log('\n5⃣ getTotalSupply():');
const r5 = await testFunction('getTotalSupply', {
inputs: [],
name: 'getTotalSupply',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function'
});
console.log(r5.success ? ` ✅ 成功 - 总供应: ${formatUnits(r5.value, 6)} USDC` : ` ❌ 失败 - ${r5.error}`);
// 6. getUtilization - 资金利用率
console.log('\n6⃣ getUtilization():');
const r6 = await testFunction('getUtilization', {
inputs: [],
name: 'getUtilization',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function'
});
console.log(r6.success ? ` ✅ 成功 - 利用率: ${Number(r6.value) / 1e16}%` : ` ❌ 失败 - ${r6.error}`);
// 7. getBorrowRate - 借款利率
console.log('\n7⃣ getBorrowRate():');
const r7 = await testFunction('getBorrowRate', {
inputs: [],
name: 'getBorrowRate',
outputs: [{ internalType: 'uint64', name: '', type: 'uint64' }],
stateMutability: 'view',
type: 'function'
});
console.log(r7.success ? ` ✅ 成功 - 借款利率: ${Number(r7.value) / 1e16}%` : ` ❌ 失败 - ${r7.error}`);
// 8. getSupplyRate - 存款利率
console.log('\n8⃣ getSupplyRate():');
const r8 = await testFunction('getSupplyRate', {
inputs: [],
name: 'getSupplyRate',
outputs: [{ internalType: 'uint64', name: '', type: 'uint64' }],
stateMutability: 'view',
type: 'function'
});
console.log(r8.success ? ` ✅ 成功 - 存款利率: ${Number(r8.value) / 1e16}%` : ` ❌ 失败 - ${r8.error}`);
// 9. owner - 管理员
console.log('\n9⃣ owner():');
const r9 = await testFunction('owner', {
inputs: [],
name: 'owner',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function'
});
console.log(r9.success ? ` ✅ 成功 - Owner: ${r9.value}` : ` ❌ 失败 - ${r9.error}`);
// 10. paused - 暂停状态
console.log('\n🔟 paused():');
const r10 = await testFunction('paused', {
inputs: [],
name: 'paused',
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
stateMutability: 'view',
type: 'function'
});
console.log(r10.success ? ` ✅ 成功 - Paused: ${r10.value}` : ` ❌ 失败 - ${r10.error}`);
// 汇总
console.log('\n' + '='.repeat(60));
console.log('📊 测试结果汇总:');
console.log('='.repeat(60));
console.log(`✅ 成功: ${testResults.success.length}/10`);
console.log(` ${testResults.success.join(', ')}`);
if (testResults.failed.length > 0) {
console.log(`❌ 失败: ${testResults.failed.length}/10`);
console.log(` ${testResults.failed.join(', ')}`);
}
console.log('='.repeat(60) + '\n');
// 对比测试脚本中的错误函数
console.log('⚠️ check-lending-setup.js 中使用的错误函数:');
console.log(' getTotalLiquidity() - 不存在,应改为 getTotalSupply()');
console.log('');
}
runAllTests().catch(console.error);