From 95c2799d86cc691532821317d685390d7ffc6835 Mon Sep 17 00:00:00 2001 From: "a.dacapo21" Date: Fri, 19 Jan 2024 23:30:57 +0100 Subject: [PATCH] dexter/cancel-order-tests TESTS for: - minswap cancel order - muesliSwap cancel order - spectrum cancel order - teddySwap cancel order - vyFinance cancel order - wingRiders cancel order - sundaeSwap cancel order --- tests/minswap.test.ts | 7 ++- tests/muesliswap.test.ts | 2 +- tests/spectrum.test.ts | 5 ++- tests/sundaeswap.test.ts | 49 ++++++++++++++++++++ tests/teddyswap.test.ts | 51 ++++++++++++++++++++- tests/vyfinance.test.ts | 96 +++++++++++++++++++++++++++++++++++++--- tests/wingriders.test.ts | 50 ++++++++++++++++++++- 7 files changed, 246 insertions(+), 14 deletions(-) diff --git a/tests/minswap.test.ts b/tests/minswap.test.ts index e7618d7..b460fc1 100644 --- a/tests/minswap.test.ts +++ b/tests/minswap.test.ts @@ -9,11 +9,10 @@ import { DatumParameters, DatumParameterKey, PayToAddress, - AddressType -} from '../src'; -import { + AddressType, UTxO -} from '@app/types'; +} from '../src'; + describe('Minswap', () => { let minswap: Minswap; const returnAddress = 'mockBlockchainAddress123'; diff --git a/tests/muesliswap.test.ts b/tests/muesliswap.test.ts index c2068ad..29707a2 100644 --- a/tests/muesliswap.test.ts +++ b/tests/muesliswap.test.ts @@ -10,8 +10,8 @@ import { DatumParameterKey, PayToAddress, AddressType, + UTxO } from '../src'; -import {UTxO} from "@app/types"; describe('MuesliSwap', () => { diff --git a/tests/spectrum.test.ts b/tests/spectrum.test.ts index 24eb7a3..dbfc883 100644 --- a/tests/spectrum.test.ts +++ b/tests/spectrum.test.ts @@ -8,9 +8,10 @@ import { DatumParameters, DatumParameterKey, PayToAddress, - AddressType, UTxO, + AddressType, + UTxO, + Spectrum } from '../src'; -import { Spectrum } from '../src'; describe('Spectrum', () => { diff --git a/tests/sundaeswap.test.ts b/tests/sundaeswap.test.ts index bd301e8..35d20ac 100644 --- a/tests/sundaeswap.test.ts +++ b/tests/sundaeswap.test.ts @@ -10,6 +10,7 @@ import { DatumParameterKey, PayToAddress, AddressType, + UTxO, } from '../src'; describe('SundaeSwap', () => { @@ -97,4 +98,52 @@ describe('SundaeSwap', () => { }); + describe('SundaeSwap Cancel Order', () => { + let sundaeswap: SundaeSwap; + const returnAddress = 'addr1'; + beforeEach(() => { + sundaeswap = new SundaeSwap(); + }); + + it('should successfully cancel an order', async () => { + let marketOrderAddress = sundaeswap.orderAddress; + const txOutputs: UTxO[] = [ + { + txHash: 'mockTxHash123', + address: marketOrderAddress, + datumHash: 'mockDatumHash123', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 1000000000000n }] + } + ]; + + const result = await sundaeswap.buildCancelSwapOrder(txOutputs, returnAddress); + + expect(result).toBeDefined(); + expect(result[0].address).toBe(returnAddress); + }); + + it('should fail to cancel an order with invalid UTxO', async () => { + const invalidTxOutputs: UTxO[] = [ + { + txHash: 'invalidTxHash', + address: 'invalidAddress', + datumHash: 'invalidDatumHash', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 1000000000000n }] + } + ]; + try { + await sundaeswap.buildCancelSwapOrder(invalidTxOutputs, returnAddress); + fail('Expected buildCancelSwapOrder to throw an error'); + } catch (error: unknown) { + if (error instanceof Error) { + expect(error.message).toContain('Unable to find relevant UTxO for cancelling the swap order.'); + } + } + + }); + + }); + }); diff --git a/tests/teddyswap.test.ts b/tests/teddyswap.test.ts index 064cb8e..f02e260 100644 --- a/tests/teddyswap.test.ts +++ b/tests/teddyswap.test.ts @@ -9,7 +9,7 @@ import { DatumParameterKey, PayToAddress, AddressType, - TeddySwap, + TeddySwap, UTxO, } from '../src'; describe('TeddySwap', () => { @@ -98,4 +98,53 @@ describe('TeddySwap', () => { }); + describe('Teddyswap Cancel Order', () => { + let teddyswap: TeddySwap; + const returnAddress = 'addr1'; + beforeEach(() => { + teddyswap = new TeddySwap(); + }); + + it('should successfully cancel an order', async () => { + let marketOrderAddress = teddyswap.orderAddress; + const txOutputs: UTxO[] = [ + { + txHash: 'mockTxHash123', + address: marketOrderAddress, + datumHash: 'mockDatumHash123', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 1000000000000n }] + } + ]; + + const result = await teddyswap.buildCancelSwapOrder(txOutputs, returnAddress); + + expect(result).toBeDefined(); + expect(result[0].address).toBe(returnAddress); + }); + + it('should fail to cancel an order with invalid UTxO', async () => { + const invalidTxOutputs: UTxO[] = [ + { + txHash: 'invalidTxHash', + address: 'invalidAddress', + datumHash: 'invalidDatumHash', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 1000000000000n }] + } + ]; + try { + await teddyswap.buildCancelSwapOrder(invalidTxOutputs, returnAddress); + fail('Expected buildCancelSwapOrder to throw an error'); + } catch (error: unknown) { + if (error instanceof Error) { + expect(error.message).toContain('Unable to find relevant UTxO for cancelling the swap order.'); + } + } + + }); + + + }); + }); diff --git a/tests/vyfinance.test.ts b/tests/vyfinance.test.ts index 08e8273..0b8773e 100644 --- a/tests/vyfinance.test.ts +++ b/tests/vyfinance.test.ts @@ -1,14 +1,15 @@ import { + AddressType, + Asset, + DatumParameterKey, + DatumParameters, Dexter, LiquidityPool, MockDataProvider, - SwapRequest, - Asset, MockWalletProvider, - DatumParameters, - DatumParameterKey, PayToAddress, - AddressType, + SwapRequest, + UTxO, VyFinance, } from '../src'; @@ -96,4 +97,89 @@ describe('VyFinance', () => { }); + describe('VyFinance Cancel Order', () => { + let vyFinance: VyFinance; + const returnAddress = 'addr1'; + beforeEach(() => { + vyFinance = new VyFinance(); + vyFinance.api.liquidityPools = async () => { + const liquidityPool = new LiquidityPool( + VyFinance.identifier, + 'lovelace', + new Asset('f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880', '69555344'), + 519219742499n, + 39619096012n, + 'mockPoolAddress', + 'mockMarketOrderAddress', + 'mockLimitOrderAddress', + ); + liquidityPool.extra = { + nft: { + policyId: 'mockNftPolicyId' + } + }; + + return [liquidityPool]; + }; + }); + + it('should successfully cancel an order', async () => { + const MockUTxO: UTxO[] = [{ + txHash: 'mockTxHash', + address: 'mockMarketOrderAddress', + datumHash: 'mockDatumHash', + outputIndex: 0, + assetBalances: [{asset: 'lovelace', quantity: 1000000000000n}] + }]; + + const cancelOrder = await vyFinance.buildCancelSwapOrder(MockUTxO, returnAddress); + expect(cancelOrder).toBeDefined(); + expect(cancelOrder[0].address).toBe('addr1'); + expect(cancelOrder[0].assetBalances[0].quantity).toBe(1000000000000n); + }); + + it('should fail to cancel an order when the liquidity pool is not found', async () => { + const mockUTxO: UTxO[] = [{ + txHash: 'mockTxHash', + address: 'mockAddress', + datumHash: 'mockDatumHash', + outputIndex: 0, + assetBalances: [{asset: 'lovelace', quantity: 1000000000000n}] + }]; + + try { + await vyFinance.buildCancelSwapOrder(mockUTxO, returnAddress); + fail('Expected buildCancelSwapOrder to throw an error'); + } catch (error: unknown) { + if (error instanceof Error) { + expect(error.message).toContain('Unable to find relevant liquidity pool for cancelling the swap order.'); + } + } + + }); + + it('should fail to cancel an order with invalid UTxO', async () => { + const invalidTxOutputs: UTxO[] = [ + { + txHash: 'invalidTxHash', + address: 'invalidAddress', + datumHash: 'invalidDatumHash', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 1000000000000n }] + } + ]; + + try { + await vyFinance.buildCancelSwapOrder(invalidTxOutputs, returnAddress); + fail('Expected buildCancelSwapOrder to throw an error'); + } catch (error: unknown) { + if (error instanceof Error) { + expect(error.message).toContain('Unable to find relevant UTxO for cancelling the swap order.'); + } + } + + }); + + }); + }); diff --git a/tests/wingriders.test.ts b/tests/wingriders.test.ts index f551c45..06b054b 100644 --- a/tests/wingriders.test.ts +++ b/tests/wingriders.test.ts @@ -9,7 +9,7 @@ import { DatumParameters, DatumParameterKey, PayToAddress, - AddressType, + AddressType, UTxO, } from '../src'; describe('WingRiders', () => { @@ -115,4 +115,52 @@ describe('WingRiders', () => { }); + describe('Wingriders Cancel Order', () => { + let wingRiders: WingRiders; + const returnAddress = 'addr1'; + beforeEach(() => { + wingRiders = new WingRiders(); + }); + + it('should successfully cancel an order', async () => { + let marketOrderAddress = wingRiders.orderAddress; + const txOutputs: UTxO[] = [ + { + txHash: 'mockTxHash123', + address: marketOrderAddress, + datumHash: 'mockDatumHash123', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 1000000000000n }] + } + ]; + + const result = await wingRiders.buildCancelSwapOrder(txOutputs, returnAddress); + + expect(result).toBeDefined(); + expect(result[0].address).toBe(returnAddress); + }); + + it('should fail to cancel an order with invalid UTxO', async () => { + const invalidTxOutputs: UTxO[] = [ + { + txHash: 'invalidTxHash', + address: 'invalidAddress', + datumHash: 'invalidDatumHash', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 1000000000000n }] + } + ]; + try { + await wingRiders.buildCancelSwapOrder(invalidTxOutputs, returnAddress); + fail('Expected buildCancelSwapOrder to throw an error'); + } catch (error: unknown) { + if (error instanceof Error) { + expect(error.message).toContain('Unable to find relevant UTxO for cancelling the swap order.'); + } + } + + }); + + }); + });