Skip to content

Commit

Permalink
migrate erc-20 to contract test
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd-ob committed Dec 18, 2024
1 parent 5aa73cf commit bab4345
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 53 deletions.
22 changes: 22 additions & 0 deletions test/e2e/page-objects/pages/send/send-token-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class SendTokenPage {

private readonly toastText = '.toast-text';

private readonly warning =
'[data-testid="send-warning"] .mm-box--min-width-0 span';

constructor(driver: Driver) {
this.driver = driver;
}
Expand Down Expand Up @@ -196,6 +199,25 @@ class SendTokenPage {
text: address,
});
}

/**
* Verifies that a specific warning message is displayed on the send token screen.
*
* @param warningText - The expected warning text to validate against.
* @returns A promise that resolves if the warning message matches the expected text.
* @throws Assertion error if the warning message does not match the expected text.
*/
async check_warningMessage(warningText: string): Promise<void> {
console.log(`Checking if warning message "${warningText}" is displayed`);
const warning = await this.driver.findElement(this.warning);
const text = await warning.getText();
assert.equal(
text,
warningText,
`Expected warning message to be "${warningText}", got "${text}"`,
);
console.log('Warning message validation successful');
}
}

export default SendTokenPage;
46 changes: 46 additions & 0 deletions test/e2e/page-objects/pages/token-overview-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Driver } from '../../webdriver/driver';

class TokenOverviewPage {
private driver: Driver;

private readonly sendButton = '[data-testid="coin-overview-send"]';

private readonly receiveButton = '[data-testid="coin-overview-receive"]';

private readonly swapButton = '[data-testid="token-overview-button-swap"]';

constructor(driver: Driver) {
this.driver = driver;
}

async check_pageIsLoaded(): Promise<void> {
try {
await this.driver.waitForMultipleSelectors([
this.sendButton,
this.receiveButton,
this.swapButton,
]);
} catch (e) {
console.log(
'Timeout while waiting for Token overview page to be loaded',
e,
);
throw e;
}
console.log('Token overview page is loaded');
}

async clickSend(): Promise<void> {
await this.driver.clickElement(this.sendButton);
}

async clickReceive(): Promise<void> {
await this.driver.clickElement(this.receiveButton);
}

async clickSwap(): Promise<void> {
await this.driver.clickElement(this.swapButton);
}
}

export default TokenOverviewPage;
53 changes: 0 additions & 53 deletions test/e2e/tests/tokens/send-erc20-to-contract.spec.js

This file was deleted.

52 changes: 52 additions & 0 deletions test/e2e/tests/tokens/send-erc20-to-contract.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
defaultGanacheOptions,
withFixtures,
unlockWallet,
} from '../../helpers';
import { SMART_CONTRACTS } from '../../seeder/smart-contracts';
import FixtureBuilder from '../../fixture-builder';

import AssetListPage from '../../page-objects/pages/home/asset-list';
import HomePage from '../../page-objects/pages/home/homepage';
import SendTokenPage from '../../page-objects/pages/send/send-token-page';
import TokenOverviewPage from '../../page-objects/pages/token-overview-page';

describe('Send ERC20 token to contract address', function () {
const smartContract = SMART_CONTRACTS.HST;

it('should display the token contract warning to the user', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder().withTokensControllerERC20().build(),
ganacheOptions: defaultGanacheOptions,
smartContract,
title: this.test?.fullTitle(),
},
async ({ driver, contractRegistry }) => {
const contractAddress: string =
await contractRegistry.getContractAddress(smartContract);
await unlockWallet(driver);

const homePage = new HomePage(driver);
const assetListPage = new AssetListPage(driver);
await homePage.check_pageIsLoaded();
await assetListPage.clickOnAsset('Ethereum');

// Send TST
const tokenOverviewPage = new TokenOverviewPage(driver);
await tokenOverviewPage.check_pageIsLoaded();
await tokenOverviewPage.clickSend();

const sendTokenPage = new SendTokenPage(driver);
await sendTokenPage.check_pageIsLoaded();
await sendTokenPage.fillRecipient(contractAddress);

// Verify warning
const warningText =
'Warning: you are about to send to a token contract which could result in a loss of funds. Learn more';
await sendTokenPage.check_warningMessage(warningText);
},
);
});
});

0 comments on commit bab4345

Please sign in to comment.