fix: harden drift verifier and validation flow
This commit is contained in:
@@ -13,7 +13,9 @@ import { getDriftStateVerifier } from '../../../lib/monitoring/drift-state-verif
|
||||
// Mock dependencies
|
||||
jest.mock('../../../lib/drift/client')
|
||||
jest.mock('../../../lib/drift/orders')
|
||||
jest.mock('../../../lib/database/trades')
|
||||
jest.mock('../../../lib/database/trades', () => ({
|
||||
getPrismaClient: jest.fn(),
|
||||
}))
|
||||
jest.mock('../../../lib/notifications/telegram')
|
||||
|
||||
describe('Bug #80: Retry Loop Cooldown', () => {
|
||||
@@ -38,18 +40,19 @@ describe('Bug #80: Retry Loop Cooldown', () => {
|
||||
|
||||
// Mock closePosition
|
||||
const ordersModule = require('../../../lib/drift/orders')
|
||||
mockClosePosition = jest.fn().mockResolvedValue({
|
||||
mockClosePosition = ordersModule.closePosition
|
||||
mockClosePosition.mockResolvedValue({
|
||||
success: true,
|
||||
transactionSignature: 'CLOSE_TX',
|
||||
realizedPnL: -10.50
|
||||
})
|
||||
ordersModule.closePosition = mockClosePosition
|
||||
|
||||
// Mock Prisma
|
||||
const { getPrismaClient } = require('../../../lib/database/trades')
|
||||
mockPrisma = {
|
||||
trade: {
|
||||
findUnique: jest.fn(),
|
||||
findFirst: jest.fn().mockResolvedValue(null),
|
||||
update: jest.fn()
|
||||
}
|
||||
}
|
||||
@@ -214,6 +217,9 @@ describe('Bug #80: Retry Loop Cooldown', () => {
|
||||
|
||||
// But database has recent attempt
|
||||
const twoMinutesAgo = new Date(Date.now() - (2 * 60 * 1000))
|
||||
mockPrisma.trade.findFirst.mockResolvedValue({
|
||||
configSnapshot: { retryCloseTime: twoMinutesAgo.toISOString() }
|
||||
})
|
||||
mockPrisma.trade.findUnique.mockResolvedValue({
|
||||
id: 'trade1',
|
||||
configSnapshot: {
|
||||
@@ -245,6 +251,9 @@ describe('Bug #80: Retry Loop Cooldown', () => {
|
||||
retryCloseTime: oneMinuteAgo.toISOString()
|
||||
}
|
||||
})
|
||||
mockPrisma.trade.findFirst.mockResolvedValue({
|
||||
configSnapshot: { retryCloseTime: oneMinuteAgo.toISOString() }
|
||||
})
|
||||
|
||||
await (verifier as any).retryClose(mismatch)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user