mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-01-12 07:49:52 -05:00
test payout tx state
This commit is contained in:
parent
428e22f7b1
commit
619c2f5ead
@ -726,7 +726,7 @@ test("Has a Monero wallet", async () => {
|
|||||||
|
|
||||||
// create withdraw tx
|
// create withdraw tx
|
||||||
const destination = new XmrDestination().setAddress(await user1.getXmrNewSubaddress()).setAmount("100000000000");
|
const destination = new XmrDestination().setAddress(await user1.getXmrNewSubaddress()).setAmount("100000000000");
|
||||||
let tx = await user1.createXmrTx([destination]);
|
let tx: XmrTx|undefined = await user1.createXmrTx([destination]);
|
||||||
testTx(tx, {isCreatedTx: true});
|
testTx(tx, {isCreatedTx: true});
|
||||||
|
|
||||||
// relay withdraw tx
|
// relay withdraw tx
|
||||||
@ -741,7 +741,7 @@ test("Has a Monero wallet", async () => {
|
|||||||
|
|
||||||
// get relayed tx
|
// get relayed tx
|
||||||
tx = await user1.getXmrTx(txHash);
|
tx = await user1.getXmrTx(txHash);
|
||||||
testTx(tx, {isCreatedTx: false});
|
testTx(tx!, {isCreatedTx: false});
|
||||||
|
|
||||||
// relay invalid tx
|
// relay invalid tx
|
||||||
try {
|
try {
|
||||||
@ -2040,27 +2040,28 @@ async function executeTrade(ctx?: TradeContext): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function testTradePayoutUnlock(ctx: TradeContext) {
|
async function testTradePayoutUnlock(ctx: TradeContext) {
|
||||||
const payoutTxId = (await ctx.buyer!.getTrade(ctx.offerId!)).getPayoutTxId();
|
|
||||||
const payoutTx = await ctx.buyer?.getXmrTx(payoutTxId);
|
|
||||||
const height = await monerod.getHeight();
|
const height = await monerod.getHeight();
|
||||||
|
|
||||||
// test after payout confirmed
|
// test after payout confirmed
|
||||||
if (!payoutTx?.getIsConfirmed()) {
|
const payoutTxId = (await ctx.buyer!.getTrade(ctx.offerId!)).getPayoutTxId();
|
||||||
await mineToHeight(height + 1);
|
let trade = await ctx.buyer!.getTrade(ctx.offerId!);
|
||||||
|
if (trade.getPayoutState() !== "PAYOUT_CONFIRMED") await mineToHeight(height + 1);
|
||||||
await wait(TestConfig.maxWalletStartupMs + TestConfig.walletSyncPeriodMs * 2);
|
await wait(TestConfig.maxWalletStartupMs + TestConfig.walletSyncPeriodMs * 2);
|
||||||
}
|
|
||||||
await testTradeState(await ctx.buyer!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_CONFIRMED", "PAYOUT_UNLOCKED"]});
|
await testTradeState(await ctx.buyer!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_CONFIRMED", "PAYOUT_UNLOCKED"]});
|
||||||
await testTradeState(await ctx.seller!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_CONFIRMED", "PAYOUT_UNLOCKED"]});
|
await testTradeState(await ctx.seller!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_CONFIRMED", "PAYOUT_UNLOCKED"]});
|
||||||
await testTradeState(await ctx.arbitrator!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_PUBLISHED", "PAYOUT_CONFIRMED", "PAYOUT_UNLOCKED"]}); // arbitrator idles wallet
|
await testTradeState(await ctx.arbitrator!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_PUBLISHED", "PAYOUT_CONFIRMED", "PAYOUT_UNLOCKED"]}); // arbitrator idles wallet
|
||||||
|
let payoutTx = await ctx.buyer?.getXmrTx(payoutTxId);
|
||||||
|
expect(payoutTx?.getIsConfirmed());
|
||||||
|
|
||||||
// test after payout unlocked
|
// test after payout unlocked
|
||||||
if (payoutTx?.getIsLocked()) {
|
trade = await ctx.buyer!.getTrade(ctx.offerId!);
|
||||||
await mineToHeight(height + 10);
|
if (trade.getPayoutState() !== "PAYOUT_UNLOCKED") await mineToHeight(height + 10);
|
||||||
await wait(TestConfig.maxWalletStartupMs + TestConfig.walletSyncPeriodMs * 2);
|
await wait(TestConfig.maxWalletStartupMs + TestConfig.walletSyncPeriodMs * 2);
|
||||||
}
|
|
||||||
await testTradeState(await ctx.buyer!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_UNLOCKED"]});
|
await testTradeState(await ctx.buyer!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_UNLOCKED"]});
|
||||||
await testTradeState(await ctx.seller!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_UNLOCKED"]});
|
await testTradeState(await ctx.seller!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_UNLOCKED"]});
|
||||||
await testTradeState(await ctx.arbitrator!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_PUBLISHED", "PAYOUT_CONFIRMED", "PAYOUT_UNLOCKED"]}); // arbitrator idles wallet
|
await testTradeState(await ctx.arbitrator!.getTrade(ctx.offerId!), {phase: "COMPLETED", payoutState: ["PAYOUT_PUBLISHED", "PAYOUT_CONFIRMED", "PAYOUT_UNLOCKED"]}); // arbitrator idles wallet
|
||||||
|
payoutTx = await ctx.buyer?.getXmrTx(payoutTxId);
|
||||||
|
expect(!payoutTx?.getIsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testTradeState(trade: TradeInfo, ctx: TradeContext) {
|
async function testTradeState(trade: TradeInfo, ctx: TradeContext) {
|
||||||
|
@ -866,12 +866,12 @@ export default class HavenoClient {
|
|||||||
* @param {String} txHash - hash of the transaction to get
|
* @param {String} txHash - hash of the transaction to get
|
||||||
* @return {XmrTx} the transaction with the hash
|
* @return {XmrTx} the transaction with the hash
|
||||||
*/
|
*/
|
||||||
async getXmrTx(txHash: string): Promise<XmrTx> {
|
async getXmrTx(txHash: string): Promise<XmrTx|undefined> {
|
||||||
const txs = await this.getXmrTxs(); // TODO (woodser): implement getXmrTx(hash) grpc call
|
const txs = await this.getXmrTxs(); // TODO (woodser): implement getXmrTx(hash) grpc call
|
||||||
for (const tx of txs) {
|
for (const tx of txs) {
|
||||||
if (tx.getHash() === txHash) return tx;
|
if (tx.getHash() === txHash) return tx;
|
||||||
}
|
}
|
||||||
throw new HavenoError("No transaction with hash " + txHash);
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user