mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-01-23 21:21:20 -05:00
test completing trade from scheduled offer with and without dispute
This commit is contained in:
parent
9c075ba957
commit
0862caae47
@ -1185,6 +1185,10 @@ test("Can schedule offers with locked funds (CI)", async () => {
|
|||||||
let err: any;
|
let err: any;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
// configure test
|
||||||
|
const completeTrade = true;
|
||||||
|
const resolveDispute = Math.random() < 0.5;
|
||||||
|
|
||||||
// start user3
|
// start user3
|
||||||
user3 = await initHaveno();
|
user3 = await initHaveno();
|
||||||
const user3Wallet = await monerojs.connectToWalletRpc("http://127.0.0.1:" + user3.getWalletRpcPort(), TestConfig.defaultHavenod.walletUsername, TestConfig.defaultHavenod.accountPassword);
|
const user3Wallet = await monerojs.connectToWalletRpc("http://127.0.0.1:" + user3.getWalletRpcPort(), TestConfig.defaultHavenod.walletUsername, TestConfig.defaultHavenod.accountPassword);
|
||||||
@ -1196,7 +1200,8 @@ test("Can schedule offers with locked funds (CI)", async () => {
|
|||||||
// schedule offer
|
// schedule offer
|
||||||
const assetCode = "BCH";
|
const assetCode = "BCH";
|
||||||
const direction = "BUY";
|
const direction = "BUY";
|
||||||
let offer: OfferInfo = await makeOffer({maker: user3, assetCode: assetCode, direction: direction, awaitFundsToMakeOffer: false});
|
const ctx = Object.assign({}, TestConfig.trade, {maker: user3, assetCode: assetCode, direction: direction, awaitFundsToMakeOffer: false});
|
||||||
|
let offer: OfferInfo = await makeOffer(ctx);
|
||||||
assert.equal(offer.getState(), "SCHEDULED");
|
assert.equal(offer.getState(), "SCHEDULED");
|
||||||
|
|
||||||
// has offer
|
// has offer
|
||||||
@ -1249,6 +1254,12 @@ test("Can schedule offers with locked funds (CI)", async () => {
|
|||||||
await wait(TestConfig.trade.maxTimePeerNoticeMs);
|
await wait(TestConfig.trade.maxTimePeerNoticeMs);
|
||||||
if (!getOffer(await user1.getOffers(assetCode, direction), offer.getId())) throw new Error("Offer " + offer.getId() + " was not found in peer's offers after posted");
|
if (!getOffer(await user1.getOffers(assetCode, direction), offer.getId())) throw new Error("Offer " + offer.getId() + " was not found in peer's offers after posted");
|
||||||
|
|
||||||
|
// complete trade or cancel offer depending on configuration
|
||||||
|
if (completeTrade) {
|
||||||
|
HavenoUtils.log(1, "Completing trade from scheduled offer, opening and resolving dispute: " + resolveDispute);
|
||||||
|
await executeTrade(Object.assign(ctx, {buyerDisputeContext: resolveDispute ? DisputeContext.OPEN_AFTER_DEPOSITS_UNLOCK : DisputeContext.NONE}));
|
||||||
|
} else {
|
||||||
|
|
||||||
// cancel offer
|
// cancel offer
|
||||||
await user3.removeOffer(offer.getId());
|
await user3.removeOffer(offer.getId());
|
||||||
|
|
||||||
@ -1259,6 +1270,7 @@ test("Can schedule offers with locked funds (CI)", async () => {
|
|||||||
expect(BigInt((await user3.getBalances()).getAvailableBalance())).toEqual(outputAmt * BigInt(2));
|
expect(BigInt((await user3.getBalances()).getAvailableBalance())).toEqual(outputAmt * BigInt(2));
|
||||||
expect(BigInt((await user3.getBalances()).getPendingBalance())).toEqual(BigInt(0));
|
expect(BigInt((await user3.getBalances()).getPendingBalance())).toEqual(BigInt(0));
|
||||||
expect(BigInt((await user3.getBalances()).getReservedOfferBalance())).toEqual(BigInt(0));
|
expect(BigInt((await user3.getBalances()).getReservedOfferBalance())).toEqual(BigInt(0));
|
||||||
|
}
|
||||||
} catch (err2) {
|
} catch (err2) {
|
||||||
err = err2;
|
err = err2;
|
||||||
}
|
}
|
||||||
|
@ -1647,9 +1647,13 @@ export default class HavenoClient {
|
|||||||
firstRequest = false;
|
firstRequest = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
await this._sendNotification(new NotificationMessage()
|
await this._sendNotification(new NotificationMessage()
|
||||||
.setType(NotificationMessage.NotificationType.KEEP_ALIVE)
|
.setType(NotificationMessage.NotificationType.KEEP_ALIVE)
|
||||||
.setTimestamp(Date.now()));
|
.setTimestamp(Date.now()));
|
||||||
|
} catch (err: any) {
|
||||||
|
HavenoUtils.log(0, "Error sending keep alive request to Haveno daemon: " + err.message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this._keepAliveLooper.start(this._keepAlivePeriodMs);
|
this._keepAliveLooper.start(this._keepAlivePeriodMs);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user