Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dexter/cancel orders tests #74

Merged
merged 5 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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