Rollback proxy
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {claimGmxFundingFeesImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Claim Funding Fees', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should claim funding fees for valid account', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await claimGmxFundingFeesImpl(sdk);
|
||||
|
||||
console.log('Claim funding fees result:', result);
|
||||
assert.ok(typeof result === 'string', 'Result should be a string');
|
||||
assert.ok(result.length > 0, 'Result should not be empty');
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
// Expected behavior - may fail if no claimable fees or in test environment
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
|
||||
// Check for expected error messages
|
||||
const errorMessage = error.message;
|
||||
const expectedErrors = [
|
||||
'No funding fees available to claim',
|
||||
'Failed to claim funding fees',
|
||||
'No markets info data available'
|
||||
];
|
||||
|
||||
const hasExpectedError = expectedErrors.some(expectedError =>
|
||||
errorMessage.includes(expectedError)
|
||||
);
|
||||
|
||||
if (!hasExpectedError) {
|
||||
// Log unexpected errors for debugging
|
||||
console.warn('Unexpected error in claimGmxFundingFeesImpl:', errorMessage);
|
||||
}
|
||||
|
||||
// Still assert it's an error for test completeness
|
||||
assert.ok(true, 'Expected error occurred');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,119 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {claimGmxPriceImpactImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Claim Price Impact', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should claim price impact rebates for valid account with claimable fees', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await claimGmxPriceImpactImpl(sdk);
|
||||
|
||||
console.log('Claim price impact result:', result);
|
||||
|
||||
// Should return a success indicator
|
||||
assert.ok(typeof result === 'string', 'Result should be a string');
|
||||
assert.equal(result, 'price_impact_claimed', 'Should return success indicator');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
|
||||
// Should be a meaningful error message
|
||||
assert.ok(
|
||||
error.message.includes('No price impact fees available to claim') ||
|
||||
error.message.includes('Failed to claim price impact rebates') ||
|
||||
error.message.includes('Error claiming price impact rebates'),
|
||||
'Error message should be meaningful'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle SDK client creation for claim', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Validate SDK properties
|
||||
assert.ok(typeof sdk === 'object', 'SDK should be an object');
|
||||
assert.ok(sdk.account === testAccount, 'SDK account should match test account');
|
||||
assert.ok(typeof sdk.chainId === 'number', 'Chain ID should be a number');
|
||||
|
||||
console.log('SDK validation passed for claim');
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should automatically fetch claimable fees before claiming', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// The method should now automatically fetch claimable fees using GraphQL
|
||||
// This test verifies that the method integrates with getGmxPriceImpactRebatesImpl
|
||||
const result = await claimGmxPriceImpactImpl(sdk);
|
||||
|
||||
console.log('Auto-fetch and claim result:', result);
|
||||
|
||||
// If successful, should return the success indicator
|
||||
assert.equal(result, 'price_impact_claimed', 'Should return success indicator');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
|
||||
// Should handle the case where no claimable fees are found
|
||||
if (error.message.includes('No price impact fees available to claim')) {
|
||||
console.log('No claimable fees found - this is expected for test account');
|
||||
assert.ok(true, 'Correctly handled no claimable fees case');
|
||||
} else {
|
||||
assert.ok(
|
||||
error.message.includes('Failed to claim price impact rebates') ||
|
||||
error.message.includes('Error claiming price impact rebates'),
|
||||
'Should be a meaningful claim error'
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle chain ID validation for claim', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Should only work for Arbitrum (chainId 42161)
|
||||
assert.equal(sdk.chainId, 42161, 'Should be using Arbitrum chain ID');
|
||||
|
||||
console.log('Chain ID validation passed for claim');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should validate contract addresses for claim', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// The method should validate that proper contract addresses are available
|
||||
// This tests the ExchangeRouter contract address retrieval
|
||||
await claimGmxPriceImpactImpl(sdk);
|
||||
|
||||
console.log('Contract validation passed');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
|
||||
// Validate error messages are meaningful
|
||||
assert.ok(
|
||||
error.message.includes('No price impact fees available to claim') ||
|
||||
error.message.includes('Failed to claim price impact rebates') ||
|
||||
error.message.includes('Unsupported chain ID') ||
|
||||
error.message.includes('Error claiming price impact rebates'),
|
||||
'Should provide meaningful error messages'
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,92 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {claimGmxUiFeesImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Claim UI Fees Implementation', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
t.test('should claim UI fees for valid account', async () => {
|
||||
try {
|
||||
// Get GMX SDK client for the test account
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Call the implementation function directly
|
||||
const result = await claimGmxUiFeesImpl(sdk);
|
||||
|
||||
// Validate response
|
||||
assert.ok(typeof result === 'string', 'Result should be a string');
|
||||
assert.strictEqual(result, 'ui_fees_claimed', 'Should return success indicator');
|
||||
|
||||
console.log('UI fees claim result:', result);
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
// In test environment, this will likely fail due to no claimable fees or network issues
|
||||
// This is expected behavior in a test environment
|
||||
}
|
||||
});
|
||||
|
||||
t.test('should handle SDK initialization for different account', async () => {
|
||||
try {
|
||||
const differentAccount = '0x1234567890123456789012345678901234567890';
|
||||
|
||||
// Get GMX SDK client for a different account
|
||||
const sdk = await getClientForAddress(differentAccount);
|
||||
|
||||
// Verify SDK was created with correct account
|
||||
assert.strictEqual(sdk.account.toLowerCase(), differentAccount.toLowerCase(), 'SDK should be initialized with correct account');
|
||||
|
||||
// Call the implementation function
|
||||
const result = await claimGmxUiFeesImpl(sdk);
|
||||
|
||||
assert.ok(typeof result === 'string', 'Result should be a string');
|
||||
console.log('Different account claim result:', result);
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
t.test('should handle errors gracefully', async () => {
|
||||
try {
|
||||
// Test with invalid/empty account to see error handling
|
||||
const invalidAccount = '0x0000000000000000000000000000000000000000';
|
||||
const sdk = await getClientForAddress(invalidAccount);
|
||||
|
||||
await claimGmxUiFeesImpl(sdk);
|
||||
|
||||
// If we reach here without error, that's also valid
|
||||
console.log('Invalid account test passed without error');
|
||||
|
||||
} catch (error) {
|
||||
// Expected to fail with invalid account
|
||||
console.log('Error handling test - caught expected error:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
assert.ok(error.message.includes('Failed to claim UI fees') ||
|
||||
error.message.includes('No markets') ||
|
||||
error.message.includes('network') ||
|
||||
error.message.includes('RPC'), 'Should have meaningful error message');
|
||||
}
|
||||
});
|
||||
|
||||
t.test('should validate SDK client creation', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Validate SDK properties
|
||||
assert.ok(sdk, 'SDK should be created');
|
||||
assert.ok(sdk.account, 'SDK should have account property');
|
||||
assert.ok(sdk.chainId, 'SDK should have chainId property');
|
||||
assert.strictEqual(sdk.account.toLowerCase(), testAccount.toLowerCase(), 'SDK account should match input');
|
||||
|
||||
console.log('SDK validation passed for account:', sdk.account);
|
||||
console.log('SDK chainId:', sdk.chainId);
|
||||
|
||||
} catch (error) {
|
||||
console.warn('SDK creation error:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,16 +1,16 @@
|
||||
import {test} from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
import {closeGmxPositionImpl, getClientForAddress} from '../../src/plugins/custom/gmx'
|
||||
import {Ticker, TradeDirection} from '../../src/generated/ManagingApiTypes'
|
||||
import {TradeDirection} from '../../src/generated/ManagingApiTypes'
|
||||
|
||||
test('GMX Position Closing', async (t) => {
|
||||
await t.test('should close a long position for BTC', async () => {
|
||||
const sdk = await getClientForAddress('0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f')
|
||||
const sdk = await getClientForAddress('0x932167388dD9aad41149b3cA23eBD489E2E2DD78')
|
||||
|
||||
const result = await closeGmxPositionImpl(
|
||||
sdk,
|
||||
Ticker.SOL,
|
||||
TradeDirection.Long
|
||||
'GMX',
|
||||
TradeDirection.Short
|
||||
)
|
||||
console.log('Position closing result:', result)
|
||||
assert.ok(result, 'Position closing result should be defined')
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {getClaimableFundingFeesImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Get Claimable Funding Fees', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should get claimable funding fees for valid account', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getClaimableFundingFeesImpl(sdk);
|
||||
|
||||
console.log('Claimable funding fees result:', result);
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
|
||||
// Check that each market entry has the expected structure
|
||||
Object.values(result).forEach(marketData => {
|
||||
assert.ok(typeof marketData.claimableFundingAmountLong === 'number', 'Long amount should be a number');
|
||||
assert.ok(typeof marketData.claimableFundingAmountShort === 'number', 'Short amount should be a number');
|
||||
assert.ok(marketData.claimableFundingAmountLong >= 0, 'Long amount should be non-negative');
|
||||
assert.ok(marketData.claimableFundingAmountShort >= 0, 'Short amount should be non-negative');
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
// In test environment, this may fail due to network issues or missing data
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,47 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {getClaimableUiFeesImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Get Claimable UI Fees', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should get claimable UI fees for valid account', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getClaimableUiFeesImpl(sdk);
|
||||
|
||||
// Log total claimable amounts
|
||||
let totalFees = 0;
|
||||
let marketsWithFees = 0;
|
||||
|
||||
Object.entries(result).forEach(([marketAddress, marketData]) => {
|
||||
const amount = marketData.claimableUiFeeAmount;
|
||||
|
||||
totalFees += amount;
|
||||
|
||||
if (amount > 0) {
|
||||
marketsWithFees++;
|
||||
console.log(`Market ${marketAddress}:`);
|
||||
console.log(` Claimable UI fee amount: ${amount}`);
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`\nSummary for account ${testAccount}:`);
|
||||
console.log(`Total UI fees claimable: ${totalFees}`);
|
||||
console.log(`Markets with claimable fees: ${marketsWithFees}`);
|
||||
console.log(`Total markets checked: ${Object.keys(result).length}`);
|
||||
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
|
||||
// Check that each market entry has the expected structure
|
||||
Object.values(result).forEach(marketData => {
|
||||
assert.ok(typeof marketData.claimableUiFeeAmount === 'number', 'UI fee amount should be a number');
|
||||
assert.ok(marketData.claimableUiFeeAmount >= 0, 'UI fee amount should be non-negative');
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
// In test environment, this may fail due to network issues or missing data
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,158 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {getClientForAddress, getGmxPriceImpactRebatesImpl} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Get Price Impact Rebates', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should get price impact rebates for valid account', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getGmxPriceImpactRebatesImpl(sdk);
|
||||
|
||||
console.log('Price impact rebates result:', result);
|
||||
|
||||
// Validate the structure
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
assert.ok(Array.isArray(result.accruedPositionPriceImpactFees), 'accruedPositionPriceImpactFees should be an array');
|
||||
assert.ok(Array.isArray(result.claimablePositionPriceImpactFees), 'claimablePositionPriceImpactFees should be an array');
|
||||
|
||||
// Validate accrued fees structure (if any exist)
|
||||
result.accruedPositionPriceImpactFees.forEach(fee => {
|
||||
assert.ok(typeof fee.factor === 'bigint', 'factor should be bigint');
|
||||
assert.ok(typeof fee.value === 'bigint', 'value should be bigint');
|
||||
assert.ok(typeof fee.valueByFactor === 'bigint', 'valueByFactor should be bigint');
|
||||
assert.ok(typeof fee.timeKey === 'number', 'timeKey should be number');
|
||||
assert.ok(typeof fee.marketAddress === 'string', 'marketAddress should be string');
|
||||
assert.ok(typeof fee.tokenAddress === 'string', 'tokenAddress should be string');
|
||||
assert.ok(typeof fee.id === 'string', 'id should be string');
|
||||
assert.equal(fee.factor, 0n, 'accrued fees should have factor of 0');
|
||||
});
|
||||
|
||||
// Validate claimable fees structure (if any exist)
|
||||
result.claimablePositionPriceImpactFees.forEach(fee => {
|
||||
assert.ok(typeof fee.factor === 'bigint', 'factor should be bigint');
|
||||
assert.ok(typeof fee.value === 'bigint', 'value should be bigint');
|
||||
assert.ok(typeof fee.valueByFactor === 'bigint', 'valueByFactor should be bigint');
|
||||
assert.ok(typeof fee.timeKey === 'number', 'timeKey should be number');
|
||||
assert.ok(typeof fee.marketAddress === 'string', 'marketAddress should be string');
|
||||
assert.ok(typeof fee.tokenAddress === 'string', 'tokenAddress should be string');
|
||||
assert.ok(typeof fee.id === 'string', 'id should be string');
|
||||
assert.ok(fee.factor > 0n, 'claimable fees should have factor > 0');
|
||||
});
|
||||
|
||||
console.log(`Found ${result.accruedPositionPriceImpactFees.length} accrued fees`);
|
||||
console.log(`Found ${result.claimablePositionPriceImpactFees.length} claimable fees`);
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle SDK client creation for rebates', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Validate SDK properties
|
||||
assert.ok(typeof sdk === 'object', 'SDK should be an object');
|
||||
assert.ok(sdk.account === testAccount, 'SDK account should match test account');
|
||||
assert.ok(typeof sdk.chainId === 'number', 'Chain ID should be a number');
|
||||
|
||||
console.log('SDK validation passed for rebates');
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should query GraphQL subgraph successfully', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getGmxPriceImpactRebatesImpl(sdk);
|
||||
|
||||
// The result should be from real GraphQL query, not mock data
|
||||
console.log('Real GraphQL query result:', {
|
||||
accruedCount: result.accruedPositionPriceImpactFees.length,
|
||||
claimableCount: result.claimablePositionPriceImpactFees.length
|
||||
});
|
||||
|
||||
// Test that the data structure is valid regardless of content
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
assert.ok('accruedPositionPriceImpactFees' in result, 'Should have accruedPositionPriceImpactFees');
|
||||
assert.ok('claimablePositionPriceImpactFees' in result, 'Should have claimablePositionPriceImpactFees');
|
||||
|
||||
// All returned fees should have valid valueByFactor calculations
|
||||
[...result.accruedPositionPriceImpactFees, ...result.claimablePositionPriceImpactFees].forEach(fee => {
|
||||
// Validate valueByFactor calculation
|
||||
const expectedValueByFactor = (fee.value * fee.factor) / (BigInt(10) ** BigInt(30));
|
||||
assert.equal(fee.valueByFactor, expectedValueByFactor, 'valueByFactor should be calculated correctly');
|
||||
|
||||
// Should not have items where factor > 0 but valueByFactor = 0 (these should be filtered out)
|
||||
if (fee.factor > 0n) {
|
||||
assert.ok(fee.valueByFactor > 0n, 'Claimable fees with factor > 0 should have valueByFactor > 0');
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle chain ID validation', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Should only work for Arbitrum (chainId 42161)
|
||||
assert.equal(sdk.chainId, 42161, 'Should be using Arbitrum chain ID');
|
||||
|
||||
console.log('Chain ID validation passed');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should validate address formatting', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getGmxPriceImpactRebatesImpl(sdk);
|
||||
|
||||
// All addresses should be lowercase and properly formatted
|
||||
[...result.accruedPositionPriceImpactFees, ...result.claimablePositionPriceImpactFees].forEach(fee => {
|
||||
assert.equal(fee.marketAddress, fee.marketAddress.toLowerCase(), 'Market address should be lowercase');
|
||||
assert.equal(fee.tokenAddress, fee.tokenAddress.toLowerCase(), 'Token address should be lowercase');
|
||||
assert.ok(fee.marketAddress.startsWith('0x'), 'Market address should start with 0x');
|
||||
assert.ok(fee.tokenAddress.startsWith('0x'), 'Token address should start with 0x');
|
||||
assert.equal(fee.marketAddress.length, 42, 'Market address should be 42 characters');
|
||||
assert.equal(fee.tokenAddress.length, 42, 'Token address should be 42 characters');
|
||||
});
|
||||
|
||||
console.log('Address formatting validation passed');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle empty results gracefully', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getGmxPriceImpactRebatesImpl(sdk);
|
||||
|
||||
// Even if arrays are empty, structure should be valid
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
assert.ok('accruedPositionPriceImpactFees' in result, 'Should have accruedPositionPriceImpactFees property');
|
||||
assert.ok('claimablePositionPriceImpactFees' in result, 'Should have claimablePositionPriceImpactFees property');
|
||||
|
||||
console.log('Empty results handling validated');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
import {test} from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
import {getClientForAddress, getGmxRebateStatsImpl} from '../../src/plugins/custom/gmx.ts'
|
||||
|
||||
test('GMX get rebate stats', async (t) => {
|
||||
await t.test('should get rebate stats for account', async () => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f'
|
||||
const sdk = await getClientForAddress(testAccount)
|
||||
|
||||
const result = await getGmxRebateStatsImpl(sdk)
|
||||
|
||||
console.log('Rebate stats result:', result)
|
||||
assert.ok(result, 'Rebate stats result should be defined')
|
||||
|
||||
// Check that the result has the expected structure
|
||||
assert.ok(typeof result.totalRebateUsd === 'number', 'totalRebateUsd should be a number')
|
||||
assert.ok(typeof result.discountUsd === 'number', 'discountUsd should be a number')
|
||||
assert.ok(typeof result.volume === 'number', 'volume should be a number')
|
||||
assert.ok(typeof result.tier === 'number', 'tier should be a number')
|
||||
assert.ok(typeof result.rebateFactor === 'number', 'rebateFactor should be a number')
|
||||
assert.ok(typeof result.discountFactor === 'number', 'discountFactor should be a number')
|
||||
|
||||
// All values should be non-negative
|
||||
assert.ok(result.totalRebateUsd >= 0, 'totalRebateUsd should be non-negative')
|
||||
assert.ok(result.discountUsd >= 0, 'discountUsd should be non-negative')
|
||||
assert.ok(result.volume >= 0, 'volume should be non-negative')
|
||||
assert.ok(result.tier >= 0, 'tier should be non-negative')
|
||||
assert.ok(result.rebateFactor >= 0, 'rebateFactor should be non-negative')
|
||||
assert.ok(result.discountFactor >= 0, 'discountFactor should be non-negative')
|
||||
})
|
||||
})
|
||||
@@ -1,32 +0,0 @@
|
||||
import {before, describe, it} from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
import {getClientForAddress, swapGmxTokensImpl} from '../../src/plugins/custom/gmx.js'
|
||||
import {Ticker} from '../../src/generated/ManagingApiTypes'
|
||||
|
||||
describe('swap tokens implementation', () => {
|
||||
let sdk: any
|
||||
|
||||
before(async () => {
|
||||
// Initialize the SDK with a test account
|
||||
const testAccount = '0xbba4eaa534cbd0ecaed5e2fd6036aec2e7ee309f'
|
||||
sdk = await getClientForAddress(testAccount)
|
||||
})
|
||||
|
||||
it('should swap USDC to ETH successfully', async () => {
|
||||
try {
|
||||
const result = await swapGmxTokensImpl(
|
||||
sdk,
|
||||
Ticker.GMX, // fromTicker
|
||||
Ticker.USDC, // toTicker
|
||||
2.06 // amount
|
||||
)
|
||||
|
||||
assert.strictEqual(typeof result, 'string')
|
||||
assert.strictEqual(result, 'swap_order_created')
|
||||
} catch (error) {
|
||||
// Test that the error is related to actual execution rather than parameter validation
|
||||
assert.ok(error instanceof Error)
|
||||
console.log('Expected error during test execution:', error.message)
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user