From cce5cfadb99ae5b54546f8c329f14f0133c60076 Mon Sep 17 00:00:00 2001 From: "a.dacapo21" Date: Fri, 19 Jan 2024 19:15:01 +0100 Subject: [PATCH 1/4] dexter/cancel-order-tests - minswap cancel order - muesliswap cancel order --- tests/minswap.test.ts | 53 +++++++++++++++++++++++++++++++++++++++- tests/muesliswap.test.ts | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/tests/minswap.test.ts b/tests/minswap.test.ts index b1dd0c6..52c63eb 100644 --- a/tests/minswap.test.ts +++ b/tests/minswap.test.ts @@ -11,9 +11,16 @@ import { PayToAddress, AddressType } from '../src'; - +import { + UTxO +} from '@app/types'; describe('Minswap', () => { + let minswap: Minswap; + const returnAddress = 'mockBlockchainAddress123'; + beforeEach(() => { + minswap = new Minswap(); + }); const walletProvider: MockWalletProvider = new MockWalletProvider(); walletProvider.loadWalletFromSeedPhrase(['']); const dexter: Dexter = (new Dexter()) @@ -21,6 +28,7 @@ describe('Minswap', () => { .withWalletProvider(walletProvider); const asset: Asset = new Asset('f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880', '69555344', 6); + describe('Set Swap In', () => { const liquidityPool: LiquidityPool = new LiquidityPool( @@ -94,4 +102,47 @@ describe('Minswap', () => { }); + describe('Minswap Cancel Order Flow', () => { + + it('should successfully cancel an order', async () => { + let marketOrderAddress = minswap.marketOrderAddress; + const txOutputs: UTxO[] = [ + { + txHash: 'mockTxHash123', + address: marketOrderAddress, + datumHash: 'mockDatumHash123', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 1000000000000n }] + } + ]; + + const result = await minswap.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: 1000n }] + } + ]; + + + try { + await minswap.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/muesliswap.test.ts b/tests/muesliswap.test.ts index 7d798b6..a7c8d1b 100644 --- a/tests/muesliswap.test.ts +++ b/tests/muesliswap.test.ts @@ -11,6 +11,7 @@ import { PayToAddress, AddressType, } from '../src'; +import {UTxO} from "@app/types"; describe('MuesliSwap', () => { @@ -94,4 +95,53 @@ describe('MuesliSwap', () => { }); + describe('Muesliswap Cancel Order FLow', () => { + let muesliswap: MuesliSwap; + const returnAddress = 'mockBlockchainAddress123'; + + beforeEach(() => { + muesliswap = new MuesliSwap(); + }); + + it('should successfully cancel an order', async () => { + let orderAddress = muesliswap.orderAddress; + const txOutputs: UTxO[] = [ + { + txHash: 'mockTxHash123', + address: orderAddress, + datumHash: 'mockDatumHash123', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 10000n }] + } + ]; + + const result = await muesliswap.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: 10000n }] + } + ]; + + try { + await muesliswap.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.'); + } + } + }); + + }); + }); From 27b9c6a66ff53fb781c1500667ea201cdb23a132 Mon Sep 17 00:00:00 2001 From: "a.dacapo21" Date: Fri, 19 Jan 2024 19:18:23 +0100 Subject: [PATCH 2/4] dexter/cancel-order-tests TESTS for: - minswap cancel order - muesliswap cancel order - spectrum cancel order --- tests/minswap.test.ts | 2 +- tests/muesliswap.test.ts | 2 +- tests/spectrum.test.ts | 51 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/tests/minswap.test.ts b/tests/minswap.test.ts index 52c63eb..e7618d7 100644 --- a/tests/minswap.test.ts +++ b/tests/minswap.test.ts @@ -102,7 +102,7 @@ describe('Minswap', () => { }); - describe('Minswap Cancel Order Flow', () => { + describe('Minswap Cancel Order', () => { it('should successfully cancel an order', async () => { let marketOrderAddress = minswap.marketOrderAddress; diff --git a/tests/muesliswap.test.ts b/tests/muesliswap.test.ts index a7c8d1b..c2068ad 100644 --- a/tests/muesliswap.test.ts +++ b/tests/muesliswap.test.ts @@ -95,7 +95,7 @@ describe('MuesliSwap', () => { }); - describe('Muesliswap Cancel Order FLow', () => { + describe('Muesliswap Cancel Order', () => { let muesliswap: MuesliSwap; const returnAddress = 'mockBlockchainAddress123'; diff --git a/tests/spectrum.test.ts b/tests/spectrum.test.ts index a988be0..dc09426 100644 --- a/tests/spectrum.test.ts +++ b/tests/spectrum.test.ts @@ -8,7 +8,7 @@ import { DatumParameters, DatumParameterKey, PayToAddress, - AddressType, + AddressType, MuesliSwap, UTxO, } from '../src'; import { Spectrum } from '../src'; @@ -98,4 +98,53 @@ describe('Spectrum', () => { }); + describe('Spectrum Cancel Order', () => { + let spectrum: Spectrum; + const returnAddress = 'mockBlockchainAddress123'; + + beforeEach(() => { + spectrum = new Spectrum(); + }); + + it('should successfully cancel an order', async () => { + let orderAddress = spectrum.orderAddress; + const txOutputs: UTxO[] = [ + { + txHash: 'mockTxHash123', + address: orderAddress, + datumHash: 'mockDatumHash123', + outputIndex: 0, + assetBalances: [{ asset: 'lovelace', quantity: 10000n }] + } + ]; + + const result = await spectrum.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: 10000n }] + } + ]; + + try { + await spectrum.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.'); + } + } + }); + + }); + }); From 2adab680f4bd50998ba59df995d9cd98e4ebb03e Mon Sep 17 00:00:00 2001 From: "a.dacapo21" Date: Fri, 19 Jan 2024 19:18:42 +0100 Subject: [PATCH 3/4] dexter/cancel-order-tests TESTS for: - minswap cancel order - muesliswap cancel order - spectrum cancel order --- tests/spectrum.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/spectrum.test.ts b/tests/spectrum.test.ts index dc09426..24eb7a3 100644 --- a/tests/spectrum.test.ts +++ b/tests/spectrum.test.ts @@ -8,7 +8,7 @@ import { DatumParameters, DatumParameterKey, PayToAddress, - AddressType, MuesliSwap, UTxO, + AddressType, UTxO, } from '../src'; import { Spectrum } from '../src'; From 95c2799d86cc691532821317d685390d7ffc6835 Mon Sep 17 00:00:00 2001 From: "a.dacapo21" Date: Fri, 19 Jan 2024 23:30:57 +0100 Subject: [PATCH 4/4] 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.'); + } + } + + }); + + }); + });