mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-01-12 07:49:52 -05:00
rename scheduled state to pending (#300)
This commit is contained in:
parent
7192b899f4
commit
8a81a993fe
@ -1497,11 +1497,11 @@ test("Can schedule offers with locked funds (CI)", async () => {
|
|||||||
const direction = OfferDirection.BUY;
|
const direction = OfferDirection.BUY;
|
||||||
const ctx = new TradeContext({maker: {havenod: user3}, assetCode: assetCode, direction: direction, awaitFundsToMakeOffer: false, reserveExactAmount: true});
|
const ctx = new TradeContext({maker: {havenod: user3}, assetCode: assetCode, direction: direction, awaitFundsToMakeOffer: false, reserveExactAmount: true});
|
||||||
let offer: OfferInfo = await makeOffer(ctx);
|
let offer: OfferInfo = await makeOffer(ctx);
|
||||||
assert.equal(offer.getState(), "SCHEDULED");
|
assert.equal(offer.getState(), "PENDING");
|
||||||
|
|
||||||
// has offer
|
// has offer
|
||||||
offer = await user3.getMyOffer(offer.getId());
|
offer = await user3.getMyOffer(offer.getId());
|
||||||
assert.equal(offer.getState(), "SCHEDULED");
|
assert.equal(offer.getState(), "PENDING");
|
||||||
|
|
||||||
// balances unchanged
|
// balances unchanged
|
||||||
expect(BigInt((await user3.getBalances()).getPendingBalance())).toEqual(outputAmt * 2n);
|
expect(BigInt((await user3.getBalances()).getPendingBalance())).toEqual(outputAmt * 2n);
|
||||||
@ -1521,7 +1521,7 @@ test("Can schedule offers with locked funds (CI)", async () => {
|
|||||||
|
|
||||||
// schedule offer
|
// schedule offer
|
||||||
offer = await makeOffer({maker: {havenod: user3}, assetCode: assetCode, direction: direction, awaitFundsToMakeOffer: false, reserveExactAmount: true});
|
offer = await makeOffer({maker: {havenod: user3}, assetCode: assetCode, direction: direction, awaitFundsToMakeOffer: false, reserveExactAmount: true});
|
||||||
assert.equal(offer.getState(), "SCHEDULED");
|
assert.equal(offer.getState(), "PENDING");
|
||||||
|
|
||||||
// peer does not see offer because it's scheduled
|
// peer does not see offer because it's scheduled
|
||||||
await wait(TestConfig.trade.maxTimePeerNoticeMs);
|
await wait(TestConfig.trade.maxTimePeerNoticeMs);
|
||||||
@ -1541,7 +1541,7 @@ test("Can schedule offers with locked funds (CI)", async () => {
|
|||||||
// awaiting split output
|
// awaiting split output
|
||||||
await waitForAvailableBalance(outputAmt, user3);
|
await waitForAvailableBalance(outputAmt, user3);
|
||||||
offer = await user3.getMyOffer(offer.getId());
|
offer = await user3.getMyOffer(offer.getId());
|
||||||
assert.equal(offer.getState(), "SCHEDULED");
|
assert.equal(offer.getState(), "PENDING");
|
||||||
|
|
||||||
// stop user3
|
// stop user3
|
||||||
user3Config = {appName: user3.getAppName()};
|
user3Config = {appName: user3.getAppName()};
|
||||||
@ -1750,6 +1750,11 @@ test("Can go offline while completing a trade (CI, sanity check)", async () => {
|
|||||||
HavenoUtils.log(1, "Starting trader processes");
|
HavenoUtils.log(1, "Starting trader processes");
|
||||||
traders = await initHavenos(2);
|
traders = await initHavenos(2);
|
||||||
|
|
||||||
|
// fund traders
|
||||||
|
HavenoUtils.log(1, "Funding traders");
|
||||||
|
const tradeAmount = 250000000000n;
|
||||||
|
await waitForAvailableBalance(tradeAmount * 2n, ...traders);
|
||||||
|
|
||||||
// create trade config
|
// create trade config
|
||||||
ctx.maker.havenod = traders[0];
|
ctx.maker.havenod = traders[0];
|
||||||
ctx.taker.havenod = traders[1];
|
ctx.taker.havenod = traders[1];
|
||||||
@ -1757,11 +1762,6 @@ test("Can go offline while completing a trade (CI, sanity check)", async () => {
|
|||||||
ctx.sellerOfflineAfterTake = true;
|
ctx.sellerOfflineAfterTake = true;
|
||||||
ctx.buyerOfflineAfterPaymentSent = true;
|
ctx.buyerOfflineAfterPaymentSent = true;
|
||||||
|
|
||||||
// fund traders
|
|
||||||
HavenoUtils.log(1, "Funding traders");
|
|
||||||
const tradeAmount = 250000000000n;
|
|
||||||
await waitForAvailableBalance(tradeAmount * 2n, ...traders);
|
|
||||||
|
|
||||||
// execute trade
|
// execute trade
|
||||||
await executeTrade(ctx);
|
await executeTrade(ctx);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -2353,7 +2353,7 @@ async function executeTrade(ctxP: Partial<TradeContext>): Promise<string> {
|
|||||||
if (ctx.isStopped) return ctx.offerId!;
|
if (ctx.isStopped) return ctx.offerId!;
|
||||||
if (makingOffer) {
|
if (makingOffer) {
|
||||||
ctx.offer = await makeOffer(ctx);
|
ctx.offer = await makeOffer(ctx);
|
||||||
expect(ctx.offer.getState()).toEqual(ctx.reserveExactAmount ? "SCHEDULED" : "AVAILABLE");
|
expect(ctx.offer.getState()).toEqual(ctx.reserveExactAmount ? "PENDING" : "AVAILABLE");
|
||||||
ctx.offerId = ctx.offer.getId();
|
ctx.offerId = ctx.offer.getId();
|
||||||
await wait(ctx.maxTimePeerNoticeMs);
|
await wait(ctx.maxTimePeerNoticeMs);
|
||||||
} else {
|
} else {
|
||||||
@ -2757,7 +2757,7 @@ async function makeOffer(ctxP?: Partial<TradeContext>): Promise<OfferInfo> {
|
|||||||
|
|
||||||
// unlocked balance has decreased
|
// unlocked balance has decreased
|
||||||
let unlockedBalanceAfter = BigInt((await ctx.maker.havenod!.getBalances()).getAvailableBalance());
|
let unlockedBalanceAfter = BigInt((await ctx.maker.havenod!.getBalances()).getAvailableBalance());
|
||||||
if (offer.getState() === "SCHEDULED") {
|
if (offer.getState() === "PENDING") {
|
||||||
if (!ctx.reserveExactAmount && unlockedBalanceAfter !== unlockedBalanceBefore) throw new Error("Unlocked balance should not change for scheduled offer " + offer.getId());
|
if (!ctx.reserveExactAmount && unlockedBalanceAfter !== unlockedBalanceBefore) throw new Error("Unlocked balance should not change for scheduled offer " + offer.getId());
|
||||||
} else if (offer.getState() === "AVAILABLE") {
|
} else if (offer.getState() === "AVAILABLE") {
|
||||||
if (unlockedBalanceAfter === unlockedBalanceBefore) {
|
if (unlockedBalanceAfter === unlockedBalanceBefore) {
|
||||||
|
@ -1173,13 +1173,13 @@ export default class HavenoClient {
|
|||||||
*
|
*
|
||||||
* @param {string} tradeId - the id of the trade
|
* @param {string} tradeId - the id of the trade
|
||||||
*/
|
*/
|
||||||
async completeTrade(tradeId: string): Promise<void> {
|
async completeTrade(tradeId: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await this._tradesClient.completeTrade(new CompleteTradeRequest().setTradeId(tradeId), {password: this._password});
|
await this._tradesClient.completeTrade(new CompleteTradeRequest().setTradeId(tradeId), {password: this._password});
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
throw new HavenoError(e.message, e.code);
|
throw new HavenoError(e.message, e.code);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all chat messages for a trade.
|
* Get all chat messages for a trade.
|
||||||
|
Loading…
Reference in New Issue
Block a user