Skip to content

Commit

Permalink
feat: add prevent tx test
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Feb 26, 2024
1 parent d6847cb commit a93ab51
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactNode } from 'react';

import BroadcastError from '@assets/images/unhappy-face-ui.png';
import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors';
import { Box, Flex, FlexProps, styled } from 'leather-styles/jsx';

interface BroadcastErrorProps extends FlexProps {
Expand All @@ -23,7 +24,12 @@ export function BroadcastErrorLayout(props: BroadcastErrorProps) {
<Box mt="space.05">
<img src={BroadcastError} alt="Unhappy user interface cloud" width="106px" />
</Box>
<styled.span mx="space.05" mt="space.05" textStyle="heading.05">
<styled.span
data-testid={SharedComponentsSelectors.BroadcastErrorTitle}
mx="space.05"
mt="space.05"
textStyle="heading.05"
>
{title}
</styled.span>
<styled.span color="accent.text-subdued" mt="space.04" textAlign="center" textStyle="body.02">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { hexToBytes } from '@noble/hashes/utils';
import * as btc from '@scure/btc-signer';
import { SendCryptoAssetSelectors } from '@tests/selectors/send.selectors';
import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors';
import { Stack } from 'leather-styles/jsx';
import get from 'lodash.get';

Expand Down Expand Up @@ -157,7 +158,12 @@ export function BtcSendFormConfirmation() {
</Stack>

<InfoCardFooter>
<Button aria-busy={isBroadcasting} onClick={initiateTransaction} width="100%">
<Button
data-testid={SharedComponentsSelectors.InfoCardButton}
aria-busy={isBroadcasting}
onClick={initiateTransaction}
width="100%"
>
Confirm and send transaction
</Button>
</InfoCardFooter>
Expand Down
3 changes: 2 additions & 1 deletion src/app/query/bitcoin/transaction/use-check-utxos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback, useState } from 'react';
import * as btc from '@scure/btc-signer';
import { bytesToHex } from '@stacks/common';

import { IS_TEST_ENV } from '@shared/environment';
import { isUndefined } from '@shared/utils';

import { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
Expand Down Expand Up @@ -100,7 +101,7 @@ export function useCheckInscribedUtxos(blockTxAction?: () => void) {

try {
// no need to check for inscriptions on testnet
if (isTestnet) {
if (isTestnet && !IS_TEST_ENV) {
return false;
}

Expand Down
46 changes: 46 additions & 0 deletions tests/mocks/mock-ordinalscom-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export const mockOrdinalsComApiHtmlResponse = `
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta property="og:title" content="Output b4c94b7270d8b97c5dc9ecc73176ee7d93e96135b60dfef1b601d661bfd7884b:0">
<meta property="og:image" content="https://generative-ordinal-node-prod/static/favicon.png">
<meta property="twitter:card" content="summary">
<title>Output b4c94b7270d8b97c5dc9ecc73176ee7d93e96135b60dfef1b601d661bfd7884b:0</title>
<link rel="alternate" href="/feed.xml" type="application/rss+xml" title="Inscription RSS Feed">
<link rel="stylesheet" href="/static/index.css">
<link rel="stylesheet" href="/static/modern-normalize.css">
<script src="/static/index.js" defer></script>
</head>
<body>
<header>
<nav>
<a href="/">Ordinals<sup>alpha</sup></a>
<a href="https://docs.ordinals.com/">Handbook</a>
<a href="https://github.com/ordinals/ord">Wallet</a>
<a href="https://discord.com/invite/ordinals">Discord</a>
<a href="/clock">Clock</a>
<form action="/search" method="get">
<input type="text" autocapitalize="off" autocomplete="off" autocorrect="off" name="query" spellcheck="false">
<input type="submit" value="Search">
</form>
</nav>
</header>
<main>
<h1>Output <span class="monospace">b4c94b7270d8b97c5dc9ecc73176ee7d93e96135b60dfef1b601d661bfd7884b:0</span></h1>
<dl>
<dt>inscriptions</dt>
<dd class="thumbnails">
<a href="/inscription/1c129e8c9b770d457049a33582b6c10d51c80d1cd9bbea0bcb2175830f9bee60i0"><iframe sandbox="allow-scripts" scrolling="no" loading="lazy" src="/preview/1c129e8c9b770d457049a33582b6c10d51c80d1cd9bbea0bcb2175830f9bee60i0"></iframe></a>
</dd>
<dt>value</dt><dd>1461</dd>
<dt>script pubkey</dt><dd class="monospace">OP_0 OP_PUSHBYTES_20 20d6ea31e3b6c8b43d1c8d52fd24c1226caa9bd2</dd>
<dt>address</dt><dd class="monospace">bc1qyrtw5v0rkmytg0gu34f06fxpyfk24x7jevtvx3</dd>
<dt>transaction</dt><dd><a class="monospace" href="/tx/b4c94b7270d8b97c5dc9ecc73176ee7d93e96135b60dfef1b601d661bfd7884b">b4c94b7270d8b97c5dc9ecc73176ee7d93e96135b60dfef1b601d661bfd7884b</a></dd>
</dl>
</main>
</body>
</html>
`;
8 changes: 8 additions & 0 deletions tests/page-object-models/send.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class SendPage {
readonly memoRow: Locator;
readonly feesListItem: Locator;
readonly feeToBePaid: Locator;
readonly infoCardButton: Locator;
readonly broadcastErrorTitle: Locator;

constructor(page: Page) {
this.page = page;
Expand Down Expand Up @@ -58,6 +60,8 @@ export class SendPage {
this.sendMaxButton = page.getByTestId(SendCryptoAssetSelectors.SendMaxBtn);
this.feesListItem = page.getByTestId(SharedComponentsSelectors.FeesListItem);
this.feeToBePaid = page.getByTestId(SharedComponentsSelectors.FeeToBePaidLabel);
this.infoCardButton = page.getByTestId(SharedComponentsSelectors.InfoCardButton);
this.broadcastErrorTitle = page.getByTestId(SharedComponentsSelectors.BroadcastErrorTitle);
}

async selectBtcAndGoToSendForm() {
Expand Down Expand Up @@ -92,4 +96,8 @@ export class SendPage {
await this.goBack();
await this.selectStxAndGoToSendForm();
}

async clickInfoCardButton() {
await this.infoCardButton.click();
}
}
4 changes: 4 additions & 0 deletions tests/selectors/shared-component.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum SharedComponentsSelectors {
// InfoCard
InfoCardAssetValue = 'info-card-asset-value',
InfoCardRowValue = 'info-card-row-value',
InfoCardButton = 'info-card-button',

// Fees
FeeRow = 'fee-row',
Expand All @@ -20,4 +21,7 @@ export enum SharedComponentsSelectors {

// Modal Header
ModalHeaderBackBtn = 'modal-header-back-button',

// Error
BroadcastErrorTitle = 'broadcast-error-title',
}
22 changes: 22 additions & 0 deletions tests/specs/send/send-btc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TEST_TESTNET_ACCOUNT_2_BTC_ADDRESS } from '@tests/mocks/constants';
import { mockOrdinalsComApiHtmlResponse } from '@tests/mocks/mock-ordinalscom-api';
import { SendCryptoAssetSelectors } from '@tests/selectors/send.selectors';
import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors';
import { getDisplayerAddress } from '@tests/utils';
Expand Down Expand Up @@ -82,5 +83,26 @@ test.describe('send btc', () => {

test.expect(fee).toContain(confirmationFee);
});

test('that prevents transaction if it contains inscribed utxo', async ({ sendPage }) => {
await sendPage.page.route('**/ordinals-explorer.generative.xyz/**', async route => {
return route.fulfill({
status: 200,
contentType: 'text/html',
body: mockOrdinalsComApiHtmlResponse,
});
});
await sendPage.amountInput.fill('0.00006');
await sendPage.recipientInput.fill(TEST_TESTNET_ACCOUNT_2_BTC_ADDRESS);

await sendPage.previewSendTxButton.click();
await sendPage.feesListItem.filter({ hasText: BtcFeeType.High }).click();

await sendPage.clickInfoCardButton();

const isErrorPageVisible = await sendPage.broadcastErrorTitle.isVisible();

test.expect(isErrorPageVisible).toBeTruthy();
});
});
});

0 comments on commit a93ab51

Please sign in to comment.