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

Cancel Orders #73

Merged
merged 4 commits into from
Jan 20, 2024
Merged

Cancel Orders #73

merged 4 commits into from
Jan 20, 2024

Conversation

Sluder
Copy link
Member

@Sluder Sluder commented Jan 4, 2024

No description provided.

@Sluder Sluder linked an issue Jan 4, 2024 that may be closed by this pull request
@Sluder Sluder marked this pull request as ready for review January 4, 2024 15:38
Copy link
Contributor

@adacapo21 adacapo21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation seems ok. Request to add test cases concerning cancelling orders for swaps in dexes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add some tests cases here (and for all the others dexes similarly):
I created locally 2 scenarios for cancelling orders (Success & Failure) for minswap, you can do the same for the other dexs.
I write the snippet of code below so you can add them:

import {
    UTxO
} from '@app/types';

then under describe

describe('Minswap', () => {
    let minswap: Minswap;
    const returnAddress = 'mockBlockchainAddress123';

    beforeEach(() => {
        minswap = new Minswap();
    });
   // rest of the code as it is and add below:
   
  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.');
                }
            }
        });
    });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a PR for Tests regarding Cancel Orders, so you don't need to add on this PR.
PR is ok for me.

@Sluder Sluder merged commit 3bec031 into master Jan 20, 2024
2 checks passed
@Sluder Sluder deleted the sluder/cancel-orders branch January 20, 2024 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: cancelSwapRequest failing on all dexs
2 participants