diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/AddressRow.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/AddressRow.tsx index fbe213250f..66db6415fe 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/AddressRow.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/AddressRow.tsx @@ -301,6 +301,7 @@ export function AddressRow({ style={tailwind("text-xs mx-1 font-normal-v2")} light={tailwind("text-mono-light-v2-500")} dark={tailwind("text-mono-dark-v2-500")} + testID="verified_address" > {translate("screens/SendScreen", "Verified {{text}}", { text: validEvmAddress diff --git a/mobile-app/cypress/e2e/functional/wallet/loans/DUSD_Loops.spec.ts b/mobile-app/cypress/e2e/functional/wallet/loans/DUSD_Loops.spec.ts new file mode 100644 index 0000000000..a4d9ab8d7c --- /dev/null +++ b/mobile-app/cypress/e2e/functional/wallet/loans/DUSD_Loops.spec.ts @@ -0,0 +1,188 @@ +import { checkValueWithinRange } from "../../../../support/walletCommands"; + +function addDFICollaterals() { + cy.createEmptyWallet(true); + cy.sendDFItoWallet() + .sendDFITokentoWallet() + .sendDFITokentoWallet() + .sendDFITokentoWallet() + .sendTokenToWallet(["BTC", "ETH"]) + .wait(6000); +} + +context("Wallet - Loans - DUSD Loops", () => { + let cntr = -1; + before(() => { + addDFICollaterals(); + cy.getByTestID("bottom_tab_loans").click(); + cy.getByTestID("loans_tabs_YOUR_VAULTS").click(); + }); + + beforeEach(() => { + cy.getByTestID("bottom_tab_loans").click(); + cy.createVault(0); + cntr++; + }); + + it("should allow user to take a DUSD Loan when vault has 100% DFI collateral", () => { + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("not.exist"); + cy.getByTestID(`vault_card_${cntr}_EMPTY_add_collateral_button`).click(); + cy.addCollateral("10", "DFI"); + cy.getByTestID(`vault_card_${cntr}_status`).contains("Ready"); + cy.getByTestID(`vault_card_${cntr}_collateral_token_group_DFI`).should( + "exist", + ); + cy.getByTestID(`vault_card_${cntr}_total_collateral_amount`).contains( + "$1,000.00", + ); + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("exist").click(); + cy.getByTestID("select_DUSD").click(); + cy.getByTestID("text_input_borrow_amount").type("5").blur(); + cy.getByTestID("borrow_button_submit").click(); + cy.getByTestID("confirm_title").contains("You are borrowing"); + cy.getByTestID("text_borrow_amount").contains("5.00000000"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("vault_id_value").should("exist"); + cy.getByTestID("col_ratio_value") + .invoke("text") + .then((text) => { + checkValueWithinRange("19,999.98", text, 0.1); + }); + cy.getByTestID("tokens_to_borrow").contains("5 DUSD"); + cy.getByTestID("button_confirm_borrow_loan").click().wait(3000); + cy.getByTestID("txn_authorization_title").contains( + "Borrowing 5.00000000 DUSD", + ); + + cy.closeOceanInterface(); + cy.getByTestID("vault_card_0").should("exist").click().wait(3000); + cy.getByTestID("loan_card_DUSD_amount") + .should("contain", "5.00") + .and("contain", "DUSD"); + }); + + it("should allow user to take a DUSD Loan when vault has 100% DUSD collateral", () => { + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("not.exist"); + cy.getByTestID(`vault_card_${cntr}_EMPTY_add_collateral_button`).click(); + cy.addCollateral("5", "DUSD"); + cy.getByTestID(`vault_card_${cntr}_status`).contains("Ready"); + cy.getByTestID(`vault_card_${cntr}_collateral_token_group_DUSD`).should( + "exist", + ); + cy.getByTestID(`vault_card_${cntr}_total_collateral_amount`).contains( + "$6.00", + ); + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("exist").click(); + cy.getByTestID("select_DUSD").click(); + cy.getByTestID("text_input_borrow_amount").type("2").blur(); + cy.getByTestID("borrow_button_submit").click(); + cy.getByTestID("confirm_title").contains("You are borrowing"); + cy.getByTestID("text_borrow_amount").contains("2.00000000"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("vault_id_value").should("exist"); + cy.getByTestID("col_ratio_value") + .invoke("text") + .then((text) => { + checkValueWithinRange("299.99", text, 0.1); + }); + cy.getByTestID("tokens_to_borrow").contains("2 DUSD"); + cy.getByTestID("button_confirm_borrow_loan").click().wait(3000); + cy.getByTestID("txn_authorization_title").contains( + "Borrowing 2.00000000 DUSD", + ); + + cy.closeOceanInterface(); + }); + + it("should allow user to take a DUSD Loan when vault has 50% DFI + other tokens as collateral", () => { + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("not.exist"); + cy.getByTestID(`vault_card_${cntr}_EMPTY_add_collateral_button`).click(); + cy.addCollateral("3", "DFI"); + cy.getByTestID(`vault_card_${cntr}`).click(); + cy.getByTestID("action_add").click(); + cy.addCollateral("6", "dBTC"); + cy.getByTestID(`vault_card_${cntr}_status`).contains("Ready"); + cy.getByTestID(`vault_card_${cntr}_collateral_token_group_DFI`).should( + "exist", + ); + cy.getByTestID(`vault_card_${cntr}_collateral_token_group_dBTC`).should( + "exist", + ); + cy.getByTestID(`vault_card_${cntr}_total_collateral_amount`).contains( + "$600.00", + ); + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("exist").click(); + cy.getByTestID("select_DUSD").click(); + cy.getByTestID("text_input_borrow_amount").type("3").blur(); + cy.getByTestID("borrow_button_submit").click(); + cy.getByTestID("confirm_title").contains("You are borrowing"); + cy.getByTestID("text_borrow_amount").contains("3.00000000"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("vault_id_value").should("exist"); + cy.getByTestID("col_ratio_value") + .invoke("text") + .then((text) => { + checkValueWithinRange("19,999.98", text, 0.1); + }); + cy.getByTestID("tokens_to_borrow").contains("3 DUSD"); + cy.getByTestID("button_confirm_borrow_loan").click().wait(3000); + cy.getByTestID("txn_authorization_title").contains( + "Borrowing 3.00000000 DUSD", + ); + + cy.closeOceanInterface(); + cy.wait(3000); + cy.getByTestID(`vault_card_${cntr}`).should("exist").click(); + cy.getByTestID("loan_card_DUSD_amount") + .should("contain", "3.00") + .and("contain", "DUSD"); + }); + + it("should not allow user to take a DUSD Loan when vault has 0% DFI + other tokens as collateral", () => { + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("not.exist"); + cy.getByTestID(`vault_card_${cntr}_EMPTY_add_collateral_button`).click(); + cy.addCollateral("3", "dETH"); + cy.getByTestID(`vault_card_${cntr}_status`).contains("Ready"); + cy.getByTestID(`vault_card_${cntr}_collateral_token_group_dETH`).should( + "exist", + ); + cy.getByTestID(`vault_card_${cntr}_total_collateral_amount`).contains( + "$21.00", + ); + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("exist").click(); + cy.getByTestID("select_DUSD").click(); + cy.getByTestID("text_input_borrow_amount").type("5").blur(); + cy.getByTestID("borrow_button_submit").should("have.attr", "aria-disabled"); + cy.getByTestID("validation_message").should( + "have.text", + "Insufficient DFI and/or DUSD in vault. Add more to start minting dTokens.", + ); + }); + + it("should not allow user to take a DUSD Loan when vault has <50% DFI + other tokens as collateral", () => { + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("not.exist"); + cy.getByTestID(`vault_card_${cntr}_EMPTY_add_collateral_button`).click(); + cy.addCollateral("0.005", "DFI"); + cy.getByTestID(`vault_card_${cntr}`).click(); + cy.getByTestID("action_add").click(); + cy.addCollateral("2", "dBTC"); + cy.getByTestID(`vault_card_${cntr}_status`).contains("Ready"); + cy.getByTestID(`vault_card_${cntr}_collateral_token_group_DFI`).should( + "exist", + ); + cy.getByTestID(`vault_card_${cntr}_collateral_token_group_dBTC`).should( + "exist", + ); + cy.getByTestID(`vault_card_${cntr}_total_collateral_amount`).contains( + "$100.50", + ); + cy.getByTestID(`vault_card_${cntr}_borrow_button`).should("exist").click(); + cy.getByTestID("select_DUSD").click(); + cy.getByTestID("text_input_borrow_amount").type("5").blur(); + cy.getByTestID("borrow_button_submit").should("have.attr", "aria-disabled"); + cy.getByTestID("validation_message").should( + "have.text", + "Insufficient DFI and/or DUSD in vault. Add more to borrow DUSD.", + ); + }); +}); diff --git a/mobile-app/cypress/e2e/functional/wallet/portfolio/convert/convert.spec.ts b/mobile-app/cypress/e2e/functional/wallet/portfolio/convert/convert.spec.ts index 53159e9c19..597db33f5e 100644 --- a/mobile-app/cypress/e2e/functional/wallet/portfolio/convert/convert.spec.ts +++ b/mobile-app/cypress/e2e/functional/wallet/portfolio/convert/convert.spec.ts @@ -4,23 +4,26 @@ import { checkValueWithinRange } from "../../../../../support/walletCommands"; BigNumber.set({ ROUNDING_MODE: BigNumber.ROUND_DOWN }); function createDFIWallet(): void { - cy.createEmptyWallet(true); - cy.sendDFItoWallet().sendDFItoWallet().sendDFITokentoWallet().wait(10000); - + createDFIWalletWithTokens(); cy.getByTestID("bottom_tab_portfolio").click(); cy.getByTestID("portfolio_list").should("exist"); - cy.getByTestID("dfi_total_balance_amount").contains("30.00000000"); + cy.getByTestID("dfi_total_balance_amount").contains("20.00000000"); cy.getByTestID("dfi_balance_card").should("exist").click(); cy.getByTestID("dfi_token_amount").contains("10.00000000"); - cy.getByTestID("dfi_utxo_amount").contains("20.00000000"); - cy.getByTestID("convert_button").click(); + cy.getByTestID("dfi_utxo_amount").contains("10.00000000"); + cy.getByTestID("convert_button").filter(":visible").click(); cy.getByTestID("button_convert_mode_toggle").click(); } +function createDFIWalletWithTokens(): void { + cy.createEmptyWallet(true); + cy.sendDFItoWallet().sendDFITokentoWallet().wait(10000); +} + function validateConvertResult( targetUnit: string, availableAmount: number, - resultingAmount: number + resultingAmount: number, ): void { cy.getByTestID("convert_result_card").should("exist"); cy.getByTestID("convert_available_label").contains(targetUnit); @@ -29,6 +32,19 @@ function validateConvertResult( cy.getByTestID("convert_result_amount").contains(resultingAmount); } +function convertDFIEVMToDVM(): void { + cy.getByTestID("convert_action_button").click(); + cy.getByTestID("DFI (Token)_symbol").click(); + cy.getByTestID("token_select_button_TO").click(); + cy.getByTestID("DFI_name").contains("DeFiChain for EVM").click(); + cy.getByTestID("50%_amount_button").click(); + cy.getByTestID("button_continue_convert").click(); + cy.getByTestID("button_confirm_convert").click(); + cy.closeOceanInterface().wait(5000); + cy.getByTestID("dfi_balance_card").should("exist"); +} + +// Verified context("Wallet - Convert DFI", () => { before(() => { createDFIWallet(); @@ -37,75 +53,76 @@ context("Wallet - Convert DFI", () => { it("should have form validation", () => { cy.getByTestID("button_continue_convert").should( "have.attr", - "aria-disabled" + "aria-disabled", + ); + cy.getByTestID("source_balance").should( + "have.text", + "I HAVE 9.90000000 UTXO", + ); + cy.getByTestID("token_select_button_FROM_display_symbol").should( + "have.text", + "UTXO", ); - cy.getByTestID("source_balance").contains(19.9); - cy.getByTestID("convert_token_button_FROM_display_symbol").contains("UTXO"); - cy.getByTestID("convert_token_button_TO_display_symbol").contains("Token"); + cy.getByTestID("convert_token_button_TO_display_symbol").contains("DFI"); cy.getByTestID("convert_input").type("1"); cy.getByTestID("convert_input").clear(); cy.getByTestID("button_continue_convert").should( "have.attr", - "aria-disabled" + "aria-disabled", ); cy.getByTestID("convert_input").type("1"); - cy.getByTestID("source_balance").contains(19.9); - validateConvertResult("tokens", 1.0, 11); + cy.getByTestID("source_balance").contains(9.9); + validateConvertResult("DFI", 10.0, 11.0); cy.getByTestID("button_continue_convert").should( "not.have.attr", - "disabled" + "disabled", ); }); it("should swap conversion", () => { cy.getByTestID("button_convert_mode_toggle").click().wait(4000); cy.getByTestID("source_balance").contains(10); - cy.getByTestID("convert_token_button_FROM_display_symbol").contains( - "Token" - ); - cy.getByTestID("convert_token_button_TO_display_symbol").contains("UTXO"); + cy.getByTestID("token_select_button_FROM_display_symbol").contains("DFI"); + cy.getByTestID("token_select_button_TO_display_symbol").contains("UTXO"); + cy.getByTestID("convert_input").type("1"); cy.getByTestID("button_continue_convert").should( "not.have.attr", - "disabled" + "disabled", ); }); - it("should test amount buttons when UTXO to account conversion", () => { - cy.getByTestID("button_convert_mode_toggle").click().wait(4000); + it("should test amount buttons when account to UTXO conversion", () => { cy.getByTestID("25%_amount_button").click(); - cy.getByTestID("convert_input").should("have.value", "4.97500000"); - validateConvertResult("tokens", 10.0, 14.975); + cy.getByTestID("convert_input").should("have.value", "2.50000000"); + validateConvertResult("UTXO", 9.9, 12.4); cy.getByTestID("50%_amount_button").click(); - cy.getByTestID("convert_input").should("have.value", "9.95000000"); - validateConvertResult("tokens", 10.0, 19.95); + cy.getByTestID("convert_input").should("have.value", "5.00000000"); + validateConvertResult("UTXO", 9.9, 14.9); cy.getByTestID("75%_amount_button").click(); - cy.getByTestID("convert_input").should("have.value", "14.92500000"); - validateConvertResult("tokens", 10.0, 24.925); + cy.getByTestID("convert_input").should("have.value", "7.50000000"); + validateConvertResult("UTXO", 9.9, 17.4); cy.getByTestID("MAX_amount_button").click(); - cy.getByTestID("convert_input").should("have.value", "19.90000000"); - validateConvertResult("tokens", 10.0, 29.9); - }); - - it("should display info on reserved UTXO when UTXO to account conversion", () => { - cy.getByTestID("source_balance_label").contains( - "A small amount of UTXO is reserved for fees" - ); + cy.getByTestID("convert_input").should("have.value", "10.00000000"); + validateConvertResult("UTXO", 9.9, 19.9); }); - it("should test amount buttons when account to UTXO conversion", () => { + it("should test amount buttons when UTXO to account conversion", () => { cy.getByTestID("button_convert_mode_toggle").click().wait(4000); cy.getByTestID("25%_amount_button").click(); - cy.getByTestID("convert_input").should("have.value", "2.50000000"); - validateConvertResult("UTXO", 20.0, 22.5); + cy.getByTestID("convert_input").should("have.value", "2.47500000"); + validateConvertResult("DFI", 10.0, 12.4); cy.getByTestID("50%_amount_button").click(); - cy.getByTestID("convert_input").should("have.value", "5.00000000"); - validateConvertResult("UTXO", 20.0, 25); + cy.getByTestID("convert_input").should("have.value", "4.95000000"); + validateConvertResult("DFI", 10.0, 14.95); cy.getByTestID("75%_amount_button").click(); - cy.getByTestID("convert_input").should("have.value", "7.50000000"); - validateConvertResult("UTXO", 20.0, 27.5); + cy.getByTestID("convert_input").should("have.value", "7.42500000"); + validateConvertResult("DFI", 10.0, 17.425); cy.getByTestID("MAX_amount_button").click(); - cy.getByTestID("convert_input").should("have.value", "10.00000000"); - validateConvertResult("UTXO", 20.0, 30); + cy.getByTestID("convert_input").should("have.value", "9.90000000"); + validateConvertResult("DFI", 10.0, 19.9); + cy.getByTestID("source_balance_label").contains( + "A small amount of UTXO is reserved for fees", + ); }); it("should test account to UTXO conversion", () => { @@ -113,30 +130,29 @@ context("Wallet - Convert DFI", () => { cy.getByTestID("button_continue_convert").click(); cy.getByTestID("button_confirm_convert").should( "not.have.attr", - "disabled" + "disabled", ); cy.getByTestID("button_cancel_convert").click(); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("convert_button").click(); - cy.getByTestID("convert_input").clear().type("1"); + cy.getByTestID("convert_button").filter(":visible").click(); cy.getByTestID("convert_input").should("exist"); - + cy.getByTestID("convert_input").clear().type("1"); cy.getByTestID("button_continue_convert").click(); cy.getByTestID("confirm_title").contains("You are converting to UTXO"); cy.getByTestID("text_convert_amount").contains("1.00000000"); - cy.getByTestID("resulting_tokens_value").contains("9.00000000"); - cy.getByTestID("resulting_tokens_sub_value").contains("30.00%"); + cy.getByTestID("resulting_tokens_value").contains("8.99"); + cy.getByTestID("resulting_tokens_sub_value").should("exist"); cy.getByTestID("resulting_utxo_value") .invoke("text") .then((text: string) => { - checkValueWithinRange(text.replace(" DFI", ""), "20.99999", 0.1); + checkValueWithinRange(text.replace(" UTXO", ""), "10.89", 0.1); }); - cy.getByTestID("resulting_utxo_sub_value").contains("70.00%"); + cy.getByTestID("resulting_utxo_sub_value").should("exist"); cy.getByTestID("transaction_fee_value").should("exist"); cy.getByTestID("button_cancel_convert").click(); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("convert_button").click(); + cy.getByTestID("convert_button").filter(":visible").click(); }); it("should test UTXO to account conversion", () => { @@ -145,48 +161,49 @@ context("Wallet - Convert DFI", () => { cy.getByTestID("button_continue_convert").click(); cy.getByTestID("button_confirm_convert").should( "not.have.attr", - "disabled" + "disabled", ); cy.getByTestID("button_cancel_convert").click(); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("convert_button").click(); + cy.getByTestID("convert_button").filter(":visible").click(); cy.getByTestID("button_convert_mode_toggle").click().wait(4000); cy.getByTestID("convert_input").clear().type("1"); cy.getByTestID("button_continue_convert").click(); - cy.getByTestID("confirm_title").contains("You are converting to tokens"); + cy.getByTestID("confirm_title").contains("You are converting to DFI"); cy.getByTestID("text_convert_amount").contains("1.00000000"); - cy.getByTestID("resulting_tokens_value").contains("11.00000000"); + cy.getByTestID("resulting_tokens_value").contains("8.90"); cy.getByTestID("resulting_tokens_sub_value") .invoke("text") .then((text) => { - checkValueWithinRange("36.79%", text, 0.1); + checkValueWithinRange("44.72%", text, 0.1); }); cy.getByTestID("resulting_utxo_value") .invoke("text") .then((text: string) => { - checkValueWithinRange(text.replace(" DFI", ""), "18.89999", 0.1); + checkValueWithinRange(text.replace(" DFI", ""), "11.00", 0.1); }); - cy.getByTestID("resulting_utxo_sub_value").contains("63.21%"); + cy.getByTestID("resulting_utxo_sub_value").contains("55.27%"); cy.getByTestID("transaction_fee_value").should("exist"); }); }); +// Verified context("Wallet - Convert UTXO to Account", () => { - it("should test conversion of UTXO to account", () => { + it("should test conversion of UTXO to DFI account from balance screen", () => { createDFIWallet(); cy.getByTestID("convert_input").clear().type("1"); cy.getByTestID("button_continue_convert").click(); cy.getByTestID("button_confirm_convert").click().wait(4000); cy.closeOceanInterface().wait(5000); - cy.getByTestID("dfi_total_balance_amount").contains("29.999"); + cy.getByTestID("dfi_total_balance_amount").contains("19.999"); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("dfi_utxo_amount").contains("18.999"); // 20 - 1 - fee - cy.getByTestID("dfi_token_amount").contains("11"); + cy.getByTestID("dfi_utxo_amount").contains("8.999"); + cy.getByTestID("dfi_token_amount").contains("11.00"); }); - it("should be able to convert correct amount when user cancel a tx and updated some inputs for UTXO to Account conversion", () => { + it("should be able to convert correct amount when user cancel a tx and updated some inputs for UTXO to DFI Account conversion", () => { const oldAmount = "1"; const newAmount = "2"; createDFIWallet(); @@ -195,14 +212,15 @@ context("Wallet - Convert UTXO to Account", () => { cy.getByTestID("button_confirm_convert").click().wait(2000); // Check for authorization page description cy.getByTestID("txn_authorization_title").contains( - `Convert ${new BigNumber(oldAmount).toFixed(8)} DFI to tokens` + `Convert ${new BigNumber(oldAmount).toFixed(8)} UTXO to DFI tokens`, ); // Cancel send on authorisation page cy.getByTestID("cancel_authorization").click(); cy.getByTestID("button_cancel_convert").click(); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("convert_button").click(); + cy.getByTestID("convert_button").filter(":visible").click(); + // Update the input amount cy.getByTestID("button_convert_mode_toggle").click().wait(4000); cy.getByTestID("convert_input").clear().type(newAmount); @@ -210,38 +228,78 @@ context("Wallet - Convert UTXO to Account", () => { // Confirm convert cy.getByTestID("button_confirm_convert").should( "not.have.attr", - "disabled" + "disabled", ); cy.getByTestID("button_confirm_convert").click(); // Check for authorization page description cy.getByTestID("txn_authorization_title").contains( - `Convert ${new BigNumber(newAmount).toFixed(8)} DFI to tokens` + `Convert ${new BigNumber(newAmount).toFixed(8)} UTXO to DFI tokens`, ); cy.closeOceanInterface().wait(5000); - - cy.getByTestID("dfi_total_balance_amount").contains("29.999"); + cy.getByTestID("dfi_total_balance_amount").contains("19.999"); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("dfi_utxo_amount").contains("17.999"); // 20 - 2 - fee + cy.getByTestID("dfi_utxo_amount").contains("7.999"); // 20 - 2 - fee cy.getByTestID("dfi_token_amount").contains("12"); }); + + it("should test conversion of account UTXO to DFI From Quicklinks", () => { + createDFIWalletWithTokens(); + cy.getByTestID("convert_action_button").should("exist").click(); + cy.getByTestID("select_DFI (UTXO)").click(); + cy.getByTestID("convert_token_button_TO_display_symbol").should( + "have.text", + "DFI", + ); + cy.getByTestID("convert_input").clear().type("1"); + cy.getByTestID("convert_available_label").contains("Available DFI"); + cy.getByTestID("convert_resulting_label").contains("Resulting DFI"); + cy.getByTestID("convert_available_amount").contains("10.00000000"); + cy.getByTestID("convert_result_amount").contains("11.00000000"); + cy.getByTestID("button_continue_convert").click(); + cy.getByTestID("confirm_title").should( + "have.text", + "You are converting to DFI", + ); + cy.getByTestID("text_convert_amount").contains("1.00000000"); + cy.getByTestID("wallet_address").should("exist"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("resulting_tokens_value").should( + "have.text", + "8.90000000 UTXO", + ); // to uncomment after fix for bug DFC-324 + cy.getByTestID("resulting_utxo_value").should( + "have.text", + "11.00000000 DFI", + ); + cy.getByTestID("button_confirm_convert").click().wait(4000); + + cy.getByTestID("txn_authorization_title").contains( + `Convert ${new BigNumber(1).toFixed(8)} UTXO to DFI tokens`, + ); + cy.closeOceanInterface().wait(5000); + cy.getByTestID("dfi_total_balance_amount").contains("19.999"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("dfi_utxo_amount").contains("8.999"); + cy.getByTestID("dfi_token_amount").should("have.text", "11.00000000 DFI"); + }); }); +// Verified context("Wallet - Convert Account to UTXO", () => { - it("should test conversion of account to UTXO", () => { + it("should test conversion of account to UTXO From Balance screen", () => { createDFIWallet(); cy.getByTestID("button_convert_mode_toggle").click().wait(4000); cy.getByTestID("convert_input").clear().type("1"); cy.getByTestID("button_continue_convert").click(); cy.getByTestID("button_confirm_convert").click().wait(4000); cy.closeOceanInterface().wait(5000); - - cy.getByTestID("dfi_total_balance_amount").contains("29.999"); + cy.getByTestID("dfi_total_balance_amount").contains("19.999"); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("dfi_utxo_amount").contains("20.999"); - cy.getByTestID("dfi_token_amount").contains("9"); + cy.getByTestID("dfi_utxo_amount").contains("10.999"); + cy.getByTestID("dfi_token_amount").should("have.text", "9.00000000 DFI"); }); - it("should be able to convert correct amount when user cancel a tx and updated some inputs for Account to UTXO conversion", () => { + it("should be able to convert correct amount when user cancel a tx and updated some inputs for Account DFI to UTXO conversion", () => { const oldAmount = "1"; const newAmount = "2"; createDFIWallet(); @@ -250,43 +308,465 @@ context("Wallet - Convert Account to UTXO", () => { cy.getByTestID("button_continue_convert").click(); cy.getByTestID("button_confirm_convert").should( "not.have.attr", - "disabled" + "disabled", ); cy.getByTestID("button_cancel_convert").click(); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("convert_button").click(); + cy.getByTestID("convert_button").filter(":visible").click(); cy.getByTestID("convert_input").clear().type(oldAmount); cy.getByTestID("button_continue_convert").click(); cy.getByTestID("button_confirm_convert").click().wait(2000); // Check for authorization page description - cy.getByTestID("txn_authorization_title").contains( - `Convert ${new BigNumber(oldAmount).toFixed(8)} DFI to UTXO` + cy.getByTestID("txn_authorization_title").should( + "have.text", + `Convert ${new BigNumber(oldAmount).toFixed(8)} DFI to UTXO tokens`, ); // Cancel send on authorisation page cy.getByTestID("cancel_authorization").click(); cy.getByTestID("button_cancel_convert").click(); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("convert_button").click(); + cy.getByTestID("convert_button").filter(":visible").click(); // Update the input amount cy.getByTestID("convert_input").clear().type(newAmount); cy.getByTestID("button_continue_convert").click(); // Confirm convert cy.getByTestID("button_confirm_convert").should( "not.have.attr", - "disabled" + "disabled", ); cy.getByTestID("button_confirm_convert").click(); // Check for authorization page description + cy.getByTestID("txn_authorization_title").should( + "have.text", + `Convert ${new BigNumber(newAmount).toFixed(8)} DFI to UTXO tokens`, + ); + cy.closeOceanInterface().wait(5000); + cy.getByTestID("dfi_total_balance_amount").contains("19.999"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("dfi_utxo_amount").contains("11.999"); // 20 + 2 - fee + cy.getByTestID("dfi_token_amount").should("have.text", "8.00000000 DFI"); + }); + + it("should test conversion of account DFI to UTXO From Quicklinks", () => { + createDFIWalletWithTokens(); + cy.getByTestID("convert_action_button").should("exist").click(); + cy.getByTestID("select_DFI (Token)").click(); + cy.getByTestID("token_select_button_TO").click(); + cy.getByTestID("select_DFI (UTXO)").click(); + cy.getByTestID("convert_input").clear().type("1"); + cy.getByTestID("convert_available_label").contains("Available UTXO"); + cy.getByTestID("convert_resulting_label").contains("Resulting UTXO"); + cy.getByTestID("convert_available_amount").contains("9.90000000"); + cy.getByTestID("convert_result_amount").contains("10.90000000"); + cy.getByTestID("button_continue_convert").click(); + cy.getByTestID("confirm_title").should( + "have.text", + "You are converting to UTXO", + ); + cy.getByTestID("text_convert_amount").contains("1.00000000"); + cy.getByTestID("wallet_address").should("exist"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("resulting_tokens_value") + .should("contain", "8.99") + .and("contain", "DFI"); + cy.getByTestID("resulting_utxo_value").contains("10.89"); + cy.getByTestID("button_confirm_convert").click().wait(4000); + + cy.getByTestID("txn_authorization_title").should( + "have.text", + `Convert ${new BigNumber(1).toFixed(8)} DFI to UTXO tokens`, + ); + cy.closeOceanInterface().wait(5000); + cy.getByTestID("dfi_total_balance_amount").contains("19.999"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("dfi_utxo_amount").contains("10.999"); + cy.getByTestID("dfi_token_amount").should("have.text", "9.00000000 DFI"); + }); +}); + +// Verified +context("Wallet - Convert DFI Convert Quick links", () => { + before(() => { + createDFIWalletWithTokens(); + convertDFIEVMToDVM(); + }); + + it("should have form validation using convert Quicklink DFI DVM to EVM", () => { + cy.getByTestID("domain_switch_DVM").should("exist"); + cy.getByTestID("convert_action_button").should("exist").click(); + cy.getByTestID("search_input").clear().type("DFI"); + cy.getByTestID("DFI (Token)_symbol").click(); + cy.getByTestID("button_continue_convert").should( + "have.attr", + "aria-disabled", + ); + cy.getByTestID("source_balance").should( + "have.text", + "I HAVE 5.00000000 DFI", + ); + cy.getByTestID("token_select_button_FROM_display_symbol").should( + "have.text", + "DFI", + ); + cy.getByTestID("token_select_button_TO").contains("Token"); + cy.getByTestID("token_select_button_TO").click(); + cy.getByTestID("search_input").clear().type("DFI"); + cy.getByTestID("DFI_name").contains("DeFiChain for EVM").click(); + cy.getByTestID("token_select_button_TO_display_symbol").contains("DFI"); + cy.getByTestID("token_select_button_TO") + .children() + .first() + .should("have.attr", "style") + .and("include", "linear-gradient"); + cy.getByTestID("convert_input").type("1").clear(); + cy.getByTestID("button_continue_convert").should( + "have.attr", + "aria-disabled", + ); + cy.getByTestID("convert_input").type("1"); + validateConvertResult("DFI (EVM)", 5.0, 6.0); + cy.getByTestID("button_continue_convert").should( + "not.have.attr", + "disabled", + ); + }); + + it("should test amount buttons when DFI DVM to EVM conversion", () => { + cy.getByTestID("25%_amount_button").click(); + cy.getByTestID("convert_input").should("have.value", "1.25000000"); + validateConvertResult("DFI", 5.0, 6.25); + cy.getByTestID("50%_amount_button").click(); + cy.getByTestID("convert_input").should("have.value", "2.50000000"); + validateConvertResult("DFI", 5.0, 7.5); + cy.getByTestID("75%_amount_button").click(); + cy.getByTestID("convert_input").should("have.value", "3.75000000"); + validateConvertResult("DFI", 5.0, 8.75); + cy.getByTestID("MAX_amount_button").click(); + cy.getByTestID("convert_input").should("have.value", "5.00000000"); + validateConvertResult("DFI", 5.0, 10.0); + }); + + it("should swap conversion DFI EVM to DVM", () => { + cy.getByTestID("button_convert_mode_toggle").click().wait(4000); + cy.getByTestID("source_balance").should( + "have.text", + "I HAVE 5.00000000 DFI (EVM)", + ); + cy.getByTestID("token_select_button_FROM_display_symbol").should( + "have.text", + "DFI", + ); + cy.getByTestID("token_select_button_FROM") + .children() + .first() + .should("have.attr", "style") + .and("include", "linear-gradient"); + cy.getByTestID("convert_token_button_TO_display_symbol").should( + "have.text", + "DFI", + ); + cy.getByTestID("button_continue_convert").should( + "not.have.attr", + "disabled", + ); + }); + + it("should have form validation using convert Quicklink DFI EVM to DVM", () => { + cy.getByTestID("bottom_tab_portfolio").click(); + cy.getByTestID("domain_switch_DVM").should("exist").click(); + cy.getByTestID("convert_action_button").click(); + cy.getByTestID("search_input").clear().type("DFI"); + cy.getByTestID("select_DFI").click(); + cy.getByTestID("button_continue_convert").should( + "have.attr", + "aria-disabled", + ); + cy.getByTestID("source_balance").should( + "have.text", + "I HAVE 5.00000000 DFI (EVM)", + ); + cy.getByTestID("token_select_button_FROM_display_symbol").should( + "have.text", + "DFI", + ); + cy.getByTestID("convert_token_button_TO_display_symbol").contains("DFI"); + cy.getByTestID("token_select_button_FROM") + .children() + .first() + .should("have.attr", "style") + .and("include", "linear-gradient"); + cy.getByTestID("convert_input").type("1").clear(); + cy.getByTestID("button_continue_convert").should( + "have.attr", + "aria-disabled", + ); + cy.getByTestID("convert_input").type("1"); + validateConvertResult("DFI", 5.0, 6.0); + cy.getByTestID("button_continue_convert").should( + "not.have.attr", + "disabled", + ); + }); + + it("should test amount buttons when DFI EVM to DVM conversion", () => { + cy.getByTestID("25%_amount_button").click(); + cy.getByTestID("convert_input").should("have.value", "1.25000000"); + validateConvertResult("DFI", 5.0, 6.25); + cy.getByTestID("50%_amount_button").click(); + cy.getByTestID("convert_input").should("have.value", "2.50000000"); + validateConvertResult("DFI", 5.0, 7.5); + cy.getByTestID("75%_amount_button").click(); + cy.getByTestID("convert_input").should("have.value", "3.75000000"); + validateConvertResult("DFI", 5.0, 8.75); + cy.getByTestID("MAX_amount_button").click(); + cy.getByTestID("convert_input").should("have.value", "5.00000000"); + validateConvertResult("DFI", 5.0, 10.0); + }); + + it("should swap conversion DFI EVM to DVM", () => { + cy.getByTestID("button_convert_mode_toggle").click().wait(4000); + cy.getByTestID("source_balance").should( + "have.text", + "I HAVE 5.00000000 DFI", + ); + cy.getByTestID("token_select_button_FROM_display_symbol").should( + "have.text", + "DFI", + ); + cy.getByTestID("token_select_button_TO_display_symbol").should( + "have.text", + "DFI", + ); + cy.getByTestID("convert_input").clear().type("1"); + cy.getByTestID("button_continue_convert").should( + "not.have.attr", + "disabled", + ); + }); +}); + +context("Wallet - Convert tokens EVM <> DVM", () => { + it("should convert DFI DVM - EVM via Quick Links in DVM Network", () => { + createDFIWalletWithTokens(); + cy.getByTestID("domain_switch_DVM").should("exist"); + cy.getByTestID("convert_action_button").should("exist").click(); + cy.getByTestID("search_input").clear().type("DFI"); + cy.getByTestID("DFI (Token)_symbol").click(); + cy.getByTestID("token_select_button_TO").click(); + cy.getByTestID("search_input").clear().type("DFI"); + cy.getByTestID("DFI_name").contains("DeFiChain for EVM").click(); + cy.getByTestID("source_balance").contains(10); + cy.getByTestID("convert_available_label").contains("Available DFI (EVM)"); + cy.getByTestID("convert_resulting_label").contains("Resulting DFI (EVM)"); + cy.getByTestID("convert_available_amount").contains("0.00000000"); // to update the value + cy.getByTestID("convert_result_amount").contains("-"); + cy.getByTestID("convert_input").clear().type("1"); + validateConvertResult("DFI", 0.0, 1.0); + cy.getByTestID("button_continue_convert").click(); + cy.getByTestID("confirm_title").should( + "have.text", + "You are converting to DFI (EVM)", + ); + cy.getByTestID("text_convert_amount").should("have.text", "1.00000000"); + cy.getByTestID("wallet_address").should("exist"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("resulting_tokens_value").should( + "have.text", + "9.00000000 DFI", + ); + cy.getByTestID("resulting_utxo_value").should( + "have.text", + "1.00000000 DFI (EVM)", + ); + cy.getByTestID("button_confirm_convert").click(); + cy.getByTestID("txn_authorization_title").should( + "have.text", + `Convert ${new BigNumber(1).toFixed(8)} DFI to DFI (EVM) tokens`, + ); + cy.closeOceanInterface().wait(5000); + + cy.getByTestID("dfi_total_balance_amount").contains("18.99"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("dfi_utxo_amount").contains("9.99"); + cy.getByTestID("dfi_token_amount").contains("9.00"); + cy.go("back"); + cy.getByTestID("domain_switch_DVM").click(); + cy.getByTestID("dfi_total_balance_amount").contains("1.00000000"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + + cy.getByTestID("token_detail_amount").contains("1.00000000"); + }); + + it("should convert DFI EVM - DVM via Quick Links in EVM Network", () => { + createDFIWalletWithTokens(); + convertDFIEVMToDVM(); + cy.getByTestID("domain_switch_DVM").should("exist"); + cy.getByTestID("domain_switch_DVM").click(); + cy.getByTestID("convert_action_button").should("exist").click(); + cy.getByTestID("search_input").clear().type("DFI"); + cy.getByTestID("select_DFI").contains("DeFiChain for EVM").click(); + cy.getByTestID("token_select_button_FROM") + .children() + .first() + .should("have.attr", "style") + .and("include", "linear-gradient"); + cy.getByTestID("token_select_button_FROM_display_symbol").contains("DFI"); + cy.getByTestID("convert_token_button_TO_display_symbol").contains("DFI"); + cy.getByTestID("source_balance").contains("I HAVE 5.00000000 DFI (EVM)"); + cy.getByTestID("convert_available_label").contains("Available DFI"); + cy.getByTestID("convert_resulting_label").contains("Resulting DFI"); + cy.getByTestID("convert_available_amount").contains("5.00000000"); + cy.getByTestID("convert_result_amount").contains("-"); + cy.getByTestID("convert_input").clear().type("1"); + validateConvertResult("DFI", 5.0, 6.0); + cy.getByTestID("button_continue_convert").click(); + cy.getByTestID("confirm_title").should( + "have.text", + "You are converting to DFI", + ); + cy.getByTestID("text_convert_amount").should("have.text", "1.00000000"); + cy.getByTestID("wallet_address").should("exist"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("resulting_tokens_value").should( + "have.text", + "4.00000000 DFI (EVM)", + ); + cy.getByTestID("resulting_utxo_value").should( + "have.text", + "6.00000000 DFI", + ); + cy.getByTestID("button_confirm_convert").click(); + cy.getByTestID("txn_authorization_title").should( + "have.text", + `Convert ${new BigNumber(1).toFixed(8)} DFI (EVM) to DFI tokens`, + ); + cy.closeOceanInterface().wait(5000); + cy.getByTestID("dfi_total_balance_amount").contains("4.000"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("token_detail_amount").should("have.text", "4.00000000"); + + cy.go("back"); + cy.getByTestID("domain_switch_EVM").click(); + cy.getByTestID("dfi_total_balance_amount").contains("15.99"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("token_detail_amount").contains("15.99"); + cy.getByTestID("dfi_utxo_amount") + .should("contain", "9.99") + .and("contain", "DFI"); + cy.getByTestID("dfi_token_amount").should("have.text", "6.00000000 DFI"); + }); + + it("should convert DFI DVM - EVM via Balance in DVM Network", () => { + createDFIWallet(); + cy.getByTestID("button_convert_mode_toggle").click(); + cy.getByTestID("token_select_button_TO").click(); + cy.getByTestID("DFI_name").contains("DeFiChain for EVM").click(); + cy.getByTestID("token_select_button_TO") + .filter(":visible") + .children() + .first() + .should("have.attr", "style") + .and("include", "linear-gradient"); + cy.getByTestID("source_balance").contains(10); + cy.getByTestID("token_select_button_FROM_display_symbol").contains("DFI"); + cy.getByTestID("token_select_button_TO_display_symbol").contains("DFI"); + cy.getByTestID("convert_available_label").contains("Available DFI (EVM)"); + cy.getByTestID("convert_resulting_label").contains("Resulting DFI (EVM)"); + cy.getByTestID("convert_available_amount").contains("0.00000000"); + cy.getByTestID("convert_result_amount").contains("-"); + cy.getByTestID("convert_input") + .filter(":visible") + .clear() + .type("0.00000009"); + cy.getByTestID("convert_available_label").contains("Available DFI (EVM)"); + cy.getByTestID("convert_resulting_label").contains("Resulting DFI (EVM)"); + cy.getByTestID("convert_available_amount") + .filter(":visible") + .should("have.text", "0.00000000"); + cy.getByTestID("convert_result_amount") + .filter(":visible") + .should("have.text", "0.00000009"); + cy.getByTestID("button_continue_convert").eq(1).click(); + cy.getByTestID("confirm_title").contains("You are converting to DFI (EVM)"); + cy.getByTestID("text_convert_amount").contains("0.00000009"); + cy.getByTestID("wallet_address").should("exist"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("resulting_tokens_value").contains("9.99999991 DFI"); + cy.getByTestID("resulting_utxo_value").contains("0.00000009 DFI (EVM)"); + cy.getByTestID("button_confirm_convert").click(); cy.getByTestID("txn_authorization_title").contains( - `Convert ${new BigNumber(newAmount).toFixed(8)} DFI to UTXO` + `Convert ${new BigNumber(0.00000009).toFixed(8)} DFI to DFI (EVM)`, ); cy.closeOceanInterface().wait(5000); + cy.getByTestID("dfi_total_balance_amount").contains("19.99"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("token_detail_amount").contains("19.99"); + cy.getByTestID("dfi_utxo_amount") + .should("contain", "9.99") + .and("contain", "DFI"); + cy.getByTestID("dfi_token_amount") + .should("contain", "9.99") + .and("contain", "DFI"); + cy.go("back"); + cy.getByTestID("domain_switch_DVM").click(); + cy.getByTestID("dfi_total_balance_amount").contains("0.00000009"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("token_detail_amount").should("have.text", "0.00000009"); + }); + + it("should convert DFI EVM - DVM via Balance in EVM Network", () => { + createDFIWalletWithTokens(); + convertDFIEVMToDVM(); + cy.getByTestID("domain_switch_DVM").should("exist").click(); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("convert_button").should("exist").click(); + cy.getByTestID("token_select_button_FROM") + .children() + .first() + .should("have.attr", "style") + .and("include", "linear-gradient"); + cy.getByTestID("token_select_button_FROM_display_symbol").contains("DFI"); + cy.getByTestID("convert_token_button_TO_display_symbol").contains("DFI"); + cy.getByTestID("source_balance").contains("I HAVE 5.00000000 DFI (EVM)"); + cy.getByTestID("convert_available_label").contains("Available DFI"); + cy.getByTestID("convert_resulting_label").contains("Resulting DFI"); + cy.getByTestID("convert_available_amount").contains("5.00000000"); + cy.getByTestID("convert_result_amount").contains("-"); + cy.getByTestID("convert_input").clear().type("1.12345678"); + validateConvertResult("DFI", 5.0, 6.12345678); + cy.getByTestID("button_continue_convert").click(); + cy.getByTestID("confirm_title").should( + "have.text", + "You are converting to DFI", + ); + cy.getByTestID("text_convert_amount").should("have.text", "1.12345678"); + cy.getByTestID("wallet_address").should("exist"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("resulting_tokens_value").contains("3.87"); + cy.getByTestID("resulting_utxo_value").should( + "have.text", + "6.12345678 DFI", + ); + cy.getByTestID("button_confirm_convert").click(); + cy.getByTestID("txn_authorization_title").should( + "have.text", + `Convert ${new BigNumber(1.12345678).toFixed(8)} DFI (EVM) to DFI tokens`, + ); + cy.closeOceanInterface().wait(5000); + cy.getByTestID("dfi_total_balance_amount").contains("3.87"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("token_detail_amount").should("have.text", "3.87654322"); - cy.getByTestID("dfi_total_balance_amount").contains("29.999"); + cy.go("back"); + cy.getByTestID("domain_switch_EVM").click(); + cy.getByTestID("dfi_total_balance_amount").contains("16.123"); cy.getByTestID("dfi_balance_card").should("exist").click(); - cy.getByTestID("dfi_utxo_amount").contains("21.999"); // 20 + 2 - fee - cy.getByTestID("dfi_token_amount").contains("8"); + cy.getByTestID("token_detail_amount").contains("16.123"); + cy.getByTestID("dfi_utxo_amount") + .should("contain", "9.99") + .and("contain", "DFI"); + cy.getByTestID("dfi_token_amount").should("have.text", "6.12345678 DFI"); }); }); diff --git a/mobile-app/cypress/e2e/functional/wallet/portfolio/receive.spec.ts b/mobile-app/cypress/e2e/functional/wallet/portfolio/receive.spec.ts index ff1ca4ad43..8225e22945 100644 --- a/mobile-app/cypress/e2e/functional/wallet/portfolio/receive.spec.ts +++ b/mobile-app/cypress/e2e/functional/wallet/portfolio/receive.spec.ts @@ -10,6 +10,19 @@ context("Wallet - Receive", () => { cy.getByTestID("receive_balance_button").click(); }); + it("should copy DVM address to clipboard when copy is clicked", () => { + cy.getByTestID("address_text").then(($txt: any) => { + const address = $txt[0].textContent; + cy.getByTestID("copy_button").should("exist").click(); + cy.window().then((win) => { + win.navigator.clipboard.readText().then((text) => { + cy.log(`From clipboard: ${text}`); + expect(text).to.eq(address); + }); + }); + }); + }); + it("should get address value and validate", () => { cy.getByTestID("qr_code_container").should("exist"); cy.getByTestID("copy_button").should("exist"); @@ -24,7 +37,49 @@ context("Wallet - Receive", () => { cy.getByTestID("address_input").type(address); cy.getByTestID("button_confirm_send_continue").should( "not.have.attr", - "disabled" + "disabled", + ); + }); + }); +}); + +context("Wallet - EVM Receive", () => { + it("should display valid address when clicked", () => { + cy.getByTestID("bottom_tab_portfolio").click(); + cy.getByTestID("domain_switch").click(); + cy.getByTestID("receive_balance_button").click(); + cy.getByTestID("qr_code_container").should("exist"); + cy.getByTestID("address_text").should("exist"); + cy.getByTestID("copy_button").should("exist"); + cy.getByTestID("share_button").should("exist"); + }); + + it("should copy EVM address to clipboard when copy is clicked", () => { + cy.getByTestID("address_text").then(($txt: any) => { + const address = $txt[0].textContent; + cy.getByTestID("copy_button").should("exist").click(); + cy.window().then((win) => { + win.navigator.clipboard.readText().then((text) => { + cy.log(`From clipboard: ${text}`); + expect(text).to.eq(address); + }); + }); + }); + }); + + it("should get address value and validate", () => { + cy.getByTestID("address_text").then(($txt: any) => { + const address = $txt[0].textContent; + cy.go("back"); + cy.getByTestID("domain_switch").click(); + cy.getByTestID("dfi_total_balance_amount").contains("10.00000000"); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("send_button").click(); + cy.getByTestID("amount_input").clear().type("1"); + cy.getByTestID("address_input").type(address); + cy.getByTestID("button_confirm_send_continue").should( + "not.have.attr", + "disabled", ); }); }); diff --git a/mobile-app/cypress/e2e/functional/wallet/portfolio/send.spec.ts b/mobile-app/cypress/e2e/functional/wallet/portfolio/send.spec.ts index cfaffcf72b..f28c1d45da 100644 --- a/mobile-app/cypress/e2e/functional/wallet/portfolio/send.spec.ts +++ b/mobile-app/cypress/e2e/functional/wallet/portfolio/send.spec.ts @@ -834,7 +834,7 @@ context("Wallet - Send - Address book", () => { }); }); -context.only("(dvm -> dvm) Wallet - Send - Address book", () => { +context("(dvm -> dvm) Wallet - Send - Address book", () => { before(() => { cy.createEmptyWallet(true); cy.sendDFItoWallet().sendDFITokentoWallet().wait(6000); @@ -918,7 +918,7 @@ context.only("(dvm -> dvm) Wallet - Send - Address book", () => { ); }); - it.only("should display evm tag when EVM address is selected in DVM domain", () => { + it("should display evm tag when EVM address is selected in DVM domain", () => { populateAddressBook(); cy.getByTestID("address_row_text_1_WHITELISTED").click(); @@ -930,6 +930,32 @@ context.only("(dvm -> dvm) Wallet - Send - Address book", () => { // expect to see evm tag in confirm screen cy.getByTestID("to_address_label_evm_tag").should("exist"); + cy.go("back"); + }); + + it("should not allow to send tokens from EVM to other EVM address", () => { + cy.getByTestID("bottom_tab_portfolio").click(); + cy.getByTestID("convert_action_button").click(); + cy.getByTestID("DFI (Token)_symbol").click(); + cy.getByTestID("token_select_button_TO").click(); + cy.getByTestID("DFI_name").contains("DeFiChain for EVM").click(); + cy.getByTestID("50%_amount_button").click(); + cy.getByTestID("button_continue_convert").click(); + cy.getByTestID("button_confirm_convert").click(); + cy.closeOceanInterface().wait(5000); + cy.getByTestID("domain_switch").click(); // Switch to EVM domain + cy.getByTestID("dfi_balance_card").should("exist"); + cy.getByTestID("send_balance_button").click().wait(3000); + cy.getByTestID("select_DFI").click().wait(3000); + cy.getByTestID("address_book_button").click(); + cy.getByTestID("address_row_0_WHITELISTED").should( + "have.attr", + "aria-disabled", + ); + cy.getByTestID("address_row_label_0_WHITELISTED_EVM_tag").should( + "have.text", + "EVM", + ); }); }); @@ -1031,3 +1057,282 @@ context("(evm -> dvm) Wallet - Send - Address book", () => { ); }); }); + +context("(evm <> dvm) Wallet - Send", () => { + const addresses: string[] = []; // Index 0 - DVM address, 1 -> EVM address + const evmAddress = "0xD8A1D481418E77552DB93aA274cc31982df857a1"; + const dvmAddress = "bcrt1qjp6yvseq9vdn3y9ram4ltkq48j02r99h3ujatg"; + let dvmbalance: string; + let evmbalance: string; + + before(() => { + cy.createEmptyWallet(true); + cy.sendDFItoWallet().sendDFITokentoWallet().wait(10000); + for (let i = 0; i < 2; i++) { + cy.getByTestID("wallet_address").click(); + cy.getByTestID("address_row_text_0") + .invoke("text") + .then((address: string) => { + addresses.push(address); + }); + cy.getByTestID("close_bottom_sheet_button").click(); + cy.getByTestID("domain_switch").click().wait(3000); + } + }); + + beforeEach(() => { + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("dfi_total_balance_amount") + .invoke("text") + .then((bal: string) => { + dvmbalance = bal; + }); + + cy.getByTestID("domain_switch").click(); + cy.getByTestID("dfi_total_balance_amount") + .invoke("text") + .then((bal: string) => { + evmbalance = bal; + }); + cy.getByTestID("domain_switch").click(); + }); + + it("should be able to send from DVM address to own EVM address", () => { + const amt = 5; + cy.getByTestID("send_balance_button").click().wait(3000); + cy.getByTestID("select_DFI").click().wait(3000); + cy.getByTestID("address_input").clear().type(addresses[1]); + cy.getByTestID("address_input_footer_evm").contains("Address 1"); + cy.getByTestID("amount_input").clear().type(amt.toString()); + cy.getByTestID("button_confirm_send_continue").should( + "not.have.attr", + "disabled", + ); + cy.getByTestID("button_confirm_send_continue").click(); + cy.getByTestID("confirm_title").contains("You are sending"); + cy.getByTestID("wallet_address").contains(addresses[0]); + cy.getByTestID("address_input_footer_evm").contains("Address 1"); + cy.getByTestID("to_address_label_evm_tag") + .should("have.attr", "style") + .and("include", "linear-gradient"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("text_amount").should("have.text", `${amt.toFixed(8)} DFI`); + cy.getByTestID("button_confirm_send").click(); + cy.getByTestID("txn_authorization_title").contains( + `Sending ${new BigNumber(amt).toFixed(8)} DFI to ${addresses[1]}`, + ); + + cy.closeOceanInterface().wait(3000); + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("dfi_total_balance_amount").contains( + Number(dvmbalance) - (amt + 0.01), + ); // $14.99 + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("dfi_utxo_amount").contains("9.99"); + cy.getByTestID("dfi_token_amount").contains("5.0000"); + cy.go("back"); + cy.getByTestID("domain_switch").click(); + cy.getByTestID("dfi_total_balance_amount").contains(amt.toFixed(8)); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.go("back"); + cy.getByTestID("domain_switch").click(); + }); + + // Execute along with previous test case (precondition) + it("should be able to send from EVM address to own DVM address", () => { + const amt = 1; + cy.getByTestID("domain_switch").click(); + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("send_balance_button").click().wait(3000); + cy.getByTestID("select_DFI").click().wait(3000); + cy.getByTestID("address_input").clear().type(addresses[0]); + cy.getByTestID("address_input_footer").contains("Address 1"); + cy.getByTestID("amount_input").clear().type(amt.toString()); + cy.getByTestID("button_confirm_send_continue").should( + "not.have.attr", + "disabled", + ); + cy.getByTestID("button_confirm_send_continue").click(); + cy.getByTestID("confirm_title").contains("You are sending"); + cy.getByTestID("wallet_address").contains(addresses[1]); + cy.getByTestID("address_input_footer").contains("Address 1"); + // Bug https://linear.app/birthdayresearch/issue/DFC-329/transfer-domain-linear-gradient-is-not-displayed-for-evm-dfi + // cy.getByTestID("to_address_label_evm_tag") + // .should("have.attr", "style") + // .and("include", "linear-gradient"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("text_amount").should("have.text", `${amt.toFixed(8)} DFI`); + cy.getByTestID("button_confirm_send").click(); + cy.getByTestID("txn_authorization_title").contains( + `Sending ${new BigNumber(amt).toFixed(8)} DFI (EVM) to ${addresses[0]}`, + ); + + cy.closeOceanInterface().wait(3000); + cy.getByTestID("portfolio_list").should("exist"); + const evmAmt = (Number(evmbalance) - amt).toFixed(8); + cy.getByTestID("dfi_total_balance_amount").contains(evmAmt); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("token_detail_amount").contains(evmAmt); + cy.go("back"); + cy.getByTestID("domain_switch").click(); + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("dfi_total_balance_amount").contains( + Math.trunc(Number(dvmbalance) * 100) / 100 + amt, + ); // get fixed 2 decimals without rounding + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("dfi_utxo_amount").contains("9.99"); + cy.getByTestID("dfi_token_amount").contains("6.0000"); + cy.go("back"); + }); + + // Execute in sequence + it("should be able to send tokens from DVM to other EVM address", () => { + const amt = 1; + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("send_balance_button").click().wait(3000); + cy.getByTestID("select_DFI").click().wait(3000); + cy.getByTestID("address_input").clear().type(evmAddress); + cy.getByTestID("verified_address").should( + "have.text", + "Verified MetaChain (EVM) address", + ); + cy.getByTestID("amount_input").clear().type(amt.toString()); + cy.getByTestID("button_confirm_send_continue").should( + "not.have.attr", + "disabled", + ); + cy.getByTestID("button_confirm_send_continue").click(); + cy.getByTestID("confirm_title").contains("You are sending"); + cy.getByTestID("wallet_address").contains(addresses[0]); + cy.getByTestID("address_input_footer_evm").contains(evmAddress); + cy.getByTestID("to_address_label_evm_tag") + .should("have.attr", "style") + .and("include", "linear-gradient"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("text_amount").should("have.text", `${amt.toFixed(8)} DFI`); + cy.getByTestID("button_confirm_send").click(); + cy.getByTestID("txn_authorization_title").contains( + `Sending ${new BigNumber(amt).toFixed(8)} DFI to ${evmAddress}`, + ); + + cy.closeOceanInterface().wait(3000); + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("dfi_total_balance_amount").contains( + Math.trunc(Number(dvmbalance) * 100) / 100 - amt, + ); // get fixed 2 decimals without rounding + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("dfi_utxo_amount").contains("9.99"); + cy.getByTestID("dfi_token_amount").contains("5.00"); + cy.go("back"); + }); + + it("should be able to send tokens from EVM to other DVM address", () => { + const amt = 1.01234567; + cy.getByTestID("domain_switch").click(); + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("send_balance_button").click().wait(3000); + cy.getByTestID("select_DFI").click().wait(3000); + cy.getByTestID("address_input").clear().type(dvmAddress); + // Uncomment after Bug Fix for DFC-380 + // cy.getByTestID("verified_address").should("have.text", "Verified Defichain (DVM) address"); + cy.getByTestID("amount_input").clear().type(amt.toString()); + cy.getByTestID("button_confirm_send_continue").should( + "not.have.attr", + "disabled", + ); + cy.getByTestID("button_confirm_send_continue").click(); + cy.getByTestID("confirm_title").contains("You are sending"); + cy.getByTestID("wallet_address").contains(addresses[1]); + // uncomment after bug fix + // cy.getByTestID("to_address_label_evm_tag") + // .should("have.attr", "style") + // .and("include", "linear-gradient"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("text_amount").should("have.text", `${amt.toFixed(8)} DFI`); + cy.getByTestID("button_confirm_send").click(); + cy.getByTestID("txn_authorization_title").contains( + `Sending ${new BigNumber(amt).toFixed(8)} DFI (EVM) to ${dvmAddress}`, + ); + + cy.closeOceanInterface().wait(3000); + cy.getByTestID("portfolio_list").should("exist"); + const evmAmt = Math.trunc(Number(evmbalance) * 100) / 100 - amt; + cy.getByTestID("dfi_total_balance_amount").contains(evmAmt); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("token_detail_amount").contains(evmAmt); + cy.go("back"); + cy.getByTestID("domain_switch").click(); + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("dfi_total_balance_amount").contains( + Math.trunc(Number(dvmbalance) * 100) / 100, + ); + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("dfi_utxo_amount").contains("9.99"); + cy.getByTestID("dfi_token_amount").contains("5.0000"); + cy.go("back"); + }); + + it("should be able to convert tokens before sending from DVM to other EVM address", () => { + const amt = 6; + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("send_balance_button").click().wait(3000); + cy.getByTestID("select_DFI").click().wait(3000); + cy.getByTestID("address_input").clear().type(evmAddress); + cy.getByTestID("verified_address").should( + "have.text", + "Verified MetaChain (EVM) address", + ); + cy.getByTestID("amount_input").clear().type(amt.toString()); + cy.getByTestID("button_confirm_send_continue").should( + "not.have.attr", + "disabled", + ); + cy.getByTestID("button_confirm_send_continue").click(); + cy.getByTestID("txn_authorization_title").contains( + `Convert ${new BigNumber(1).toFixed(8)} UTXO to DFI tokens`, + ); + cy.closeOceanInterface().wait(3000); + cy.getByTestID("confirm_title").contains("You are sending"); + cy.getByTestID("text_send_amount").should( + "have.text", + new BigNumber(amt).toFixed(8), + ); + cy.getByTestID("wallet_address").contains(addresses[0]); + cy.getByTestID("address_input_footer_evm").contains(evmAddress); + cy.getByTestID("to_address_label_evm_tag") + .should("have.attr", "style") + .and("include", "linear-gradient"); + cy.getByTestID("amount_to_convert_value").should( + "have.text", + "1.00000000 DFI", + ); + cy.getByTestID("conversion_status").should("have.text", "Converted"); + cy.getByTestID("transaction_fee_value").should("exist"); + cy.getByTestID("text_amount").should("have.text", `${amt.toFixed(8)} DFI`); + cy.getByTestID("button_confirm_send").click(); + cy.getByTestID("txn_authorization_title").contains( + `Sending ${new BigNumber(amt).toFixed(8)} DFI to ${evmAddress}`, + ); + cy.closeOceanInterface().wait(3000); + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("dfi_total_balance_amount").contains( + Math.trunc(Number(dvmbalance) * 100) / 100 - amt, + ); // get fixed 2 decimals without rounding + cy.getByTestID("dfi_balance_card").should("exist").click(); + cy.getByTestID("dfi_utxo_amount").contains("8.99"); + cy.getByTestID("dfi_token_amount").should("have.text", "0.00000000 DFI"); + cy.go("back"); + }); + + it("should not allow to send tokens from EVM to other EVM address", () => { + cy.getByTestID("domain_switch").click(); + cy.getByTestID("portfolio_list").should("exist"); + cy.getByTestID("send_balance_button").click().wait(3000); + cy.getByTestID("select_DFI").click().wait(3000); + cy.getByTestID("address_input").clear().type(evmAddress); + cy.getByTestID("address_error_text").should( + "have.text", + "Invalid address. Make sure the address is correct to avoid irrecoverable losses", + ); + }); +});