mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-05-21 07:50:29 -04:00
test chat messages by configuration
This commit is contained in:
parent
897d43dfba
commit
7046924f40
1 changed files with 61 additions and 55 deletions
|
@ -143,6 +143,7 @@ const defaultTradeConfig: Partial<TradeContext> = {
|
||||||
disputeSummary: "Seller is winner",
|
disputeSummary: "Seller is winner",
|
||||||
walletSyncPeriodMs: 5000,
|
walletSyncPeriodMs: 5000,
|
||||||
maxTimePeerNoticeMs: 5000,
|
maxTimePeerNoticeMs: 5000,
|
||||||
|
testChatMessages: true,
|
||||||
stopOnFailure: true,
|
stopOnFailure: true,
|
||||||
testPayoutConfirmed: true,
|
testPayoutConfirmed: true,
|
||||||
testPayoutUnlocked: false,
|
testPayoutUnlocked: false,
|
||||||
|
@ -218,6 +219,7 @@ class TradeContext {
|
||||||
sellerOpenedDispute?: boolean;
|
sellerOpenedDispute?: boolean;
|
||||||
walletSyncPeriodMs: number;
|
walletSyncPeriodMs: number;
|
||||||
maxTimePeerNoticeMs: number;
|
maxTimePeerNoticeMs: number;
|
||||||
|
testChatMessages: boolean;
|
||||||
stopOnFailure?: boolean;
|
stopOnFailure?: boolean;
|
||||||
buyerAppName?: string;
|
buyerAppName?: string;
|
||||||
sellerAppName?: string;
|
sellerAppName?: string;
|
||||||
|
@ -2924,65 +2926,69 @@ async function testOpenDispute(ctxP: Partial<TradeContext>) {
|
||||||
await ctx.getDisputePeer()!.havenod!.addNotificationListener(notification => { HavenoUtils.log(3, "Dispute peer received notification " + notification.getType() + " " + (notification.getChatMessage() ? notification.getChatMessage()?.getMessage() : "")); disputePeerNotifications.push(notification); });
|
await ctx.getDisputePeer()!.havenod!.addNotificationListener(notification => { HavenoUtils.log(3, "Dispute peer received notification " + notification.getType() + " " + (notification.getChatMessage() ? notification.getChatMessage()?.getMessage() : "")); disputePeerNotifications.push(notification); });
|
||||||
await arbitrator.addNotificationListener(notification => { HavenoUtils.log(3, "Arbitrator received notification " + notification.getType() + " " + (notification.getChatMessage() ? notification.getChatMessage()?.getMessage() : "")); arbitratorNotifications.push(notification); });
|
await arbitrator.addNotificationListener(notification => { HavenoUtils.log(3, "Arbitrator received notification " + notification.getType() + " " + (notification.getChatMessage() ? notification.getChatMessage()?.getMessage() : "")); arbitratorNotifications.push(notification); });
|
||||||
|
|
||||||
// arbitrator sends chat messages to traders
|
// test chat messages
|
||||||
HavenoUtils.log(1, "Arbitrator sending chat messages to traders. tradeId=" + ctx.offerId + ", disputeId=" + openerDispute.getId());
|
if (ctx.testChatMessages) {
|
||||||
await ctx.arbitrator.havenod!.sendDisputeChatMessage(arbDisputeOpener!.getId(), "Arbitrator chat message to dispute opener", []);
|
|
||||||
await ctx.arbitrator.havenod!.sendDisputeChatMessage(arbDisputePeer!.getId(), "Arbitrator chat message to dispute peer", []);
|
|
||||||
|
|
||||||
// traders reply to arbitrator chat messages
|
// arbitrator sends chat messages to traders
|
||||||
await wait(ctx.maxTimePeerNoticeMs); // wait for arbitrator's message to arrive
|
HavenoUtils.log(1, "Arbitrator sending chat messages to traders. tradeId=" + ctx.offerId + ", disputeId=" + openerDispute.getId());
|
||||||
const attachment = new Attachment();
|
await ctx.arbitrator.havenod!.sendDisputeChatMessage(arbDisputeOpener!.getId(), "Arbitrator chat message to dispute opener", []);
|
||||||
const bytes = new Uint8Array(Buffer.from("Proof dispute opener was scammed", "utf8"));
|
await ctx.arbitrator.havenod!.sendDisputeChatMessage(arbDisputePeer!.getId(), "Arbitrator chat message to dispute peer", []);
|
||||||
attachment.setBytes(bytes);
|
|
||||||
attachment.setFileName("proof.txt");
|
|
||||||
const attachment2 = new Attachment();
|
|
||||||
const bytes2 = new Uint8Array(Buffer.from("picture bytes", "utf8"));
|
|
||||||
attachment2.setBytes(bytes2);
|
|
||||||
attachment2.setFileName("proof.png");
|
|
||||||
HavenoUtils.log(2, "Dispute opener sending chat message to arbitrator. tradeId=" + ctx.offerId + ", disputeId=" + openerDispute.getId());
|
|
||||||
await ctx.getDisputeOpener()!.havenod!.sendDisputeChatMessage(openerDispute.getId(), "Dispute opener chat message", [attachment, attachment2]);
|
|
||||||
await wait(ctx.maxTimePeerNoticeMs); // wait for user2's message to arrive
|
|
||||||
HavenoUtils.log(2, "Dispute peer sending chat message to arbitrator. tradeId=" + ctx.offerId + ", disputeId=" + peerDispute.getId());
|
|
||||||
await ctx.getDisputePeer()!.havenod!.sendDisputeChatMessage(peerDispute.getId(), "Dispute peer chat message", []);
|
|
||||||
|
|
||||||
// test trader chat messages
|
// traders reply to arbitrator chat messages
|
||||||
await wait(ctx.maxTimePeerNoticeMs);
|
await wait(ctx.maxTimePeerNoticeMs); // wait for arbitrator's message to arrive
|
||||||
let dispute = await ctx.getDisputeOpener()!.havenod!.getDispute(ctx.offerId!);
|
const attachment = new Attachment();
|
||||||
let messages = dispute.getChatMessageList();
|
const bytes = new Uint8Array(Buffer.from("Proof dispute opener was scammed", "utf8"));
|
||||||
expect(messages.length).toBeGreaterThanOrEqual(3); // last messages are chat, first messages are system message and possibly DisputeOpenedMessage acks
|
attachment.setBytes(bytes);
|
||||||
expect(messages[messages.length - 2].getMessage()).toEqual("Arbitrator chat message to dispute opener");
|
attachment.setFileName("proof.txt");
|
||||||
expect(messages[messages.length - 1].getMessage()).toEqual("Dispute opener chat message");
|
const attachment2 = new Attachment();
|
||||||
let attachments = messages[messages.length - 1].getAttachmentsList();
|
const bytes2 = new Uint8Array(Buffer.from("picture bytes", "utf8"));
|
||||||
expect(attachments.length).toEqual(2);
|
attachment2.setBytes(bytes2);
|
||||||
expect(attachments[0].getFileName()).toEqual("proof.txt");
|
attachment2.setFileName("proof.png");
|
||||||
expect(attachments[0].getBytes()).toEqual(bytes);
|
HavenoUtils.log(2, "Dispute opener sending chat message to arbitrator. tradeId=" + ctx.offerId + ", disputeId=" + openerDispute.getId());
|
||||||
expect(attachments[1].getFileName()).toEqual("proof.png");
|
await ctx.getDisputeOpener()!.havenod!.sendDisputeChatMessage(openerDispute.getId(), "Dispute opener chat message", [attachment, attachment2]);
|
||||||
expect(attachments[1].getBytes()).toEqual(bytes2);
|
await wait(ctx.maxTimePeerNoticeMs); // wait for user2's message to arrive
|
||||||
dispute = await ctx.getDisputePeer()!.havenod!.getDispute(ctx.offerId!);
|
HavenoUtils.log(2, "Dispute peer sending chat message to arbitrator. tradeId=" + ctx.offerId + ", disputeId=" + peerDispute.getId());
|
||||||
messages = dispute.getChatMessageList();
|
await ctx.getDisputePeer()!.havenod!.sendDisputeChatMessage(peerDispute.getId(), "Dispute peer chat message", []);
|
||||||
expect(messages.length).toBeGreaterThanOrEqual(3);
|
|
||||||
expect(messages[messages.length - 2].getMessage()).toEqual("Arbitrator chat message to dispute peer");
|
|
||||||
expect(messages[messages.length - 1].getMessage()).toEqual("Dispute peer chat message");
|
|
||||||
|
|
||||||
// test notifications of chat messages
|
// test trader chat messages
|
||||||
let chatNotifications = getNotifications(disputeOpenerNotifications, NotificationMessage.NotificationType.CHAT_MESSAGE, ctx.offerId);
|
await wait(ctx.maxTimePeerNoticeMs);
|
||||||
expect(chatNotifications.length).toBe(1);
|
let dispute = await ctx.getDisputeOpener()!.havenod!.getDispute(ctx.offerId!);
|
||||||
expect(chatNotifications[0].getChatMessage()?.getMessage()).toEqual("Arbitrator chat message to dispute opener");
|
let messages = dispute.getChatMessageList();
|
||||||
chatNotifications = getNotifications(disputePeerNotifications, NotificationMessage.NotificationType.CHAT_MESSAGE, ctx.offerId);
|
expect(messages.length).toBeGreaterThanOrEqual(3); // last messages are chat, first messages are system message and possibly DisputeOpenedMessage acks
|
||||||
expect(chatNotifications.length).toBe(1);
|
expect(messages[messages.length - 2].getMessage()).toEqual("Arbitrator chat message to dispute opener");
|
||||||
expect(chatNotifications[0].getChatMessage()?.getMessage()).toEqual("Arbitrator chat message to dispute peer");
|
expect(messages[messages.length - 1].getMessage()).toEqual("Dispute opener chat message");
|
||||||
|
let attachments = messages[messages.length - 1].getAttachmentsList();
|
||||||
|
expect(attachments.length).toEqual(2);
|
||||||
|
expect(attachments[0].getFileName()).toEqual("proof.txt");
|
||||||
|
expect(attachments[0].getBytes()).toEqual(bytes);
|
||||||
|
expect(attachments[1].getFileName()).toEqual("proof.png");
|
||||||
|
expect(attachments[1].getBytes()).toEqual(bytes2);
|
||||||
|
dispute = await ctx.getDisputePeer()!.havenod!.getDispute(ctx.offerId!);
|
||||||
|
messages = dispute.getChatMessageList();
|
||||||
|
expect(messages.length).toBeGreaterThanOrEqual(3);
|
||||||
|
expect(messages[messages.length - 2].getMessage()).toEqual("Arbitrator chat message to dispute peer");
|
||||||
|
expect(messages[messages.length - 1].getMessage()).toEqual("Dispute peer chat message");
|
||||||
|
|
||||||
// arbitrator has 2 chat messages, one with attachments
|
// test notifications of chat messages
|
||||||
chatNotifications = getNotifications(arbitratorNotifications, NotificationMessage.NotificationType.CHAT_MESSAGE, ctx.offerId);
|
let chatNotifications = getNotifications(disputeOpenerNotifications, NotificationMessage.NotificationType.CHAT_MESSAGE, ctx.offerId);
|
||||||
expect(chatNotifications.length).toBe(2);
|
expect(chatNotifications.length).toBe(1);
|
||||||
expect(chatNotifications[0].getChatMessage()?.getMessage()).toEqual("Dispute opener chat message");
|
expect(chatNotifications[0].getChatMessage()?.getMessage()).toEqual("Arbitrator chat message to dispute opener");
|
||||||
assert(chatNotifications[0].getChatMessage()?.getAttachmentsList());
|
chatNotifications = getNotifications(disputePeerNotifications, NotificationMessage.NotificationType.CHAT_MESSAGE, ctx.offerId);
|
||||||
attachments = chatNotifications[0].getChatMessage()?.getAttachmentsList()!;
|
expect(chatNotifications.length).toBe(1);
|
||||||
expect(attachments[0].getFileName()).toEqual("proof.txt");
|
expect(chatNotifications[0].getChatMessage()?.getMessage()).toEqual("Arbitrator chat message to dispute peer");
|
||||||
expect(attachments[0].getBytes()).toEqual(bytes);
|
|
||||||
expect(attachments[1].getFileName()).toEqual("proof.png");
|
// arbitrator has 2 chat messages, one with attachments
|
||||||
expect(attachments[1].getBytes()).toEqual(bytes2);
|
chatNotifications = getNotifications(arbitratorNotifications, NotificationMessage.NotificationType.CHAT_MESSAGE, ctx.offerId);
|
||||||
expect(chatNotifications[1].getChatMessage()?.getMessage()).toEqual("Dispute peer chat message");
|
expect(chatNotifications.length).toBe(2);
|
||||||
|
expect(chatNotifications[0].getChatMessage()?.getMessage()).toEqual("Dispute opener chat message");
|
||||||
|
assert(chatNotifications[0].getChatMessage()?.getAttachmentsList());
|
||||||
|
attachments = chatNotifications[0].getChatMessage()?.getAttachmentsList()!;
|
||||||
|
expect(attachments[0].getFileName()).toEqual("proof.txt");
|
||||||
|
expect(attachments[0].getBytes()).toEqual(bytes);
|
||||||
|
expect(attachments[1].getFileName()).toEqual("proof.png");
|
||||||
|
expect(attachments[1].getBytes()).toEqual(bytes2);
|
||||||
|
expect(chatNotifications[1].getChatMessage()?.getMessage()).toEqual("Dispute peer chat message");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resolveDispute(ctxP: Partial<TradeContext>) {
|
async function resolveDispute(ctxP: Partial<TradeContext>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue