Skip to content

Commit

Permalink
dexter/cancel-order-tests
Browse files Browse the repository at this point in the history
TESTS for:
- minswap cancel order
- muesliSwap cancel order
- spectrum cancel order
- teddySwap cancel order
- vyFinance cancel order
- wingRiders cancel order
- sundaeSwap cancel order
  • Loading branch information
adacapo21 committed Jan 19, 2024
1 parent 2adab68 commit 95c2799
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 14 deletions.
7 changes: 3 additions & 4 deletions tests/minswap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion tests/muesliswap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
DatumParameterKey,
PayToAddress,
AddressType,
UTxO
} from '../src';
import {UTxO} from "@app/types";

describe('MuesliSwap', () => {

Expand Down
5 changes: 3 additions & 2 deletions tests/spectrum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
DatumParameters,
DatumParameterKey,
PayToAddress,
AddressType, UTxO,
AddressType,
UTxO,
Spectrum
} from '../src';
import { Spectrum } from '../src';

describe('Spectrum', () => {

Expand Down
49 changes: 49 additions & 0 deletions tests/sundaeswap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DatumParameterKey,
PayToAddress,
AddressType,
UTxO,
} from '../src';

describe('SundaeSwap', () => {
Expand Down Expand Up @@ -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.');
}
}

});

});

});
51 changes: 50 additions & 1 deletion tests/teddyswap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DatumParameterKey,
PayToAddress,
AddressType,
TeddySwap,
TeddySwap, UTxO,
} from '../src';

describe('TeddySwap', () => {
Expand Down Expand Up @@ -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.');
}
}

});


});

});
96 changes: 91 additions & 5 deletions tests/vyfinance.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {
AddressType,
Asset,
DatumParameterKey,
DatumParameters,
Dexter,
LiquidityPool,
MockDataProvider,
SwapRequest,
Asset,
MockWalletProvider,
DatumParameters,
DatumParameterKey,
PayToAddress,
AddressType,
SwapRequest,
UTxO,
VyFinance,
} from '../src';

Expand Down Expand Up @@ -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.');
}
}

});

});

});
50 changes: 49 additions & 1 deletion tests/wingriders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DatumParameters,
DatumParameterKey,
PayToAddress,
AddressType,
AddressType, UTxO,
} from '../src';

describe('WingRiders', () => {
Expand Down Expand Up @@ -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.');
}
}

});

});

});

0 comments on commit 95c2799

Please sign in to comment.