mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2024-12-25 07:19:29 -05:00
test posting crypto and fiat offers with base and price inversion
This commit is contained in:
parent
7a4d3a375d
commit
f2aca97e5c
@ -923,21 +923,45 @@ test("Can create crypto payment accounts", async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can post and remove an offer", async () => {
|
test("Can post and remove offers", async () => {
|
||||||
|
|
||||||
// wait for alice to have unlocked balance to post offer
|
// wait for alice to have at least 5 outputs of 0.5 XMR
|
||||||
const tradeAmount = BigInt("250000000000");
|
await waitForUnlockedOutputs([aliceWallet], BigInt("500000000000"), 5);
|
||||||
await waitForUnlockedBalance(tradeAmount * BigInt("2"), alice);
|
|
||||||
|
|
||||||
// get unlocked balance before reserving funds for offer
|
// get unlocked balance before reserving funds for offer
|
||||||
const unlockedBalanceBefore = BigInt((await alice.getBalances()).getUnlockedBalance());
|
const unlockedBalanceBefore = BigInt((await alice.getBalances()).getUnlockedBalance());
|
||||||
|
|
||||||
// post offer
|
// post crypto offer
|
||||||
const assetCode = getRandomAssetCode();
|
let assetCode = "ETH";
|
||||||
let offer: OfferInfo = await postOffer(alice, {assetCode: assetCode});
|
let price = 1 / 17;
|
||||||
if (isCrypto(assetCode)) assert.equal(offer.getBaseCurrencyCode(), assetCode); // TODO: crypto base/counter is inverted
|
price = 1 / price; // TODO: price in crypto offer is inverted
|
||||||
else assert.equal(offer.getCounterCurrencyCode(),assetCode);
|
let offer: OfferInfo = await postOffer(alice, {assetCode: assetCode, price: price});
|
||||||
assert.equal(offer.getState(), "AVAILABLE");
|
assert.equal(offer.getState(), "AVAILABLE");
|
||||||
|
assert.equal(offer.getBaseCurrencyCode(), assetCode); // TODO: base and counter currencies inverted in crypto offer
|
||||||
|
assert.equal(offer.getCounterCurrencyCode(), "XMR");
|
||||||
|
assert.equal(offer.getPrice(), price * 100000000); // TODO: price when posting crypto offer is inverted and * 100000000.
|
||||||
|
|
||||||
|
// has offer
|
||||||
|
offer = await alice.getMyOffer(offer.getId());
|
||||||
|
assert.equal(offer.getState(), "AVAILABLE");
|
||||||
|
|
||||||
|
// cancel offer
|
||||||
|
await alice.removeOffer(offer.getId());
|
||||||
|
|
||||||
|
// offer is removed from my offers
|
||||||
|
if (getOffer(await alice.getMyOffers(assetCode, "buy"), offer.getId())) throw new Error("Offer " + offer.getId() + " was found in my offers after removal");
|
||||||
|
|
||||||
|
// reserved balance released
|
||||||
|
expect(BigInt((await alice.getBalances()).getUnlockedBalance())).toEqual(unlockedBalanceBefore);
|
||||||
|
|
||||||
|
// post fiat offer
|
||||||
|
assetCode = "USD";
|
||||||
|
price = 180.0;
|
||||||
|
offer = await postOffer(alice, {assetCode: assetCode, price: price});
|
||||||
|
assert.equal(offer.getState(), "AVAILABLE");
|
||||||
|
assert.equal(offer.getBaseCurrencyCode(), "XMR");
|
||||||
|
assert.equal(offer.getCounterCurrencyCode(), "USD");
|
||||||
|
assert.equal(offer.getPrice(), price * 10000); // TODO: price = price * 10000
|
||||||
|
|
||||||
// has offer
|
// has offer
|
||||||
offer = await alice.getMyOffer(offer.getId());
|
offer = await alice.getMyOffer(offer.getId());
|
||||||
@ -951,23 +975,6 @@ test("Can post and remove an offer", async () => {
|
|||||||
|
|
||||||
// reserved balance released
|
// reserved balance released
|
||||||
expect(BigInt((await alice.getBalances()).getUnlockedBalance())).toEqual(unlockedBalanceBefore);
|
expect(BigInt((await alice.getBalances()).getUnlockedBalance())).toEqual(unlockedBalanceBefore);
|
||||||
});
|
|
||||||
|
|
||||||
test("Can prepare for trading", async () => {
|
|
||||||
|
|
||||||
// create ethereum and revolut payment accounts
|
|
||||||
await createPaymentAccount(alice, "eth");
|
|
||||||
await createRevolutPaymentAccount(alice);
|
|
||||||
await createPaymentAccount(bob, "eth");
|
|
||||||
await createRevolutPaymentAccount(bob);
|
|
||||||
|
|
||||||
// fund alice and bob with at least 5 outputs of 0.5 XMR
|
|
||||||
const numOutputs = 5;
|
|
||||||
const outputAmt = BigInt("500000000000");
|
|
||||||
const walletsToFund = [];
|
|
||||||
if (!await hasUnlockedOutputs(aliceWallet, outputAmt, numOutputs)) walletsToFund.push(aliceWallet);
|
|
||||||
if (!await hasUnlockedOutputs(bobWallet, outputAmt, numOutputs)) walletsToFund.push(bobWallet);
|
|
||||||
await fundWallets(walletsToFund, outputAmt, numOutputs);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO (woodser): test grpc notifications
|
// TODO (woodser): test grpc notifications
|
||||||
@ -1101,7 +1108,7 @@ test("Can resolve disputes", async () => {
|
|||||||
|
|
||||||
// wait for alice and bob to have unlocked balance for trade
|
// wait for alice and bob to have unlocked balance for trade
|
||||||
const tradeAmount = BigInt("250000000000");
|
const tradeAmount = BigInt("250000000000");
|
||||||
await fundWallets([aliceWallet, bobWallet], tradeAmount * BigInt("6"), 4);
|
await waitForUnlockedOutputs([aliceWallet, bobWallet], tradeAmount * BigInt("6"), 4);
|
||||||
|
|
||||||
// register to receive notifications
|
// register to receive notifications
|
||||||
const aliceNotifications: NotificationMessage[] = [];
|
const aliceNotifications: NotificationMessage[] = [];
|
||||||
@ -1835,7 +1842,7 @@ async function hasUnlockedOutputs(wallet: any, amt: BigInt, numOutputs?: number)
|
|||||||
* @param {BigInt} amt - the amount to fund
|
* @param {BigInt} amt - the amount to fund
|
||||||
* @param {number?} numOutputs - the number of outputs of the given amount (default 1)
|
* @param {number?} numOutputs - the number of outputs of the given amount (default 1)
|
||||||
*/
|
*/
|
||||||
async function fundWallets(wallets: any[], amt: BigInt, numOutputs?: number): Promise<void> {
|
async function waitForUnlockedOutputs(wallets: any[], amt: BigInt, numOutputs?: number): Promise<void> {
|
||||||
if (numOutputs === undefined) numOutputs = 1;
|
if (numOutputs === undefined) numOutputs = 1;
|
||||||
|
|
||||||
// collect destinations
|
// collect destinations
|
||||||
|
Loading…
Reference in New Issue
Block a user