diff --git a/tests/minswap.test.ts b/tests/minswap.test.ts index b1dd0c6..b460fc1 100644 --- a/tests/minswap.test.ts +++ b/tests/minswap.test.ts @@ -9,11 +9,17 @@ import { DatumParameters, DatumParameterKey, PayToAddress, - AddressType + AddressType, + UTxO } from '../src'; 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 +27,7 @@ describe('Minswap', () => { .withWalletProvider(walletProvider); const asset: Asset = new Asset('f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880', '69555344', 6); + describe('Set Swap In', () => { const liquidityPool: LiquidityPool = new LiquidityPool( @@ -94,4 +101,47 @@ describe('Minswap', () => { }); + describe('Minswap Cancel Order', () => { + + 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..29707a2 100644 --- a/tests/muesliswap.test.ts +++ b/tests/muesliswap.test.ts @@ -10,6 +10,7 @@ import { DatumParameterKey, PayToAddress, AddressType, + UTxO } from '../src'; describe('MuesliSwap', () => { @@ -94,4 +95,53 @@ describe('MuesliSwap', () => { }); + describe('Muesliswap Cancel Order', () => { + 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.'); + } + } + }); + + }); + }); diff --git a/tests/spectrum.test.ts b/tests/spectrum.test.ts index a988be0..dbfc883 100644 --- a/tests/spectrum.test.ts +++ b/tests/spectrum.test.ts @@ -9,8 +9,9 @@ import { DatumParameterKey, PayToAddress, AddressType, + UTxO, + Spectrum } from '../src'; -import { Spectrum } from '../src'; describe('Spectrum', () => { @@ -98,4 +99,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.'); + } + } + }); + + }); + }); 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.'); + } + } + + }); + + }); + });