Skip to content

Commit

Permalink
Merge pull request #74 from IndigoProtocol/dexter/cancel-orders-tests
Browse files Browse the repository at this point in the history
Dexter/cancel orders tests
  • Loading branch information
Sluder authored Jan 20, 2024
2 parents 3bec031 + da1807d commit af9b32b
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 9 deletions.
52 changes: 51 additions & 1 deletion tests/minswap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ 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())
.withDataProvider(new MockDataProvider())
.withWalletProvider(walletProvider);
const asset: Asset = new Asset('f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880', '69555344', 6);


describe('Set Swap In', () => {

const liquidityPool: LiquidityPool = new LiquidityPool(
Expand Down Expand Up @@ -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.');
}
}
});
});

});
50 changes: 50 additions & 0 deletions tests/muesliswap.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('MuesliSwap', () => {
Expand Down Expand Up @@ -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.');
}
}
});

});

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

describe('Spectrum', () => {

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

});

});
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.');
}
}

});


});

});
Loading

0 comments on commit af9b32b

Please sign in to comment.