-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e6de69
commit 16e1379
Showing
3 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { PendingTransactionMessage } from "../../src/messages/pending-transaction-message"; | ||
import { ExchangeHistory } from "../../src/interfaces/exchange-history-store"; | ||
import { MultiPlanetary } from "../../src/multi-planetary"; | ||
import { TransactionStatus } from "../../src/types/transaction-status"; | ||
|
||
describe("PendingTransactionMessage", () => { | ||
const mockMultiPlanetary = { | ||
getRequestPlanetName: jest.fn().mockReturnValue("Odin"), | ||
} as unknown as MultiPlanetary; | ||
|
||
it("should render pending transactions correctly for BSCereum", () => { | ||
const transactions: ExchangeHistory[] = [ | ||
{ | ||
network: "BSCereum", | ||
tx_id: "TX-123", | ||
sender: "0xSenderAddress", | ||
recipient: "0xRecipientAddress", | ||
timestamp: new Date().toISOString(), | ||
amount: 100, | ||
status: TransactionStatus.PENDING, | ||
}, | ||
]; | ||
|
||
const message = new PendingTransactionMessage( | ||
transactions, | ||
mockMultiPlanetary | ||
); | ||
const result = message.render() as { | ||
text: string; | ||
attachments: { | ||
author_name: string; | ||
fields: { title: string; value: string }[]; | ||
}[]; | ||
}; | ||
|
||
expect(result.text).toBe("1 Pending Transactions Found"); | ||
expect(result.attachments).toHaveLength(1); | ||
expect(result.attachments[0].author_name).toBe( | ||
"[BSC] wNCG → NCG pending event" | ||
); | ||
expect(result.attachments[0].fields[0].title).toBe("BSC transaction"); | ||
expect(result.attachments[0].fields[1].title).toBe("Planet Name"); | ||
expect(result.attachments[0].fields[1].value).toBe("Odin"); | ||
expect(result.attachments[0].fields[2].title).toBe("Sender(BSC)"); | ||
expect(result.attachments[0].fields[2].value).toBe("0xSenderAddress"); | ||
expect(result.attachments[0].fields[3].title).toBe("Recipient(9c)"); | ||
expect(result.attachments[0].fields[3].value).toBe("0xRecipientAddress"); | ||
expect(result.attachments[0].fields[4].title).toBe("Amount"); | ||
expect(result.attachments[0].fields[4].value).toBe("100"); | ||
expect(result.attachments[0].fields[5].title).toBe("Timestamp"); | ||
expect(result.attachments[0].fields[5].value).toBe( | ||
transactions[0].timestamp | ||
); | ||
}); | ||
|
||
it("should render no pending transactions message", () => { | ||
const message = new PendingTransactionMessage([], mockMultiPlanetary); | ||
const result = message.render() as { | ||
text: string; | ||
attachments: { | ||
author_name: string; | ||
fields: { title: string; value: string }[]; | ||
}[]; | ||
}; | ||
|
||
expect(result.text).toBe("No pending transactions"); | ||
expect(result.attachments).toHaveLength(1); | ||
expect(result.attachments[0].author_name).toBe("BSC Bridge Restarted"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { PendingTransactionHandler } from "../src/pending-transactions"; | ||
import { IExchangeHistoryStore } from "../src/interfaces/exchange-history-store"; | ||
import { INCGTransfer } from "../src/interfaces/ncg-transfer"; | ||
import { MultiPlanetary } from "../src/multi-planetary"; | ||
import { ISlackMessageSender } from "../src/interfaces/slack-message-sender"; | ||
import { PendingTransactionMessage } from "../src/messages/pending-transaction-message"; | ||
import { TransactionStatus } from "../src/types/transaction-status"; | ||
|
||
describe("PendingTransactionHandler", () => { | ||
let exchangeHistoryStore: jest.Mocked<IExchangeHistoryStore>; | ||
let ncgTransfer: jest.Mocked<INCGTransfer>; | ||
let multiPlanetary: jest.Mocked<MultiPlanetary>; | ||
let slackMessageSender: jest.Mocked<ISlackMessageSender>; | ||
let handler: PendingTransactionHandler; | ||
|
||
beforeEach(() => { | ||
exchangeHistoryStore = { | ||
getPendingTransactions: jest.fn(), | ||
updateStatus: jest.fn(), | ||
} as unknown as jest.Mocked<IExchangeHistoryStore>; | ||
|
||
ncgTransfer = {} as jest.Mocked<INCGTransfer>; | ||
multiPlanetary = {} as jest.Mocked<MultiPlanetary>; | ||
slackMessageSender = { | ||
sendMessage: jest.fn(), | ||
} as unknown as jest.Mocked<ISlackMessageSender>; | ||
|
||
handler = new PendingTransactionHandler( | ||
exchangeHistoryStore, | ||
ncgTransfer, | ||
multiPlanetary, | ||
slackMessageSender | ||
); | ||
}); | ||
|
||
it("should send a message for pending transactions and update their status", async () => { | ||
const pendingTransactions = [ | ||
{ | ||
tx_id: "TX-1", | ||
network: "ethereum", | ||
amount: 100, | ||
sender: "sender1", | ||
recipient: "recipient1", | ||
timestamp: new Date().toISOString(), | ||
status: TransactionStatus.PENDING, | ||
}, | ||
{ | ||
tx_id: "TX-2", | ||
network: "nineChronicles", | ||
amount: 200, | ||
sender: "sender2", | ||
recipient: "recipient2", | ||
timestamp: new Date().toISOString(), | ||
status: TransactionStatus.PENDING, | ||
}, | ||
]; | ||
|
||
exchangeHistoryStore.getPendingTransactions.mockResolvedValue( | ||
pendingTransactions | ||
); | ||
|
||
await handler.messagePendingTransactions(); | ||
|
||
expect(slackMessageSender.sendMessage).toHaveBeenCalledWith( | ||
expect.any(PendingTransactionMessage) | ||
); | ||
expect(exchangeHistoryStore.updateStatus).toHaveBeenCalledTimes(2); | ||
expect(exchangeHistoryStore.updateStatus).toHaveBeenCalledWith( | ||
"TX-1", | ||
TransactionStatus.FAILED | ||
); | ||
expect(exchangeHistoryStore.updateStatus).toHaveBeenCalledWith( | ||
"TX-2", | ||
TransactionStatus.FAILED | ||
); | ||
}); | ||
|
||
it("should not send a message if there are no pending transactions", async () => { | ||
exchangeHistoryStore.getPendingTransactions.mockResolvedValue([]); | ||
|
||
await handler.messagePendingTransactions(); | ||
|
||
expect(slackMessageSender.sendMessage).not.toHaveBeenCalled(); | ||
expect(exchangeHistoryStore.updateStatus).not.toHaveBeenCalled(); | ||
}); | ||
}); |