Start claiming rebate

This commit is contained in:
2025-06-03 02:54:48 +07:00
parent 2550f917e3
commit f41af96406
4 changed files with 312 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import { test } from 'node:test'
import assert from 'node:assert'
import { getClientForAddress, getGmxRebateStatsImpl } from '../../src/plugins/custom/gmx'
test('GMX get rebate stats', async (t) => {
await t.test('should get rebate stats for account', async () => {
const testAccount = '0x932167388dD9aad41149b3cA23eBD489E2E2DD78'
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')
})
await t.test('should handle account with no referral info', async () => {
// Test with a different account that might not have referral data
const testAccount = '0x0000000000000000000000000000000000000000'
const sdk = await getClientForAddress(testAccount)
const result = await getGmxRebateStatsImpl(sdk)
console.log('Rebate stats result for empty account:', result)
assert.ok(result, 'Rebate stats result should be defined even for empty account')
// Should return default values for account with no referral info
assert.strictEqual(result.totalRebateUsd, 0, 'totalRebateUsd should be 0 for empty account')
assert.strictEqual(result.discountUsd, 0, 'discountUsd should be 0 for empty account')
assert.strictEqual(result.volume, 0, 'volume should be 0 for empty account')
assert.strictEqual(result.tier, 0, 'tier should be 0 for empty account')
assert.strictEqual(result.rebateFactor, 0, 'rebateFactor should be 0 for empty account')
assert.strictEqual(result.discountFactor, 0, 'discountFactor should be 0 for empty account')
})
await t.test('should handle errors gracefully', async () => {
// Test with an invalid account address to trigger error handling
try {
const sdk = await getClientForAddress('invalid-address')
await getGmxRebateStatsImpl(sdk)
assert.fail('Should have thrown an error for invalid address')
} catch (error) {
assert.ok(error instanceof Error, 'Should throw an Error instance')
console.log('Expected error for invalid address:', error.message)
}
})
})

View File

@@ -0,0 +1,62 @@
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')
})
await t.test('should handle account with no referral info', async () => {
// Test with a different account that might not have referral data
const testAccount = '0x0000000000000000000000000000000000000000'
const sdk = await getClientForAddress(testAccount)
const result = await getGmxRebateStatsImpl(sdk)
console.log('Rebate stats result for empty account:', result)
assert.ok(result, 'Rebate stats result should be defined even for empty account')
// Should return default values for account with no referral info
assert.strictEqual(result.totalRebateUsd, 0, 'totalRebateUsd should be 0 for empty account')
assert.strictEqual(result.discountUsd, 0, 'discountUsd should be 0 for empty account')
assert.strictEqual(result.volume, 0, 'volume should be 0 for empty account')
assert.strictEqual(result.tier, 0, 'tier should be 0 for empty account')
assert.strictEqual(result.rebateFactor, 0, 'rebateFactor should be 0 for empty account')
assert.strictEqual(result.discountFactor, 0, 'discountFactor should be 0 for empty account')
})
await t.test('should handle errors gracefully', async () => {
// Test with an invalid account address to trigger error handling
try {
const sdk = await getClientForAddress('invalid-address')
await getGmxRebateStatsImpl(sdk)
assert.fail('Should have thrown an error for invalid address')
} catch (error) {
assert.ok(error instanceof Error, 'Should throw an Error instance')
console.log('Expected error for invalid address:', error.message)
}
})
})