2024-06-06 14:05:31 +00:00
|
|
|
|
import QtQuick 2.15
|
2024-05-15 21:22:13 +00:00
|
|
|
|
import QtTest 1.15
|
|
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2024-06-18 17:24:07 +00:00
|
|
|
|
import StatusQ.Controls 0.1
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
|
|
|
|
|
|
import Models 1.0
|
|
|
|
|
import Storybook 1.0
|
|
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
import shared.stores 1.0
|
|
|
|
|
import AppLayouts.Wallet.popups.swap 1.0
|
|
|
|
|
import AppLayouts.Wallet.stores 1.0
|
|
|
|
|
import AppLayouts.Wallet 1.0
|
2024-06-18 22:51:49 +00:00
|
|
|
|
import AppLayouts.Wallet.adaptors 1.0
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
2024-06-18 22:51:49 +00:00
|
|
|
|
width: 800
|
|
|
|
|
height: 600
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
|
readonly property var dummySwapTransactionRoutes: SwapTransactionRoutes {}
|
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
|
readonly property var swapStore: SwapStore {
|
2024-07-19 03:36:36 +00:00
|
|
|
|
signal suggestedRoutesReady(var txRoutes, string errCode, string errDescription)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
signal transactionSent(var chainId,var txHash, var uuid, var error)
|
2024-09-13 11:39:12 +00:00
|
|
|
|
signal transactionSendingComplete(var txHash, var status)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
|
readonly property var accounts: WalletAccountsModel {}
|
|
|
|
|
readonly property var flatNetworks: NetworksModel.flatNetworks
|
|
|
|
|
readonly property bool areTestNetworksEnabled: true
|
2024-06-06 14:05:31 +00:00
|
|
|
|
function getWei2Eth(wei, decimals) {
|
|
|
|
|
return wei/(10**decimals)
|
|
|
|
|
}
|
2024-06-30 22:08:08 +00:00
|
|
|
|
function fetchSuggestedRoutes(uuid, accountFrom, accountTo, amount, tokenFrom, tokenTo,
|
2024-06-24 13:52:10 +00:00
|
|
|
|
disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts) {
|
|
|
|
|
swapStore.fetchSuggestedRoutesCalled()
|
|
|
|
|
}
|
|
|
|
|
function authenticateAndTransfer(uuid, accountFrom, accountTo, tokenFrom,
|
|
|
|
|
tokenTo, sendType, tokenName, tokenIsOwnerToken, paths) {}
|
|
|
|
|
// local signals for testing function calls
|
|
|
|
|
signal fetchSuggestedRoutesCalled()
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-24 00:33:26 +00:00
|
|
|
|
readonly property SwapModalAdaptor swapAdaptor: SwapModalAdaptor {
|
2024-05-15 21:22:13 +00:00
|
|
|
|
currencyStore: CurrenciesStore {}
|
|
|
|
|
walletAssetsStore: WalletAssetsStore {
|
|
|
|
|
id: thisWalletAssetStore
|
|
|
|
|
walletTokensStore: TokensStore {
|
2024-05-28 17:39:41 +00:00
|
|
|
|
plainTokensBySymbolModel: TokensBySymbolModel {}
|
2024-06-06 14:05:31 +00:00
|
|
|
|
getDisplayAssetsBelowBalanceThresholdDisplayAmount: () => 0
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
readonly property var baseGroupedAccountAssetModel: GroupedAccountsAssetsModel {}
|
|
|
|
|
assetsWithFilteredBalances: thisWalletAssetStore.groupedAccountsAssetsModel
|
|
|
|
|
}
|
|
|
|
|
swapStore: root.swapStore
|
|
|
|
|
swapFormData: root.swapFormData
|
2024-06-06 14:05:31 +00:00
|
|
|
|
swapOutputData: SwapOutputData{}
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
readonly property var tokenSelectorAdaptor: TokenSelectorViewAdaptor {
|
|
|
|
|
assetsModel: swapAdaptor.walletAssetsStore.groupedAccountAssetsModel
|
|
|
|
|
flatNetworksModel: swapStore.flatNetworks
|
2024-06-25 21:33:25 +00:00
|
|
|
|
currentCurrency: swapAdaptor.currencyStore.currentCurrency
|
2024-07-03 16:29:30 +00:00
|
|
|
|
plainTokensBySymbolModel: root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel
|
2024-06-18 22:51:49 +00:00
|
|
|
|
|
|
|
|
|
enabledChainIds: !!root.swapFormData && root.swapFormData.selectedNetworkChainId !== - 1 ? [root.swapFormData.selectedNetworkChainId] : []
|
|
|
|
|
accountAddress: !!root.swapFormData && root.swapFormData.selectedAccountAddress
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 17:24:07 +00:00
|
|
|
|
property SwapInputParamsForm swapFormData: SwapInputParamsForm {
|
2024-07-10 18:35:24 +00:00
|
|
|
|
defaultToTokenKey: Constants.swap.testStatusTokenKey
|
2024-06-18 17:24:07 +00:00
|
|
|
|
}
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
Component {
|
|
|
|
|
id: componentUnderTest
|
|
|
|
|
SwapModal {
|
|
|
|
|
swapInputParamsForm: root.swapFormData
|
|
|
|
|
swapAdaptor: root.swapAdaptor
|
2024-07-10 18:35:24 +00:00
|
|
|
|
loginType: Constants.LoginType.Password
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
SignalSpy {
|
|
|
|
|
id: formValuesChanged
|
|
|
|
|
target: swapFormData
|
|
|
|
|
signalName: "formValuesChanged"
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 13:52:10 +00:00
|
|
|
|
SignalSpy {
|
|
|
|
|
id: fetchSuggestedRoutesCalled
|
|
|
|
|
target: swapStore
|
|
|
|
|
signalName: "fetchSuggestedRoutesCalled"
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
|
TestCase {
|
|
|
|
|
name: "SwapModal"
|
|
|
|
|
when: windowShown
|
|
|
|
|
|
|
|
|
|
property SwapModal controlUnderTest: null
|
|
|
|
|
|
|
|
|
|
// helper functions -------------------------------------------------------------
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
function init() {
|
2024-06-07 12:27:56 +00:00
|
|
|
|
swapAdaptor.swapFormData = root.swapFormData
|
|
|
|
|
controlUnderTest = createTemporaryObject(componentUnderTest, root, { swapInputParamsForm: root.swapFormData})
|
2024-06-06 14:05:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
function cleanup() {
|
|
|
|
|
root.swapFormData.resetFormData()
|
|
|
|
|
formValuesChanged.clear()
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
|
function launchAndVerfyModal() {
|
2024-06-06 14:05:31 +00:00
|
|
|
|
formValuesChanged.clear()
|
2024-05-15 21:22:13 +00:00
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
|
controlUnderTest.open()
|
|
|
|
|
verify(!!controlUnderTest.opened)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeAndVerfyModal() {
|
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
|
controlUnderTest.close()
|
|
|
|
|
verify(!controlUnderTest.opened)
|
2024-06-06 14:05:31 +00:00
|
|
|
|
formValuesChanged.clear()
|
2024-06-18 17:24:07 +00:00
|
|
|
|
root.swapFormData.resetFormData()
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getAndVerifyAccountsModalHeader() {
|
2024-06-07 12:27:56 +00:00
|
|
|
|
const accountsModalHeader = findChild(controlUnderTest, "accountSelector")
|
2024-05-15 21:22:13 +00:00
|
|
|
|
verify(!!accountsModalHeader)
|
|
|
|
|
return accountsModalHeader
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function launchAccountSelectionPopup(accountsModalHeader) {
|
|
|
|
|
// Launch account selection popup
|
|
|
|
|
verify(!accountsModalHeader.control.popup.opened)
|
2024-05-29 15:42:26 +00:00
|
|
|
|
mouseClick(accountsModalHeader)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
waitForRendering(accountsModalHeader)
|
|
|
|
|
verify(!!accountsModalHeader.control.popup.opened)
|
2024-07-01 12:03:08 +00:00
|
|
|
|
mouseMove(accountsModalHeader)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
return accountsModalHeader
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
function verifyLoadingAndNoErrorsState(payPanel, receivePanel) {
|
2024-06-06 14:05:31 +00:00
|
|
|
|
// verify loading state was set and no errors currently
|
|
|
|
|
verify(!root.swapAdaptor.validSwapProposalReceived)
|
|
|
|
|
verify(root.swapAdaptor.swapProposalLoading)
|
2024-07-03 22:08:03 +00:00
|
|
|
|
compare(root.swapAdaptor.swapOutputData.rawPaths, [])
|
2024-06-06 14:05:31 +00:00
|
|
|
|
compare(root.swapAdaptor.swapOutputData.hasError, false)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
// verfy input and output panels
|
2024-06-14 11:34:20 +00:00
|
|
|
|
verify(!payPanel.mainInputLoading)
|
2024-08-30 09:16:40 +00:00
|
|
|
|
verify(payPanel.bottomTextLoading)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(payPanel.selectedHoldingId, root.swapFormData.fromTokensKey)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(payPanel.value, Number(root.swapFormData.fromTokenAmount))
|
|
|
|
|
compare(payPanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(root.swapFormData.fromTokenAmount, root.swapAdaptor.fromToken.decimals).toString())
|
|
|
|
|
verify(payPanel.valueValid)
|
|
|
|
|
verify(receivePanel.mainInputLoading)
|
|
|
|
|
verify(receivePanel.bottomTextLoading)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(!receivePanel.interactive)
|
|
|
|
|
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(receivePanel.value, 0)
|
|
|
|
|
compare(receivePanel.rawValue, "0")
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
|
// end helper functions -------------------------------------------------------------
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
function test_floating_header_default_account() {
|
|
|
|
|
verify(!!controlUnderTest)
|
|
|
|
|
/* using a for loop set different accounts as default index and
|
|
|
|
|
check if the correct values are displayed in the floating header*/
|
|
|
|
|
for (let i = 0; i< swapAdaptor.nonWatchAccounts.count; i++) {
|
2024-06-07 12:27:56 +00:00
|
|
|
|
const nonWatchAccount = swapAdaptor.nonWatchAccounts.get(i)
|
|
|
|
|
root.swapFormData.selectedAccountAddress = nonWatchAccount.address
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
const floatingHeaderBackground = findChild(controlUnderTest, "headerBackground")
|
|
|
|
|
verify(!!floatingHeaderBackground)
|
2024-06-07 12:27:56 +00:00
|
|
|
|
compare(floatingHeaderBackground.color.toString().toUpperCase(), Utils.getColorForId(nonWatchAccount.colorId).toString().toUpperCase())
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
|
const headerContentItemText = findChild(controlUnderTest, "textContent")
|
2024-05-15 21:22:13 +00:00
|
|
|
|
verify(!!headerContentItemText)
|
2024-06-07 12:27:56 +00:00
|
|
|
|
compare(headerContentItemText.text, nonWatchAccount.name)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
|
const headerContentItemEmoji = findChild(controlUnderTest, "assetContent")
|
2024-05-15 21:22:13 +00:00
|
|
|
|
verify(!!headerContentItemEmoji)
|
2024-06-07 12:27:56 +00:00
|
|
|
|
compare(headerContentItemEmoji.asset.emoji, nonWatchAccount.emoji)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_floating_header_doesnt_contain_watch_accounts() {
|
|
|
|
|
// main input list from store should contian watch accounts
|
|
|
|
|
let hasWatchAccount = false
|
|
|
|
|
for(let i =0; i< swapStore.accounts.count; i++) {
|
|
|
|
|
if(swapStore.accounts.get(i).walletType === Constants.watchWalletType) {
|
|
|
|
|
hasWatchAccount = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
verify(!!hasWatchAccount)
|
|
|
|
|
|
|
|
|
|
// launch modal and get the account selection header
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
const accountsModalHeader = getAndVerifyAccountsModalHeader()
|
|
|
|
|
|
|
|
|
|
// header model should not contain watch accounts
|
|
|
|
|
let floatingHeaderHasWatchAccount = false
|
|
|
|
|
for(let i =0; i< accountsModalHeader.model.count; i++) {
|
|
|
|
|
if(accountsModalHeader.model.get(i).walletType === Constants.watchWalletType) {
|
|
|
|
|
floatingHeaderHasWatchAccount = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
verify(!floatingHeaderHasWatchAccount)
|
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_floating_header_list_items() {
|
|
|
|
|
// Launch popup and account selection modal
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
const accountsModalHeader = getAndVerifyAccountsModalHeader()
|
|
|
|
|
launchAccountSelectionPopup(accountsModalHeader)
|
|
|
|
|
|
|
|
|
|
const comboBoxList = findChild(controlUnderTest, "accountSelectorList")
|
|
|
|
|
verify(!!comboBoxList)
|
2024-06-25 21:33:25 +00:00
|
|
|
|
waitForRendering(comboBoxList)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
for(let i =0; i< comboBoxList.model.count; i++) {
|
|
|
|
|
let delegateUnderTest = comboBoxList.itemAtIndex(i)
|
2024-10-04 15:23:26 +00:00
|
|
|
|
let accountToBeTested = swapAdaptor.nonWatchAccounts.get(i)
|
|
|
|
|
let elidedAddress = SQUtils.Utils.elideAndFormatWalletAddress(accountToBeTested.address)
|
|
|
|
|
compare(delegateUnderTest.title, accountToBeTested.name)
|
|
|
|
|
compare(delegateUnderTest.subTitle, elidedAddress)
|
|
|
|
|
compare(delegateUnderTest.asset.color.toString().toUpperCase(), accountToBeTested.color.toString().toUpperCase())
|
|
|
|
|
compare(delegateUnderTest.asset.emoji, accountToBeTested.emoji)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
const walletAccountCurrencyBalance = findChild(delegateUnderTest, "walletAccountCurrencyBalance")
|
|
|
|
|
verify(!!walletAccountCurrencyBalance)
|
2024-10-04 15:23:26 +00:00
|
|
|
|
verify(walletAccountCurrencyBalance.text, LocaleUtils.currencyAmountToLocaleString(accountToBeTested.currencyBalance))
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
// check if selected item in combo box is highlighted with the right color
|
|
|
|
|
if(comboBoxList.currentIndex === i) {
|
|
|
|
|
verify(delegateUnderTest.color, Theme.palette.statusListItem.highlightColor)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
verify(delegateUnderTest.color, Theme.palette.transparent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: always null not sure why
|
|
|
|
|
// const walletAccountTypeIcon = findChild(delegateUnderTest, "walletAccountTypeIcon")
|
|
|
|
|
// verify(!!walletAccountTypeIcon)
|
2024-10-04 15:23:26 +00:00
|
|
|
|
// compare(walletAccountTypeIcon.icon, accountToBeTested.walletType === Constants.watchWalletType ? "show" : delegateUnderTest.model.migratedToKeycard ? "keycard": "")
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
// Hover over the item and check hovered state
|
|
|
|
|
mouseMove(delegateUnderTest, delegateUnderTest.width/2, delegateUnderTest.height/2)
|
|
|
|
|
verify(delegateUnderTest.sensor.containsMouse)
|
2024-10-04 15:23:26 +00:00
|
|
|
|
compare(delegateUnderTest.title, accountToBeTested.name)
|
|
|
|
|
compare(delegateUnderTest.subTitle, Utils.richColorText(elidedAddress, Theme.palette.directColor1))
|
2024-05-15 21:22:13 +00:00
|
|
|
|
verify(delegateUnderTest.color, Theme.palette.baseColor2)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
controlUnderTest.close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_floating_header_after_setting_fromAsset() {
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
// launch account selection dropdown
|
|
|
|
|
const accountsModalHeader = getAndVerifyAccountsModalHeader()
|
|
|
|
|
launchAccountSelectionPopup(accountsModalHeader)
|
|
|
|
|
|
|
|
|
|
const comboBoxList = findChild(accountsModalHeader, "accountSelectorList")
|
|
|
|
|
verify(!!comboBoxList)
|
|
|
|
|
|
|
|
|
|
// before setting network chainId and fromTokensKey the header should not have balances
|
|
|
|
|
for(let i =0; i< comboBoxList.model.count; i++) {
|
|
|
|
|
let delegateUnderTest = comboBoxList.itemAtIndex(i)
|
2024-06-07 12:27:56 +00:00
|
|
|
|
verify(!delegateUnderTest.model.accountBalance)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// close account selection dropdown
|
|
|
|
|
accountsModalHeader.control.popup.close()
|
|
|
|
|
|
|
|
|
|
// set network chainId and fromTokensKey and verify balances in account selection dropdown
|
2024-05-29 15:42:26 +00:00
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
2024-05-15 21:22:13 +00:00
|
|
|
|
root.swapFormData.fromTokensKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(0).key
|
|
|
|
|
compare(controlUnderTest.swapInputParamsForm.selectedNetworkChainId, root.swapFormData.selectedNetworkChainId)
|
|
|
|
|
compare(controlUnderTest.swapInputParamsForm.fromTokensKey, root.swapFormData.fromTokensKey)
|
|
|
|
|
|
|
|
|
|
// launch account selection dropdown
|
|
|
|
|
launchAccountSelectionPopup(accountsModalHeader)
|
|
|
|
|
verify(!!comboBoxList)
|
|
|
|
|
|
|
|
|
|
for(let i =0; i< comboBoxList.model.count; i++) {
|
|
|
|
|
let delegateUnderTest = comboBoxList.itemAtIndex(i)
|
2024-06-07 12:27:56 +00:00
|
|
|
|
verify(!!delegateUnderTest.model.fromToken)
|
|
|
|
|
verify(!!delegateUnderTest.model.accountBalance)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
compare(delegateUnderTest.inlineTagModel, 1)
|
|
|
|
|
|
|
|
|
|
const inlineTagDelegate_0 = findChild(delegateUnderTest, "inlineTagDelegate_0")
|
|
|
|
|
verify(!!inlineTagDelegate_0)
|
|
|
|
|
|
2024-06-25 13:37:42 +00:00
|
|
|
|
const balance = delegateUnderTest.model.accountBalance.balance
|
|
|
|
|
|
2024-10-15 19:26:12 +00:00
|
|
|
|
compare(inlineTagDelegate_0.asset.name, Theme.svg("tiny/%1".arg(delegateUnderTest.model.accountBalance.iconUrl)))
|
2024-06-07 12:27:56 +00:00
|
|
|
|
compare(inlineTagDelegate_0.asset.color.toString().toUpperCase(), delegateUnderTest.model.accountBalance.chainColor.toString().toUpperCase())
|
2024-06-25 13:37:42 +00:00
|
|
|
|
compare(inlineTagDelegate_0.titleText.color, balance === "0" ? Theme.palette.baseColor1 : Theme.palette.directColor1)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
2024-06-25 13:37:42 +00:00
|
|
|
|
let bigIntBalance = SQUtils.AmountsArithmetic.toNumber(balance, delegateUnderTest.model.fromToken.decimals)
|
|
|
|
|
compare(inlineTagDelegate_0.title, balance === "0" ? "0 %1".arg(delegateUnderTest.model.fromToken.symbol)
|
|
|
|
|
: root.swapAdaptor.formatCurrencyAmount(bigIntBalance, delegateUnderTest.model.fromToken.symbol))
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_floating_header_selection() {
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
2024-07-15 17:09:21 +00:00
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const amountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(amountToSendInput.cursorVisible)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
2024-07-15 17:09:21 +00:00
|
|
|
|
for(let i =0; i< swapAdaptor.nonWatchAccounts.count; i++) {
|
2024-05-15 21:22:13 +00:00
|
|
|
|
// launch account selection dropdown
|
|
|
|
|
const accountsModalHeader = getAndVerifyAccountsModalHeader()
|
|
|
|
|
launchAccountSelectionPopup(accountsModalHeader)
|
|
|
|
|
|
|
|
|
|
const comboBoxList = findChild(accountsModalHeader, "accountSelectorList")
|
|
|
|
|
verify(!!comboBoxList)
|
|
|
|
|
|
|
|
|
|
let delegateUnderTest = comboBoxList.itemAtIndex(i)
|
|
|
|
|
|
2024-05-29 15:42:26 +00:00
|
|
|
|
mouseClick(delegateUnderTest)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
waitForRendering(delegateUnderTest)
|
|
|
|
|
verify(accountsModalHeader.control.popup.closed)
|
|
|
|
|
|
|
|
|
|
// The input params form's slected Index should be updated as per this selection
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(root.swapFormData.selectedAccountAddress, swapAdaptor.nonWatchAccounts.get(i).address)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
|
|
// The comboBox item should reflect chosen account
|
|
|
|
|
const floatingHeaderBackground = findChild(accountsModalHeader, "headerBackground")
|
|
|
|
|
verify(!!floatingHeaderBackground)
|
|
|
|
|
compare(floatingHeaderBackground.color.toString().toUpperCase(), swapAdaptor.nonWatchAccounts.get(i).color.toString().toUpperCase())
|
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
|
const headerContentItemText = findChild(accountsModalHeader, "textContent")
|
2024-05-15 21:22:13 +00:00
|
|
|
|
verify(!!headerContentItemText)
|
|
|
|
|
compare(headerContentItemText.text, swapAdaptor.nonWatchAccounts.get(i).name)
|
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
|
const headerContentItemEmoji = findChild(accountsModalHeader, "assetContent")
|
2024-05-15 21:22:13 +00:00
|
|
|
|
verify(!!headerContentItemEmoji)
|
2024-06-07 12:27:56 +00:00
|
|
|
|
compare(headerContentItemEmoji.asset.emoji, swapAdaptor.nonWatchAccounts.get(i).emoji)
|
2024-07-15 17:09:21 +00:00
|
|
|
|
|
2024-10-08 15:28:33 +00:00
|
|
|
|
waitForRendering(amountToSendInput)
|
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(amountToSendInput.cursorVisible)
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
2024-05-29 15:42:26 +00:00
|
|
|
|
|
|
|
|
|
function test_network_default_and_selection() {
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
2024-07-15 17:09:21 +00:00
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const amountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(amountToSendInput.cursorVisible)
|
2024-07-15 17:09:21 +00:00
|
|
|
|
|
2024-05-29 15:42:26 +00:00
|
|
|
|
// get network comboBox
|
|
|
|
|
const networkComboBox = findChild(controlUnderTest, "networkFilter")
|
|
|
|
|
verify(!!networkComboBox)
|
|
|
|
|
|
|
|
|
|
// check default value of network comboBox, should be mainnet
|
|
|
|
|
compare(root.swapFormData.selectedNetworkChainId, -1)
|
2024-06-06 09:49:13 +00:00
|
|
|
|
compare(root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId, 11155111 /*Sepolia Mainnet*/)
|
2024-05-29 15:42:26 +00:00
|
|
|
|
|
|
|
|
|
// lets ensure that the selected one is correctly set
|
|
|
|
|
for (let i=0; i<networkComboBox.control.popup.contentItem.count; i++) {
|
|
|
|
|
// launch network selection popup
|
|
|
|
|
verify(!networkComboBox.control.popup.opened)
|
|
|
|
|
mouseClick(networkComboBox)
|
|
|
|
|
verify(networkComboBox.control.popup.opened)
|
|
|
|
|
|
|
|
|
|
let delegateUnderTest = networkComboBox.control.popup.contentItem.itemAtIndex(i)
|
|
|
|
|
verify(!!delegateUnderTest)
|
|
|
|
|
|
|
|
|
|
// if you try selecting an item already selected it doesnt do anything
|
|
|
|
|
if(networkComboBox.control.popup.contentItem.currentIndex === i) {
|
|
|
|
|
mouseClick(networkComboBox)
|
|
|
|
|
} else {
|
|
|
|
|
// select item
|
|
|
|
|
mouseClick(delegateUnderTest)
|
|
|
|
|
|
|
|
|
|
// verify values set
|
|
|
|
|
verify(!networkComboBox.control.popup.opened)
|
|
|
|
|
compare(root.swapFormData.selectedNetworkChainId, networkComboBox.control.popup.contentItem.model.get(i).chainId)
|
2024-06-06 09:49:13 +00:00
|
|
|
|
|
|
|
|
|
const networkComboIcon = findChild(networkComboBox.control.contentItem, "contentItemIcon")
|
|
|
|
|
verify(!!networkComboIcon)
|
|
|
|
|
verify(networkComboIcon.asset.name.includes(root.swapAdaptor.filteredFlatNetworksModel.get(i).iconUrl))
|
2024-07-15 17:09:21 +00:00
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(amountToSendInput.cursorVisible)
|
2024-05-29 15:42:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
networkComboBox.control.popup.close()
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_network_and_account_header_items() {
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
// get network comboBox
|
|
|
|
|
const networkComboBox = findChild(controlUnderTest, "networkFilter")
|
|
|
|
|
verify(!!networkComboBox)
|
|
|
|
|
|
|
|
|
|
for (let i=0; i<networkComboBox.control.popup.contentItem.count; i++) {
|
|
|
|
|
// launch network selection popup
|
|
|
|
|
verify(!networkComboBox.control.popup.opened)
|
|
|
|
|
mouseClick(networkComboBox)
|
|
|
|
|
verify(networkComboBox.control.popup.opened)
|
|
|
|
|
|
|
|
|
|
let delegateUnderTest = networkComboBox.control.popup.contentItem.itemAtIndex(i)
|
|
|
|
|
verify(!!delegateUnderTest)
|
|
|
|
|
|
|
|
|
|
let networkModelItem = networkComboBox.control.popup.contentItem.model.get(i)
|
|
|
|
|
|
|
|
|
|
// if you try selecting an item already selected it doesnt do anything
|
|
|
|
|
if(networkComboBox.control.popup.contentItem.currentIndex === i) {
|
|
|
|
|
mouseClick(networkComboBox)
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = networkModelItem.chainId
|
|
|
|
|
} else {
|
|
|
|
|
// select item
|
|
|
|
|
mouseClick(delegateUnderTest)
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 17:24:07 +00:00
|
|
|
|
root.swapFormData.fromTokensKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(0).key
|
|
|
|
|
|
2024-05-29 15:42:26 +00:00
|
|
|
|
// verify values in accouns modal header dropdown
|
|
|
|
|
const accountsModalHeader = getAndVerifyAccountsModalHeader()
|
|
|
|
|
launchAccountSelectionPopup(accountsModalHeader)
|
|
|
|
|
|
|
|
|
|
const comboBoxList = findChild(accountsModalHeader, "accountSelectorList")
|
|
|
|
|
verify(!!comboBoxList)
|
|
|
|
|
|
|
|
|
|
for(let j =0; j< comboBoxList.model.count; j++) {
|
|
|
|
|
let accountDelegateUnderTest = comboBoxList.itemAtIndex(j)
|
|
|
|
|
verify(!!accountDelegateUnderTest)
|
2024-06-18 22:51:49 +00:00
|
|
|
|
waitForItemPolished(accountDelegateUnderTest)
|
2024-05-29 15:42:26 +00:00
|
|
|
|
const inlineTagDelegate_0 = findChild(accountDelegateUnderTest, "inlineTagDelegate_0")
|
|
|
|
|
verify(!!inlineTagDelegate_0)
|
|
|
|
|
|
2024-10-15 19:26:12 +00:00
|
|
|
|
compare(inlineTagDelegate_0.asset.name, Theme.svg("tiny/%1".arg(networkModelItem.iconUrl)))
|
2024-05-29 15:42:26 +00:00
|
|
|
|
compare(inlineTagDelegate_0.asset.color.toString().toUpperCase(), networkModelItem.chainColor.toString().toUpperCase())
|
|
|
|
|
|
|
|
|
|
let balancesModel = SQUtils.ModelUtils.getByKey(root.swapAdaptor.walletAssetsStore.baseGroupedAccountAssetModel, "tokensKey", root.swapFormData.fromTokensKey).balances
|
|
|
|
|
verify(!!balancesModel)
|
2024-06-07 12:27:56 +00:00
|
|
|
|
let filteredBalances = SQUtils.ModelUtils.modelToArray(balancesModel).filter(balances => balances.chainId === root.swapFormData.selectedNetworkChainId).filter(balances => balances.account === accountDelegateUnderTest.model.address)
|
2024-05-29 15:42:26 +00:00
|
|
|
|
verify(!!filteredBalances)
|
|
|
|
|
let accountBalance = filteredBalances.length > 0 ? filteredBalances[0]: { balance: "0", iconUrl: networkModelItem.iconUrl, chainColor: networkModelItem.chainColor}
|
|
|
|
|
verify(!!accountBalance)
|
|
|
|
|
let fromToken = SQUtils.ModelUtils.getByKey(root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel, "key", root.swapFormData.fromTokensKey)
|
|
|
|
|
verify(!!fromToken)
|
|
|
|
|
let bigIntBalance = SQUtils.AmountsArithmetic.toNumber(accountBalance.balance, fromToken.decimals)
|
2024-06-25 13:37:42 +00:00
|
|
|
|
compare(inlineTagDelegate_0.title, bigIntBalance === 0 ? "0 %1".arg(fromToken.symbol)
|
|
|
|
|
: root.swapAdaptor.formatCurrencyAmount(bigIntBalance, fromToken.symbol))
|
2024-05-29 15:42:26 +00:00
|
|
|
|
}
|
|
|
|
|
// close account selection dropdown
|
|
|
|
|
accountsModalHeader.control.popup.close()
|
|
|
|
|
}
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = -1
|
|
|
|
|
networkComboBox.control.popup.close()
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
2024-06-04 11:58:37 +00:00
|
|
|
|
|
|
|
|
|
function test_edit_slippage() {
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
// test default values for the various footer items for slippage
|
|
|
|
|
const maxSlippageText = findChild(controlUnderTest, "maxSlippageText")
|
|
|
|
|
verify(!!maxSlippageText)
|
|
|
|
|
compare(maxSlippageText.text, qsTr("Max slippage:"))
|
|
|
|
|
|
|
|
|
|
const maxSlippageValue = findChild(controlUnderTest, "maxSlippageValue")
|
|
|
|
|
verify(!!maxSlippageValue)
|
|
|
|
|
|
|
|
|
|
const editSlippageButton = findChild(controlUnderTest, "editSlippageButton")
|
|
|
|
|
verify(!!editSlippageButton)
|
|
|
|
|
|
|
|
|
|
const editSlippagePanel = findChild(controlUnderTest, "editSlippagePanel")
|
|
|
|
|
verify(!!editSlippagePanel)
|
|
|
|
|
verify(!editSlippagePanel.visible)
|
|
|
|
|
|
|
|
|
|
// set swap proposal to ready and check state of the edit slippage buttons and max slippage values
|
2024-06-06 14:05:31 +00:00
|
|
|
|
root.swapAdaptor.validSwapProposalReceived = true
|
2024-06-04 11:58:37 +00:00
|
|
|
|
compare(maxSlippageValue.text, "%1%".arg(0.5))
|
|
|
|
|
verify(editSlippageButton.visible)
|
|
|
|
|
|
|
|
|
|
// clicking on editSlippageButton should show the edit slippage panel
|
|
|
|
|
mouseClick(editSlippageButton)
|
|
|
|
|
verify(!editSlippageButton.visible)
|
|
|
|
|
verify(editSlippagePanel.visible)
|
|
|
|
|
|
|
|
|
|
const slippageSelector = findChild(editSlippagePanel, "slippageSelector")
|
|
|
|
|
verify(!!slippageSelector)
|
|
|
|
|
|
|
|
|
|
verify(slippageSelector.valid)
|
|
|
|
|
compare(slippageSelector.value, 0.5)
|
|
|
|
|
|
|
|
|
|
const buttonsRepeater = findChild(slippageSelector, "buttonsRepeater")
|
|
|
|
|
verify(!!buttonsRepeater)
|
|
|
|
|
waitForRendering(buttonsRepeater)
|
|
|
|
|
|
|
|
|
|
for(let i =0; i< buttonsRepeater.count; i++) {
|
|
|
|
|
let buttonUnderTest = buttonsRepeater.itemAt(i)
|
|
|
|
|
verify(!!buttonUnderTest)
|
|
|
|
|
|
|
|
|
|
// the mouseClick(buttonUnderTest) doesnt seem to work
|
|
|
|
|
buttonUnderTest.clicked()
|
|
|
|
|
|
|
|
|
|
verify(slippageSelector.valid)
|
|
|
|
|
compare(slippageSelector.value, buttonUnderTest.value)
|
|
|
|
|
|
|
|
|
|
compare(maxSlippageValue.text, "%1%".arg(buttonUnderTest.value))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const signButton = findChild(controlUnderTest, "signButton")
|
|
|
|
|
verify(!!signButton)
|
|
|
|
|
verify(signButton.enabled)
|
|
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
function test_modal_swap_proposal_setup() {
|
|
|
|
|
root.swapAdaptor.reset()
|
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
waitForItemPolished(controlUnderTest.contentItem)
|
|
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
|
const maxFeesText = findChild(controlUnderTest, "maxFeesText")
|
|
|
|
|
verify(!!maxFeesText)
|
|
|
|
|
|
|
|
|
|
const maxFeesValue = findChild(controlUnderTest, "maxFeesValue")
|
|
|
|
|
verify(!!maxFeesValue)
|
|
|
|
|
|
|
|
|
|
const signButton = findChild(controlUnderTest, "signButton")
|
|
|
|
|
verify(!!signButton)
|
|
|
|
|
|
|
|
|
|
const errorTag = findChild(controlUnderTest, "errorTag")
|
|
|
|
|
verify(!!errorTag)
|
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
|
|
|
|
|
const receivePanel = findChild(controlUnderTest, "receivePanel")
|
|
|
|
|
verify(!!receivePanel)
|
|
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
|
// Check max fees values and sign button state when nothing is set
|
|
|
|
|
compare(maxFeesText.text, qsTr("Max fees:"))
|
|
|
|
|
compare(maxFeesValue.text, "--")
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.interactive)
|
2024-06-06 14:05:31 +00:00
|
|
|
|
verify(!errorTag.visible)
|
|
|
|
|
|
|
|
|
|
// set input values in the form correctly
|
|
|
|
|
root.swapFormData.fromTokensKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(0).key
|
2024-06-24 13:52:10 +00:00
|
|
|
|
formValuesChanged.wait()
|
2024-06-06 14:05:31 +00:00
|
|
|
|
root.swapFormData.toTokenKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(1).key
|
2024-06-13 00:45:33 +00:00
|
|
|
|
root.swapFormData.fromTokenAmount = "0.001"
|
2024-07-01 12:03:08 +00:00
|
|
|
|
waitForRendering(receivePanel)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
formValuesChanged.wait()
|
2024-06-06 14:05:31 +00:00
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
2024-06-24 13:52:10 +00:00
|
|
|
|
formValuesChanged.wait()
|
2024-07-24 20:10:36 +00:00
|
|
|
|
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
|
2024-06-24 13:52:10 +00:00
|
|
|
|
formValuesChanged.wait()
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// wait for fetchSuggestedRoutes function to be called
|
2024-06-24 13:52:10 +00:00
|
|
|
|
fetchSuggestedRoutesCalled.wait()
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// verify loading state was set and no errors currently
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
2024-07-19 03:36:36 +00:00
|
|
|
|
// emit event that no routes were found with unknown error
|
2024-07-24 20:10:36 +00:00
|
|
|
|
const txRoutes = root.dummySwapTransactionRoutes.txNoRoutes
|
|
|
|
|
txRoutes.uuid = root.swapAdaptor.uuid
|
|
|
|
|
root.swapStore.suggestedRoutesReady(txRoutes, "NO_ROUTES", "No routes found")
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// verify loading state was removed and that error was displayed
|
|
|
|
|
verify(!root.swapAdaptor.validSwapProposalReceived)
|
|
|
|
|
verify(!root.swapAdaptor.swapProposalLoading)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.toTokenAmount, "")
|
2024-06-06 14:05:31 +00:00
|
|
|
|
compare(root.swapAdaptor.swapOutputData.totalFees, 0)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalNeeded, false)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.hasError, true)
|
|
|
|
|
verify(errorTag.visible)
|
|
|
|
|
verify(errorTag.text, qsTr("An error has occured, please try again"))
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.interactive)
|
2024-06-06 14:05:31 +00:00
|
|
|
|
compare(signButton.text, qsTr("Swap"))
|
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
// verfy input and output panels
|
2024-06-14 11:34:20 +00:00
|
|
|
|
verify(!payPanel.mainInputLoading)
|
|
|
|
|
verify(!payPanel.bottomTextLoading)
|
|
|
|
|
verify(!receivePanel.mainInputLoading)
|
|
|
|
|
verify(!receivePanel.bottomTextLoading)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(!receivePanel.interactive)
|
|
|
|
|
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(receivePanel.value, 0)
|
|
|
|
|
compare(receivePanel.rawValue, "0")
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
|
// edit some params to retry swap
|
2024-06-13 00:45:33 +00:00
|
|
|
|
root.swapFormData.fromTokenAmount = "0.00011"
|
2024-07-01 12:03:08 +00:00
|
|
|
|
waitForRendering(receivePanel)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
formValuesChanged.wait()
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// wait for fetchSuggestedRoutes function to be called
|
2024-06-24 13:52:10 +00:00
|
|
|
|
fetchSuggestedRoutesCalled.wait()
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// verify loading state was set and no errors currently
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
2024-07-19 03:36:36 +00:00
|
|
|
|
// emit event that no routes were found due to not enough token balance
|
2024-07-24 20:10:36 +00:00
|
|
|
|
txRoutes.uuid = root.swapAdaptor.uuid
|
2024-08-28 12:50:09 +00:00
|
|
|
|
root.swapStore.suggestedRoutesReady(txRoutes, Constants.routerErrorCodes.router.errNotEnoughTokenBalance, "errNotEnoughTokenBalance")
|
2024-07-19 03:36:36 +00:00
|
|
|
|
|
|
|
|
|
// verify loading state was removed and that error was displayed
|
|
|
|
|
verify(!root.swapAdaptor.validSwapProposalReceived)
|
|
|
|
|
verify(!root.swapAdaptor.swapProposalLoading)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.toTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.totalFees, 0)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalNeeded, false)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.hasError, true)
|
|
|
|
|
verify(errorTag.visible)
|
|
|
|
|
verify(errorTag.text, qsTr("Insufficient funds for swap"))
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.interactive)
|
2024-07-19 03:36:36 +00:00
|
|
|
|
compare(signButton.text, qsTr("Swap"))
|
|
|
|
|
|
|
|
|
|
// verfy input and output panels
|
|
|
|
|
verify(!payPanel.mainInputLoading)
|
|
|
|
|
verify(!payPanel.bottomTextLoading)
|
|
|
|
|
verify(!receivePanel.mainInputLoading)
|
|
|
|
|
verify(!receivePanel.bottomTextLoading)
|
|
|
|
|
verify(!receivePanel.interactive)
|
|
|
|
|
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
|
|
|
|
|
compare(receivePanel.value, 0)
|
|
|
|
|
compare(receivePanel.rawValue, "0")
|
|
|
|
|
|
|
|
|
|
// edit some params to retry swap
|
|
|
|
|
root.swapFormData.fromTokenAmount = "0.00012"
|
|
|
|
|
waitForRendering(receivePanel)
|
|
|
|
|
formValuesChanged.wait()
|
|
|
|
|
|
|
|
|
|
// wait for fetchSuggestedRoutes function to be called
|
|
|
|
|
fetchSuggestedRoutesCalled.wait()
|
|
|
|
|
|
|
|
|
|
// verify loading state was set and no errors currently
|
|
|
|
|
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
|
|
|
|
|
|
|
|
|
|
// emit event that no routes were found due to not enough eth balance
|
2024-07-24 20:10:36 +00:00
|
|
|
|
txRoutes.uuid = root.swapAdaptor.uuid
|
2024-08-28 12:50:09 +00:00
|
|
|
|
root.swapStore.suggestedRoutesReady(txRoutes, Constants.routerErrorCodes.router.errNotEnoughNativeBalance, "errNotEnoughNativeBalance")
|
2024-07-19 03:36:36 +00:00
|
|
|
|
|
|
|
|
|
// verify loading state was removed and that error was displayed
|
|
|
|
|
verify(!root.swapAdaptor.validSwapProposalReceived)
|
|
|
|
|
verify(!root.swapAdaptor.swapProposalLoading)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.toTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.totalFees, 0)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalNeeded, false)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.hasError, true)
|
|
|
|
|
verify(errorTag.visible)
|
|
|
|
|
verify(errorTag.text, qsTr("Insufficient funds to pay gas fees"))
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.interactive)
|
2024-07-19 03:36:36 +00:00
|
|
|
|
compare(signButton.text, qsTr("Swap"))
|
|
|
|
|
|
|
|
|
|
// verfy input and output panels
|
|
|
|
|
verify(!payPanel.mainInputLoading)
|
|
|
|
|
verify(!payPanel.bottomTextLoading)
|
|
|
|
|
verify(!receivePanel.mainInputLoading)
|
|
|
|
|
verify(!receivePanel.bottomTextLoading)
|
|
|
|
|
verify(!receivePanel.interactive)
|
|
|
|
|
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
|
|
|
|
|
compare(receivePanel.value, 0)
|
|
|
|
|
compare(receivePanel.rawValue, "0")
|
|
|
|
|
|
|
|
|
|
// edit some params to retry swap
|
|
|
|
|
root.swapFormData.fromTokenAmount = "0.00013"
|
|
|
|
|
waitForRendering(receivePanel)
|
|
|
|
|
formValuesChanged.wait()
|
|
|
|
|
|
|
|
|
|
// wait for fetchSuggestedRoutes function to be called
|
|
|
|
|
fetchSuggestedRoutesCalled.wait()
|
|
|
|
|
|
|
|
|
|
// verify loading state was set and no errors currently
|
|
|
|
|
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
|
|
|
|
|
|
|
|
|
|
// emit event that no routes were found due to price timeout
|
2024-07-24 20:10:36 +00:00
|
|
|
|
txRoutes.uuid = root.swapAdaptor.uuid
|
2024-08-28 12:50:09 +00:00
|
|
|
|
root.swapStore.suggestedRoutesReady(txRoutes, Constants.routerErrorCodes.processor.errPriceTimeout, "errPriceTimeout")
|
2024-07-19 03:36:36 +00:00
|
|
|
|
|
|
|
|
|
// verify loading state was removed and that error was displayed
|
|
|
|
|
verify(!root.swapAdaptor.validSwapProposalReceived)
|
|
|
|
|
verify(!root.swapAdaptor.swapProposalLoading)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.toTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.totalFees, 0)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalNeeded, false)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.hasError, true)
|
|
|
|
|
verify(errorTag.visible)
|
|
|
|
|
verify(errorTag.text, qsTr("Fetching the price took longer than expected. Please, try again later."))
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.interactive)
|
2024-07-19 03:36:36 +00:00
|
|
|
|
compare(signButton.text, qsTr("Swap"))
|
|
|
|
|
|
|
|
|
|
// verfy input and output panels
|
|
|
|
|
verify(!payPanel.mainInputLoading)
|
|
|
|
|
verify(!payPanel.bottomTextLoading)
|
|
|
|
|
verify(!receivePanel.mainInputLoading)
|
|
|
|
|
verify(!receivePanel.bottomTextLoading)
|
|
|
|
|
verify(!receivePanel.interactive)
|
|
|
|
|
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
|
|
|
|
|
compare(receivePanel.value, 0)
|
|
|
|
|
compare(receivePanel.rawValue, "0")
|
|
|
|
|
|
|
|
|
|
// edit some params to retry swap
|
2024-07-24 20:10:36 +00:00
|
|
|
|
root.swapFormData.fromTokenAmount = "0.00014"
|
2024-07-19 03:36:36 +00:00
|
|
|
|
waitForRendering(receivePanel)
|
|
|
|
|
formValuesChanged.wait()
|
|
|
|
|
|
|
|
|
|
// wait for fetchSuggestedRoutes function to be called
|
|
|
|
|
fetchSuggestedRoutesCalled.wait()
|
|
|
|
|
|
|
|
|
|
// verify loading state was set and no errors currently
|
|
|
|
|
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
|
|
|
|
|
|
|
|
|
|
// emit event that no routes were found due to not enough liquidity
|
2024-07-24 20:10:36 +00:00
|
|
|
|
txRoutes.uuid = root.swapAdaptor.uuid
|
2024-08-28 12:50:09 +00:00
|
|
|
|
root.swapStore.suggestedRoutesReady(txRoutes, Constants.routerErrorCodes.processor.errNotEnoughLiquidity, "errNotEnoughLiquidity")
|
2024-07-19 03:36:36 +00:00
|
|
|
|
|
|
|
|
|
// verify loading state was removed and that error was displayed
|
|
|
|
|
verify(!root.swapAdaptor.validSwapProposalReceived)
|
|
|
|
|
verify(!root.swapAdaptor.swapProposalLoading)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.toTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.totalFees, 0)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalNeeded, false)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.hasError, true)
|
|
|
|
|
verify(errorTag.visible)
|
|
|
|
|
verify(errorTag.text, qsTr("Not enough liquidity. Lower token amount or try again later."))
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.interactive)
|
2024-07-19 03:36:36 +00:00
|
|
|
|
compare(signButton.text, qsTr("Swap"))
|
|
|
|
|
|
|
|
|
|
// verfy input and output panels
|
|
|
|
|
verify(!payPanel.mainInputLoading)
|
|
|
|
|
verify(!payPanel.bottomTextLoading)
|
|
|
|
|
verify(!receivePanel.mainInputLoading)
|
|
|
|
|
verify(!receivePanel.bottomTextLoading)
|
|
|
|
|
verify(!receivePanel.interactive)
|
|
|
|
|
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
|
|
|
|
|
compare(receivePanel.value, 0)
|
|
|
|
|
compare(receivePanel.rawValue, "0")
|
|
|
|
|
|
|
|
|
|
// edit some params to retry swap
|
2024-07-24 20:10:36 +00:00
|
|
|
|
root.swapFormData.fromTokenAmount = "0.00015"
|
2024-07-19 03:36:36 +00:00
|
|
|
|
waitForRendering(receivePanel)
|
|
|
|
|
formValuesChanged.wait()
|
|
|
|
|
// verify loading state was set and no errors currently
|
|
|
|
|
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
|
|
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
|
// emit event with route that needs no approval
|
2024-07-24 20:10:36 +00:00
|
|
|
|
const txHasRouteNoApproval = root.dummySwapTransactionRoutes.txHasRouteNoApproval
|
|
|
|
|
txHasRouteNoApproval.uuid = root.swapAdaptor.uuid
|
|
|
|
|
root.swapStore.suggestedRoutesReady(txHasRouteNoApproval, "", "")
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
// verify loading state removed and data is displayed as expected on the Modal
|
2024-06-06 14:05:31 +00:00
|
|
|
|
verify(root.swapAdaptor.validSwapProposalReceived)
|
|
|
|
|
verify(!root.swapAdaptor.swapProposalLoading)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
|
2024-06-25 21:33:25 +00:00
|
|
|
|
compare(root.swapAdaptor.swapOutputData.toTokenAmount,
|
|
|
|
|
SQUtils.AmountsArithmetic.div(
|
2024-07-24 20:10:36 +00:00
|
|
|
|
SQUtils.AmountsArithmetic.fromString(txHasRouteNoApproval.amountToReceive),
|
2024-06-25 21:33:25 +00:00
|
|
|
|
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)
|
|
|
|
|
).toString())
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// calculation needed for total fees
|
2024-07-24 20:10:36 +00:00
|
|
|
|
let gasTimeEstimate = txHasRouteNoApproval.gasTimeEstimate
|
2024-06-06 14:05:31 +00:00
|
|
|
|
let totalTokenFeesInFiat = gasTimeEstimate.totalTokenFees * root.swapAdaptor.fromToken.marketDetails.currencyPrice.amount
|
|
|
|
|
let totalFees = root.swapAdaptor.currencyStore.getFiatValue(gasTimeEstimate.totalFeesInEth, Constants.ethToken) + totalTokenFeesInFiat
|
|
|
|
|
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.totalFees, totalFees)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalNeeded, false)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.hasError, false)
|
|
|
|
|
verify(!errorTag.visible)
|
|
|
|
|
verify(signButton.enabled)
|
|
|
|
|
compare(signButton.text, qsTr("Swap"))
|
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
// verfy input and output panels
|
|
|
|
|
waitForRendering(receivePanel)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
verify(payPanel.valueValid)
|
2024-08-30 09:16:40 +00:00
|
|
|
|
verify(!payPanel.mainInputLoading)
|
|
|
|
|
verify(!payPanel.bottomTextLoading)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
verify(!receivePanel.mainInputLoading)
|
|
|
|
|
verify(!receivePanel.bottomTextLoading)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(!receivePanel.interactive)
|
|
|
|
|
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
|
2024-07-24 20:10:36 +00:00
|
|
|
|
compare(receivePanel.value, root.swapStore.getWei2Eth(txHasRouteNoApproval.amountToReceive, root.swapAdaptor.toToken.decimals))
|
2024-08-14 13:04:28 +00:00
|
|
|
|
compare(receivePanel.rawValue,
|
|
|
|
|
SQUtils.AmountsArithmetic.times(
|
|
|
|
|
SQUtils.AmountsArithmetic.fromString(root.swapAdaptor.swapOutputData.toTokenAmount),
|
|
|
|
|
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)
|
|
|
|
|
).toFixed())
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
|
// edit some params to retry swap
|
2024-06-13 00:45:33 +00:00
|
|
|
|
root.swapFormData.fromTokenAmount = "0.012"
|
2024-07-01 12:03:08 +00:00
|
|
|
|
waitForRendering(receivePanel)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
formValuesChanged.wait()
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// wait for fetchSuggestedRoutes function to be called
|
2024-06-24 13:52:10 +00:00
|
|
|
|
fetchSuggestedRoutesCalled.wait()
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// verify loading state was set and no errors currently
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// emit event with route that needs no approval
|
|
|
|
|
let txRoutes2 = root.dummySwapTransactionRoutes.txHasRoutesApprovalNeeded
|
2024-07-24 20:10:36 +00:00
|
|
|
|
txRoutes2.uuid = root.swapAdaptor.uuid
|
2024-07-19 03:36:36 +00:00
|
|
|
|
root.swapStore.suggestedRoutesReady(txRoutes2, "", "")
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// verify loading state removed and data ius displayed as expected on the Modal
|
|
|
|
|
verify(root.swapAdaptor.validSwapProposalReceived)
|
|
|
|
|
verify(!root.swapAdaptor.swapProposalLoading)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
|
2024-06-25 21:33:25 +00:00
|
|
|
|
compare(root.swapAdaptor.swapOutputData.toTokenAmount, SQUtils.AmountsArithmetic.div(
|
2024-07-24 20:10:36 +00:00
|
|
|
|
SQUtils.AmountsArithmetic.fromString(txRoutes2.amountToReceive),
|
2024-06-25 21:33:25 +00:00
|
|
|
|
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)).toString())
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
|
|
// calculation needed for total fees
|
|
|
|
|
gasTimeEstimate = txRoutes2.gasTimeEstimate
|
|
|
|
|
totalTokenFeesInFiat = gasTimeEstimate.totalTokenFees * root.swapAdaptor.fromToken.marketDetails.currencyPrice.amount
|
|
|
|
|
totalFees = root.swapAdaptor.currencyStore.getFiatValue(gasTimeEstimate.totalFeesInEth, Constants.ethToken) + totalTokenFeesInFiat
|
|
|
|
|
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.totalFees, totalFees)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalNeeded, true)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.hasError, false)
|
|
|
|
|
verify(!errorTag.visible)
|
|
|
|
|
verify(signButton.enabled)
|
|
|
|
|
compare(signButton.text, qsTr("Approve %1").arg(root.swapAdaptor.fromToken.symbol))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
// verfy input and output panels
|
|
|
|
|
waitForRendering(receivePanel)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
verify(payPanel.valueValid)
|
2024-08-30 09:16:40 +00:00
|
|
|
|
verify(!payPanel.mainInputLoading)
|
|
|
|
|
verify(!payPanel.bottomTextLoading)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
verify(!receivePanel.mainInputLoading)
|
|
|
|
|
verify(!receivePanel.bottomTextLoading)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(!receivePanel.interactive)
|
|
|
|
|
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
|
2024-07-24 20:10:36 +00:00
|
|
|
|
compare(receivePanel.value, root.swapStore.getWei2Eth(txRoutes2.amountToReceive, root.swapAdaptor.toToken.decimals))
|
2024-08-14 13:04:28 +00:00
|
|
|
|
compare(receivePanel.rawValue,
|
|
|
|
|
SQUtils.AmountsArithmetic.times(
|
|
|
|
|
SQUtils.AmountsArithmetic.fromString(root.swapAdaptor.swapOutputData.toTokenAmount),
|
|
|
|
|
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)
|
|
|
|
|
).toFixed())
|
2024-06-13 00:45:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_pay_input_default() {
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const amountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
const bottomItemText = findChild(payPanel, "bottomItemText")
|
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
const holdingSelector = findChild(payPanel, "holdingSelector")
|
|
|
|
|
verify(!!holdingSelector)
|
|
|
|
|
const maxTagButton = findChild(payPanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
const tokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!tokenSelectorContentItemText)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
|
waitForRendering(controlUnderTest.contentItem)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
// check default states for the from input selector
|
|
|
|
|
compare(amountToSendInput.caption, qsTr("Pay"))
|
|
|
|
|
verify(amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
compare(amountToSendInput.text, "")
|
|
|
|
|
verify(amountToSendInput.cursorVisible)
|
|
|
|
|
compare(amountToSendInput.placeholderText, LocaleUtils.numberToLocaleString(0))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(bottomItemText.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(0, root.swapAdaptor.currencyStore.currentCurrency))
|
2024-06-18 22:51:49 +00:00
|
|
|
|
compare(holdingSelector.currentTokensKey, "")
|
2024-06-18 17:24:07 +00:00
|
|
|
|
compare(tokenSelectorContentItemText.text, qsTr("Select asset"))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(!maxTagButton.visible)
|
|
|
|
|
compare(payPanel.selectedHoldingId, "")
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(payPanel.value, 0)
|
|
|
|
|
compare(payPanel.rawValue, "0")
|
|
|
|
|
verify(!payPanel.valueValid)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_pay_input_presetValues() {
|
|
|
|
|
// try setting value before popup is launched and check values
|
|
|
|
|
let valueToExchange = 0.001
|
|
|
|
|
let valueToExchangeString = valueToExchange.toString()
|
|
|
|
|
root.swapFormData.selectedAccountAddress = swapAdaptor.nonWatchAccounts.get(0).address
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
|
|
|
|
root.swapFormData.fromTokensKey = "ETH"
|
|
|
|
|
root.swapFormData.fromTokenAmount = valueToExchangeString
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
let expectedToken = SQUtils.ModelUtils.getByKey(root.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", "ETH")
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
waitForItemPolished(controlUnderTest.contentItem)
|
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
2024-06-25 13:37:42 +00:00
|
|
|
|
waitForRendering(payPanel)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
const amountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
const bottomItemText = findChild(payPanel, "bottomItemText")
|
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
const holdingSelector = findChild(payPanel, "holdingSelector")
|
|
|
|
|
verify(!!holdingSelector)
|
|
|
|
|
const maxTagButton = findChild(payPanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
const tokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!tokenSelectorContentItemText)
|
|
|
|
|
const tokenSelectorIcon = findChild(payPanel, "tokenSelectorIcon")
|
|
|
|
|
verify(!!tokenSelectorIcon)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
compare(amountToSendInput.caption, qsTr("Pay"))
|
|
|
|
|
verify(amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
tryCompare(amountToSendInput, "text", valueToExchangeString)
|
|
|
|
|
compare(amountToSendInput.placeholderText, LocaleUtils.numberToLocaleString(0))
|
|
|
|
|
tryCompare(amountToSendInput, "cursorVisible", true)
|
2024-06-18 22:51:49 +00:00
|
|
|
|
tryCompare(bottomItemText, "text", root.swapAdaptor.currencyStore.formatCurrencyAmount(valueToExchange * expectedToken.marketDetails.currencyPrice.amount, root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
compare(holdingSelector.currentTokensKey, expectedToken.tokensKey)
|
2024-06-25 13:37:42 +00:00
|
|
|
|
tryCompare(tokenSelectorContentItemText, "text", expectedToken.symbol)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
compare(tokenSelectorIcon.image.source, Constants.tokenIcon(expectedToken.symbol))
|
|
|
|
|
verify(tokenSelectorIcon.visible)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(maxTagButton.visible)
|
2024-06-25 13:37:42 +00:00
|
|
|
|
compare(maxTagButton.text, qsTr("Max. %1").arg(expectedToken.currentBalance === 0 ? "0"
|
|
|
|
|
: root.swapAdaptor.currencyStore.formatCurrencyAmount(WalletUtils.calculateMaxSafeSendAmount(expectedToken.currentBalance, expectedToken.symbol), expectedToken.symbol, {noSymbol: true})))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(payPanel.selectedHoldingId, expectedToken.symbol)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(payPanel.value, valueToExchange)
|
|
|
|
|
compare(payPanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(valueToExchangeString, expectedToken.decimals).toString())
|
2024-06-25 13:37:42 +00:00
|
|
|
|
tryCompare(payPanel, "valueValid", expectedToken.currentBalance > 0)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_pay_input_wrong_value_1() {
|
|
|
|
|
let invalidValues = ["ABC", "0.0.010201", "12PASA", "100,9.01"]
|
|
|
|
|
for (let i =0; i<invalidValues.length; i++) {
|
|
|
|
|
let invalidValue = invalidValues[i]
|
|
|
|
|
// try setting value before popup is launched and check values
|
|
|
|
|
root.swapFormData.selectedAccountAddress = swapAdaptor.nonWatchAccounts.get(0).address
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
|
|
|
|
root.swapFormData.fromTokensKey =
|
|
|
|
|
root.swapFormData.fromTokenAmount = invalidValue
|
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const amountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
const bottomItemText = findChild(payPanel, "bottomItemText")
|
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
const holdingSelector = findChild(payPanel, "holdingSelector")
|
|
|
|
|
verify(!!holdingSelector)
|
|
|
|
|
const maxTagButton = findChild(payPanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
const tokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!tokenSelectorContentItemText)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
waitForRendering(payPanel)
|
|
|
|
|
|
|
|
|
|
compare(amountToSendInput.caption, qsTr("Pay"))
|
|
|
|
|
verify(amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
compare(amountToSendInput.placeholderText, LocaleUtils.numberToLocaleString(0))
|
|
|
|
|
verify(amountToSendInput.cursorVisible)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(bottomItemText.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(0, root.swapAdaptor.currencyStore.currentCurrency))
|
2024-06-18 22:51:49 +00:00
|
|
|
|
compare(holdingSelector.currentTokensKey, "")
|
2024-06-18 17:24:07 +00:00
|
|
|
|
compare(tokenSelectorContentItemText.text, "Select asset")
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(!maxTagButton.visible)
|
2024-06-18 22:51:49 +00:00
|
|
|
|
compare(payPanel.selectedHoldingId, "")
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(payPanel.value, 0)
|
|
|
|
|
compare(payPanel.rawValue, SQUtils.AmountsArithmetic.fromNumber("0", 0).toString())
|
|
|
|
|
verify(!payPanel.valueValid)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_pay_input_wrong_value_2() {
|
|
|
|
|
// try setting value before popup is launched and check values
|
|
|
|
|
let valueToExchange = 100
|
|
|
|
|
let valueToExchangeString = valueToExchange.toString()
|
|
|
|
|
root.swapFormData.selectedAccountAddress = swapAdaptor.nonWatchAccounts.get(0).address
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
|
|
|
|
root.swapFormData.fromTokensKey = "ETH"
|
|
|
|
|
root.swapFormData.fromTokenAmount = valueToExchangeString
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
let expectedToken = SQUtils.ModelUtils.getByKey(root.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", "ETH")
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
waitForItemPolished(controlUnderTest.contentItem)
|
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
2024-06-25 13:37:42 +00:00
|
|
|
|
waitForRendering(payPanel)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
const amountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
const bottomItemText = findChild(payPanel, "bottomItemText")
|
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
const holdingSelector = findChild(payPanel, "holdingSelector")
|
|
|
|
|
verify(!!holdingSelector)
|
|
|
|
|
const maxTagButton = findChild(payPanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
const tokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!tokenSelectorContentItemText)
|
|
|
|
|
const tokenSelectorIcon = findChild(payPanel, "tokenSelectorIcon")
|
|
|
|
|
verify(!!tokenSelectorIcon)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
compare(amountToSendInput.caption, qsTr("Pay"))
|
|
|
|
|
verify(amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
compare(amountToSendInput.text, valueToExchangeString)
|
|
|
|
|
compare(amountToSendInput.placeholderText, LocaleUtils.numberToLocaleString(0))
|
|
|
|
|
tryCompare(amountToSendInput, "cursorVisible", true)
|
2024-06-18 22:51:49 +00:00
|
|
|
|
tryCompare(bottomItemText, "text", root.swapAdaptor.currencyStore.formatCurrencyAmount(valueToExchange * expectedToken.marketDetails.currencyPrice.amount, root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
compare(holdingSelector.currentTokensKey, expectedToken.tokensKey)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
compare(tokenSelectorContentItemText.text, expectedToken.symbol)
|
|
|
|
|
compare(tokenSelectorIcon.image.source, Constants.tokenIcon(expectedToken.symbol))
|
|
|
|
|
verify(tokenSelectorIcon.visible)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(maxTagButton.visible)
|
2024-06-25 13:37:42 +00:00
|
|
|
|
compare(maxTagButton.text, qsTr("Max. %1").arg(expectedToken.currentBalance === 0 ? "0"
|
|
|
|
|
: root.swapAdaptor.currencyStore.formatCurrencyAmount(WalletUtils.calculateMaxSafeSendAmount(expectedToken.currentBalance, expectedToken.symbol), expectedToken.symbol, {noSymbol: true})))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(payPanel.selectedHoldingId, expectedToken.symbol)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(payPanel.value, valueToExchange)
|
|
|
|
|
compare(payPanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(valueToExchangeString, expectedToken.decimals).toString())
|
|
|
|
|
verify(!payPanel.valueValid)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_receive_input_default() {
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
const receivePanel = findChild(controlUnderTest, "receivePanel")
|
|
|
|
|
verify(!!receivePanel)
|
2024-07-31 13:02:10 +00:00
|
|
|
|
waitForRendering(receivePanel)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
const amountToSendInput = findChild(receivePanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
const bottomItemText = findChild(receivePanel, "bottomItemText")
|
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
const holdingSelector = findChild(receivePanel, "holdingSelector")
|
|
|
|
|
verify(!!holdingSelector)
|
|
|
|
|
const maxTagButton = findChild(receivePanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
const tokenSelectorContentItemText = findChild(receivePanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!tokenSelectorContentItemText)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
// check default states for the from input selector
|
|
|
|
|
compare(amountToSendInput.caption, qsTr("Receive"))
|
2024-08-14 13:04:28 +00:00
|
|
|
|
compare(amountToSendInput.text, "")
|
2024-06-13 00:45:33 +00:00
|
|
|
|
// TODO: this should be come interactive under https://github.com/status-im/status-desktop/issues/15095
|
|
|
|
|
verify(!amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(!amountToSendInput.cursorVisible)
|
|
|
|
|
compare(amountToSendInput.placeholderText, LocaleUtils.numberToLocaleString(0))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(bottomItemText.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(0, root.swapAdaptor.currencyStore.currentCurrency))
|
2024-07-16 11:30:48 +00:00
|
|
|
|
compare(holdingSelector.currentTokensKey, "STT")
|
|
|
|
|
compare(tokenSelectorContentItemText.text, "STT")
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(!maxTagButton.visible)
|
2024-07-16 11:30:48 +00:00
|
|
|
|
compare(receivePanel.selectedHoldingId, "STT")
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(receivePanel.value, 0)
|
|
|
|
|
compare(receivePanel.rawValue, "0")
|
|
|
|
|
verify(!receivePanel.valueValid)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_receive_input_presetValues() {
|
|
|
|
|
let valueToReceive = 0.001
|
|
|
|
|
let valueToReceiveString = valueToReceive.toString()
|
|
|
|
|
// try setting value before popup is launched and check values
|
|
|
|
|
root.swapFormData.selectedAccountAddress = swapAdaptor.nonWatchAccounts.get(0).address
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
|
|
|
|
root.swapFormData.toTokenKey = "STT"
|
|
|
|
|
root.swapFormData.toTokenAmount = valueToReceiveString
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
let expectedToken = SQUtils.ModelUtils.getByKey(root.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", "STT")
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
waitForItemPolished(controlUnderTest.contentItem)
|
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
const receivePanel = findChild(controlUnderTest, "receivePanel")
|
|
|
|
|
verify(!!receivePanel)
|
2024-06-25 13:37:42 +00:00
|
|
|
|
waitForRendering(receivePanel)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
const amountToSendInput = findChild(receivePanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
const bottomItemText = findChild(receivePanel, "bottomItemText")
|
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
const holdingSelector = findChild(receivePanel, "holdingSelector")
|
|
|
|
|
verify(!!holdingSelector)
|
|
|
|
|
const maxTagButton = findChild(receivePanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
const tokenSelectorContentItemText = findChild(receivePanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!tokenSelectorContentItemText)
|
|
|
|
|
const tokenSelectorIcon = findChild(receivePanel, "tokenSelectorIcon")
|
|
|
|
|
verify(!!tokenSelectorIcon)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
compare(amountToSendInput.caption, qsTr("Receive"))
|
|
|
|
|
// TODO: this should be come interactive under https://github.com/status-im/status-desktop/issues/15095
|
|
|
|
|
verify(!amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(!amountToSendInput.cursorVisible)
|
|
|
|
|
compare(amountToSendInput.text, valueToReceive.toLocaleString(Qt.locale(), 'f', -128))
|
|
|
|
|
compare(amountToSendInput.placeholderText, LocaleUtils.numberToLocaleString(0))
|
2024-06-18 22:51:49 +00:00
|
|
|
|
tryCompare(bottomItemText, "text", root.swapAdaptor.currencyStore.formatCurrencyAmount(valueToReceive * expectedToken.marketDetails.currencyPrice.amount, root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
compare(holdingSelector.currentTokensKey, expectedToken.tokensKey)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
compare(tokenSelectorContentItemText.text, expectedToken.symbol)
|
|
|
|
|
compare(tokenSelectorIcon.image.source, Constants.tokenIcon(expectedToken.symbol))
|
|
|
|
|
verify(tokenSelectorIcon.visible)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(!maxTagButton.visible)
|
|
|
|
|
compare(receivePanel.selectedHoldingId, expectedToken.symbol)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(receivePanel.value, valueToReceive)
|
|
|
|
|
compare(receivePanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(valueToReceiveString, expectedToken.decimals).toString())
|
|
|
|
|
verify(receivePanel.valueValid)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_max_button_click_with_preset_pay_value() {
|
|
|
|
|
// try setting value before popup is launched and check values
|
|
|
|
|
let valueToExchange = 0.2
|
|
|
|
|
let valueToExchangeString = valueToExchange.toString()
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
2024-06-18 22:51:49 +00:00
|
|
|
|
// The default is the first account. Setting the second account to test switching accounts
|
2024-06-13 00:45:33 +00:00
|
|
|
|
root.swapFormData.fromTokensKey = "ETH"
|
|
|
|
|
root.swapFormData.fromTokenAmount = valueToExchangeString
|
|
|
|
|
root.swapFormData.toTokenKey = "STT"
|
|
|
|
|
|
2024-06-24 13:52:10 +00:00
|
|
|
|
formValuesChanged.wait()
|
2024-06-18 22:51:49 +00:00
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
// The default is the first account. Setting the second account to test switching accounts
|
|
|
|
|
root.swapFormData.selectedAccountAddress = swapAdaptor.nonWatchAccounts.get(1).address
|
|
|
|
|
|
|
|
|
|
waitForItemPolished(controlUnderTest.contentItem)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const maxTagButton = findChild(payPanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
|
const amountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
const bottomItemText = findChild(payPanel, "bottomItemText")
|
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
let expectedToken = SQUtils.ModelUtils.getByKey(root.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", "ETH")
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
// check states for the pay input selector
|
|
|
|
|
verify(maxTagButton.visible)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
// FIXME: maxTagButton should be enabled after #15709 is resolved
|
2024-07-24 23:20:27 +00:00
|
|
|
|
verify(!maxTagButton.enabled);
|
2024-06-13 00:45:33 +00:00
|
|
|
|
let maxPossibleValue = WalletUtils.calculateMaxSafeSendAmount(expectedToken.currentBalance, expectedToken.symbol)
|
|
|
|
|
let truncmaxPossibleValue = Math.trunc(maxPossibleValue*100)/100
|
2024-06-18 22:51:49 +00:00
|
|
|
|
compare(maxTagButton.text, qsTr("Max. %1").arg(truncmaxPossibleValue === 0 ? Qt.locale().zeroDigit
|
|
|
|
|
: root.swapAdaptor.currencyStore.formatCurrencyAmount(truncmaxPossibleValue, expectedToken.symbol, {noSymbol: true})))
|
|
|
|
|
waitForItemPolished(amountToSendInput)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
tryCompare(amountToSendInput, "cursorVisible", true)
|
|
|
|
|
tryCompare(amountToSendInput, "text", valueToExchange.toLocaleString(Qt.locale(), 'f', -128))
|
|
|
|
|
compare(amountToSendInput.placeholderText, LocaleUtils.numberToLocaleString(0))
|
2024-06-18 22:51:49 +00:00
|
|
|
|
tryCompare(bottomItemText, "text", root.swapAdaptor.currencyStore.formatCurrencyAmount(valueToExchange * expectedToken.marketDetails.currencyPrice.amount, root.swapAdaptor.currencyStore.currentCurrency))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
2024-07-24 23:20:27 +00:00
|
|
|
|
if (maxTagButton.enabled) {
|
|
|
|
|
// click on max button
|
|
|
|
|
mouseClick(maxTagButton)
|
|
|
|
|
waitForItemPolished(payPanel)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
2024-07-24 23:20:27 +00:00
|
|
|
|
verify(amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(amountToSendInput.cursorVisible)
|
|
|
|
|
tryCompare(amountToSendInput, "text", maxPossibleValue === 0 ? "" : maxPossibleValue.toLocaleString(Qt.locale(), 'f', -128))
|
2024-07-24 23:20:27 +00:00
|
|
|
|
tryCompare(bottomItemText, "text", root.swapAdaptor.currencyStore.formatCurrencyAmount(maxPossibleValue * expectedToken.marketDetails.currencyPrice.amount, root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
}
|
2024-06-13 00:45:33 +00:00
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_max_button_click_with_no_preset_pay_value() {
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
2024-06-07 12:27:56 +00:00
|
|
|
|
// The default is the first account. Setting the second account to test switching accounts
|
|
|
|
|
root.swapFormData.selectedAccountAddress = swapAdaptor.nonWatchAccounts.get(1).address
|
|
|
|
|
formValuesChanged.clear()
|
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
// try setting value before popup is launched and check values
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
|
|
|
|
root.swapFormData.selectedAccountAddress = swapAdaptor.nonWatchAccounts.get(0).address
|
|
|
|
|
root.swapFormData.fromTokensKey = "ETH"
|
|
|
|
|
root.swapFormData.toTokenKey = "STT"
|
|
|
|
|
|
2024-06-24 13:52:10 +00:00
|
|
|
|
formValuesChanged.wait()
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const maxTagButton = findChild(payPanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
|
const amountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
const bottomItemText = findChild(payPanel, "bottomItemText")
|
|
|
|
|
verify(!!bottomItemText)
|
|
|
|
|
|
|
|
|
|
waitForRendering(payPanel)
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
let expectedToken = SQUtils.ModelUtils.getByKey(root.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", "ETH")
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
// check states for the pay input selector
|
|
|
|
|
verify(maxTagButton.visible)
|
|
|
|
|
let maxPossibleValue = WalletUtils.calculateMaxSafeSendAmount(expectedToken.currentBalance, expectedToken.symbol)
|
2024-06-25 13:37:42 +00:00
|
|
|
|
compare(maxTagButton.text, qsTr("Max. %1").arg(maxPossibleValue === 0 ? "0"
|
|
|
|
|
: root.swapAdaptor.currencyStore.formatCurrencyAmount(maxPossibleValue, expectedToken.symbol, {noSymbol: true})))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
verify(amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(amountToSendInput.cursorVisible)
|
|
|
|
|
compare(amountToSendInput.text, "")
|
|
|
|
|
compare(amountToSendInput.placeholderText, LocaleUtils.numberToLocaleString(0))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(bottomItemText.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(0, root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
|
|
|
|
|
// click on max button
|
|
|
|
|
maxTagButton.clicked()
|
2024-06-18 22:51:49 +00:00
|
|
|
|
waitForItemPolished(payPanel)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
2024-06-24 13:52:10 +00:00
|
|
|
|
formValuesChanged.wait()
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
verify(amountToSendInput.interactive)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(amountToSendInput.cursorVisible)
|
|
|
|
|
compare(amountToSendInput.text, maxPossibleValue > 0 ? maxPossibleValue.toLocaleString(Qt.locale(), 'f', -128) : "")
|
2024-06-18 22:51:49 +00:00
|
|
|
|
tryCompare(bottomItemText, "text", root.swapAdaptor.currencyStore.formatCurrencyAmount(maxPossibleValue * expectedToken.marketDetails.currencyPrice.amount, root.swapAdaptor.currencyStore.currentCurrency))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_pay_input_switching_accounts() {
|
|
|
|
|
// test with pay value being set and not set
|
|
|
|
|
let payValuesToTestWith = ["", "0.2"]
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
for (let index = 0; index < payValuesToTestWith.length; index++) {
|
2024-06-13 00:45:33 +00:00
|
|
|
|
let valueToExchangeString = payValuesToTestWith[index]
|
|
|
|
|
let valueToExchange = Number(valueToExchangeString)
|
|
|
|
|
|
|
|
|
|
// Asset chosen but no pay value set state -------------------------------------------------------------------------------
|
|
|
|
|
root.swapFormData.fromTokenAmount = valueToExchangeString
|
|
|
|
|
root.swapFormData.selectedAccountAddress = swapAdaptor.nonWatchAccounts.get(0).address
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
|
|
|
|
root.swapFormData.fromTokensKey = "ETH"
|
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const maxTagButton = findChild(payPanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
|
const amountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
|
|
|
|
|
|
|
|
|
const errorTag = findChild(controlUnderTest, "errorTag")
|
|
|
|
|
verify(!!errorTag)
|
|
|
|
|
|
|
|
|
|
for (let i=0; i< root.swapAdaptor.nonWatchAccounts.count; i++) {
|
|
|
|
|
root.swapFormData.selectedAccountAddress = root.swapAdaptor.nonWatchAccounts.get(i).address
|
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
waitForItemPolished(controlUnderTest.contentItem)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
|
2024-06-25 13:37:42 +00:00
|
|
|
|
let expectedToken = SQUtils.ModelUtils.getByKey(root.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", "ETH")
|
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
|
// check states for the pay input selector
|
2024-06-25 13:37:42 +00:00
|
|
|
|
tryCompare(maxTagButton, "visible", true)
|
2024-06-18 22:51:49 +00:00
|
|
|
|
let maxPossibleValue = WalletUtils.calculateMaxSafeSendAmount(expectedToken.currentBalance, expectedToken.symbol)
|
2024-06-25 13:37:42 +00:00
|
|
|
|
tryCompare(maxTagButton, "text", qsTr("Max. %1").arg(maxPossibleValue === 0 ? Qt.locale().zeroDigit : root.swapAdaptor.currencyStore.formatCurrencyAmount(maxPossibleValue, expectedToken.symbol, {noSymbol: true})))
|
2024-06-13 00:45:33 +00:00
|
|
|
|
compare(payPanel.selectedHoldingId, expectedToken.symbol)
|
2024-06-18 22:51:49 +00:00
|
|
|
|
tryCompare(payPanel, "valueValid", !!valueToExchangeString && valueToExchange <= maxPossibleValue)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
|
2024-06-18 22:51:49 +00:00
|
|
|
|
tryCompare(payPanel, "value", valueToExchange)
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(payPanel.rawValue, !!valueToExchangeString ? SQUtils.AmountsArithmetic.fromNumber(valueToExchangeString, expectedToken.decimals).toString(): "0")
|
|
|
|
|
|
|
|
|
|
// check if tag is visible in case amount entered to exchange is greater than max balance to send
|
|
|
|
|
let amountEnteredGreaterThanMaxBalance = valueToExchange > maxPossibleValue
|
|
|
|
|
let errortext = amountEnteredGreaterThanMaxBalance ? qsTr("Insufficient funds for swap"): qsTr("An error has occured, please try again")
|
|
|
|
|
compare(errorTag.visible, amountEnteredGreaterThanMaxBalance)
|
2024-07-24 20:10:36 +00:00
|
|
|
|
compare(errorTag.text, root.swapAdaptor.errorMessage)
|
|
|
|
|
compare(errorTag.buttonText, root.swapAdaptor.isTokenBalanceInsufficient ? qsTr("Buy crypto") : qsTr("Buy ETH"))
|
2024-06-14 11:34:20 +00:00
|
|
|
|
compare(errorTag.buttonVisible, amountEnteredGreaterThanMaxBalance)
|
2024-06-13 00:45:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
|
}
|
2024-06-18 17:24:07 +00:00
|
|
|
|
|
2024-07-24 00:33:26 +00:00
|
|
|
|
function test_modal_exchange_button_enabled_state_data() {
|
|
|
|
|
return [
|
|
|
|
|
{fromToken: "", fromTokenAmount: "", toToken: "", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "", fromTokenAmount: "", toToken: "STT", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "", toToken: "", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "", toToken: "STT", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "100", toToken: "STT", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "", toToken: "STT", toTokenAmount: "50"},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "100", toToken: "STT", toTokenAmount: "50"},
|
|
|
|
|
{fromToken: "", fromTokenAmount: "", toToken: "", toTokenAmount: "50"},
|
|
|
|
|
{fromToken: "", fromTokenAmount: "100", toToken: "", toTokenAmount: ""}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_exchange_button_enabled_state(data) {
|
|
|
|
|
const swapExchangeButton = findChild(controlUnderTest, "swapExchangeButton")
|
|
|
|
|
verify(!!swapExchangeButton)
|
|
|
|
|
|
|
|
|
|
root.swapFormData.fromTokensKey = data.fromToken
|
|
|
|
|
root.swapFormData.fromTokenAmount = data.fromTokenAmount
|
|
|
|
|
root.swapFormData.toTokenKey = data.toToken
|
|
|
|
|
root.swapFormData.toTokenAmount = data.toTokenAmount
|
|
|
|
|
|
|
|
|
|
tryCompare(swapExchangeButton, "enabled", !!data.fromToken || !!data.toToken)
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
|
function test_modal_exchange_button_default_state_data() {
|
|
|
|
|
return [
|
|
|
|
|
{fromToken: "", fromTokenAmount: "", toToken: "", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "", fromTokenAmount: "", toToken: "STT", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "", toToken: "", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "", toToken: "STT", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "100", toToken: "STT", toTokenAmount: ""},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "", toToken: "STT", toTokenAmount: "50"},
|
|
|
|
|
{fromToken: "ETH", fromTokenAmount: "100", toToken: "STT", toTokenAmount: "50"},
|
|
|
|
|
{fromToken: "", fromTokenAmount: "", toToken: "", toTokenAmount: "50"},
|
|
|
|
|
{fromToken: "", fromTokenAmount: "100", toToken: "", toTokenAmount: ""}
|
|
|
|
|
]
|
|
|
|
|
}
|
2024-06-18 17:24:07 +00:00
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
|
function test_modal_exchange_button_default_state(data) {
|
2024-06-18 17:24:07 +00:00
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const receivePanel = findChild(controlUnderTest, "receivePanel")
|
|
|
|
|
verify(!!receivePanel)
|
|
|
|
|
const swapExchangeButton = findChild(controlUnderTest, "swapExchangeButton")
|
|
|
|
|
verify(!!swapExchangeButton)
|
|
|
|
|
|
|
|
|
|
const payAmountToSendInput = findChild(payPanel, "amountToSendInput")
|
|
|
|
|
verify(!!payAmountToSendInput)
|
|
|
|
|
const payBottomItemText = findChild(payPanel, "bottomItemText")
|
|
|
|
|
verify(!!payBottomItemText)
|
|
|
|
|
const maxTagButton = findChild(payPanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
|
|
|
|
|
|
const receiveAmountToSendInput = findChild(receivePanel, "amountToSendInput")
|
|
|
|
|
verify(!!receiveAmountToSendInput)
|
|
|
|
|
const receiveBottomItemText = findChild(receivePanel, "bottomItemText")
|
|
|
|
|
verify(!!receiveBottomItemText)
|
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
|
root.swapAdaptor.reset()
|
2024-06-18 17:24:07 +00:00
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
|
// set network and address by default same
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
|
|
|
|
root.swapFormData.selectedAccountAddress = root.swapAdaptor.nonWatchAccounts.get(0).address
|
|
|
|
|
root.swapFormData.fromTokensKey = data.fromToken
|
|
|
|
|
root.swapFormData.fromTokenAmount = data.fromTokenAmount
|
|
|
|
|
root.swapFormData.toTokenKey = data.toToken
|
|
|
|
|
root.swapFormData.toTokenAmount = data.toTokenAmount
|
2024-06-18 17:24:07 +00:00
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
|
let expectedFromTokenIcon = !!root.swapAdaptor.fromToken && !!root.swapAdaptor.fromToken.symbol ?
|
|
|
|
|
Constants.tokenIcon(root.swapAdaptor.fromToken.symbol): ""
|
|
|
|
|
let expectedToTokenIcon = !!root.swapAdaptor.toToken && !!root.swapAdaptor.toToken.symbol ?
|
|
|
|
|
Constants.tokenIcon(root.swapAdaptor.toToken.symbol): ""
|
2024-06-18 17:24:07 +00:00
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
waitForRendering(payPanel)
|
|
|
|
|
waitForRendering(receivePanel)
|
2024-10-08 15:28:33 +00:00
|
|
|
|
waitForRendering(payAmountToSendInput)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
|
let paytokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!paytokenSelectorContentItemText)
|
|
|
|
|
let paytokenSelectorIcon = findChild(payPanel, "tokenSelectorIcon")
|
|
|
|
|
compare(!!data.fromToken , !!paytokenSelectorIcon)
|
|
|
|
|
let receivetokenSelectorContentItemText = findChild(receivePanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!receivetokenSelectorContentItemText)
|
|
|
|
|
let receivetokenSelectorIcon = findChild(receivePanel, "tokenSelectorIcon")
|
|
|
|
|
compare(!!data.toToken, !!receivetokenSelectorIcon)
|
|
|
|
|
|
|
|
|
|
// verify pay values
|
|
|
|
|
compare(payPanel.tokenKey, data.fromToken)
|
|
|
|
|
compare(payPanel.tokenAmount, data.fromTokenAmount)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(payAmountToSendInput.cursorVisible)
|
2024-07-03 16:29:30 +00:00
|
|
|
|
compare(paytokenSelectorContentItemText.text, !!root.swapFormData.fromTokensKey ? root.swapFormData.fromTokensKey : qsTr("Select asset"))
|
|
|
|
|
compare(!!data.fromToken , !!paytokenSelectorIcon)
|
|
|
|
|
if(!!paytokenSelectorIcon) {
|
|
|
|
|
compare(paytokenSelectorIcon.image.source, expectedFromTokenIcon)
|
|
|
|
|
}
|
|
|
|
|
verify(!!data.fromToken ? maxTagButton.visible: !maxTagButton.visible)
|
|
|
|
|
|
|
|
|
|
// verify receive values
|
|
|
|
|
compare(receivePanel.tokenKey, data.toToken)
|
|
|
|
|
compare(receivePanel.tokenAmount, data.toTokenAmount)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(!receiveAmountToSendInput.cursorVisible)
|
2024-07-03 16:29:30 +00:00
|
|
|
|
compare(receivetokenSelectorContentItemText.text, !!root.swapFormData.toTokenKey ? root.swapFormData.toTokenKey : qsTr("Select asset"))
|
|
|
|
|
if(!!receivetokenSelectorIcon) {
|
|
|
|
|
compare(receivetokenSelectorIcon.image.source, expectedToTokenIcon)
|
|
|
|
|
}
|
2024-06-18 17:24:07 +00:00
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
|
// click exchange button
|
|
|
|
|
swapExchangeButton.clicked()
|
|
|
|
|
waitForRendering(payPanel)
|
|
|
|
|
waitForRendering(receivePanel)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
|
// verify form values
|
|
|
|
|
compare(root.swapFormData.fromTokensKey, data.toToken)
|
|
|
|
|
compare(root.swapFormData.fromTokenAmount, data.toTokenAmount)
|
|
|
|
|
compare(root.swapFormData.toTokenKey, data.fromToken)
|
|
|
|
|
compare(root.swapFormData.toTokenAmount, data.fromTokenAmount)
|
|
|
|
|
|
|
|
|
|
paytokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!paytokenSelectorContentItemText)
|
|
|
|
|
paytokenSelectorIcon = findChild(payPanel, "tokenSelectorIcon")
|
|
|
|
|
compare(!!root.swapFormData.fromTokensKey , !!paytokenSelectorIcon)
|
|
|
|
|
receivetokenSelectorContentItemText = findChild(receivePanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!receivetokenSelectorContentItemText)
|
|
|
|
|
receivetokenSelectorIcon = findChild(receivePanel, "tokenSelectorIcon")
|
|
|
|
|
compare(!!root.swapFormData.toTokenKey, !!receivetokenSelectorIcon)
|
|
|
|
|
|
|
|
|
|
// verify pay values
|
|
|
|
|
compare(payPanel.tokenKey, data.toToken)
|
|
|
|
|
compare(payPanel.tokenAmount, data.toTokenAmount)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(payAmountToSendInput.cursorVisible)
|
2024-07-03 16:29:30 +00:00
|
|
|
|
compare(paytokenSelectorContentItemText.text, !!data.toToken ? data.toToken : qsTr("Select asset"))
|
|
|
|
|
if(!!paytokenSelectorIcon) {
|
|
|
|
|
compare(paytokenSelectorIcon.image.source, expectedToTokenIcon)
|
|
|
|
|
}
|
|
|
|
|
verify(!!data.toToken ? maxTagButton.visible: !maxTagButton.visible)
|
|
|
|
|
compare(maxTagButton.text, qsTr("Max. %1").arg(Qt.locale().zeroDigit))
|
2024-08-14 13:04:28 +00:00
|
|
|
|
compare(maxTagButton.type, (payAmountToSendInput.valid || !payAmountToSendInput.text) && maxTagButton.value > 0 ? StatusBaseButton.Type.Normal : StatusBaseButton.Type.Danger)
|
2024-07-03 16:29:30 +00:00
|
|
|
|
|
|
|
|
|
// verify receive values
|
|
|
|
|
compare(receivePanel.tokenKey, data.fromToken)
|
|
|
|
|
compare(receivePanel.tokenAmount, data.fromTokenAmount)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
verify(!receiveAmountToSendInput.cursorVisible)
|
2024-07-03 16:29:30 +00:00
|
|
|
|
compare(receivetokenSelectorContentItemText.text, !!data.fromToken ? data.fromToken : qsTr("Select asset"))
|
|
|
|
|
if(!!receivetokenSelectorIcon) {
|
|
|
|
|
compare(receivetokenSelectorIcon.image.source, expectedFromTokenIcon)
|
2024-06-18 17:24:07 +00:00
|
|
|
|
}
|
2024-07-03 16:29:30 +00:00
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
2024-06-18 17:24:07 +00:00
|
|
|
|
}
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
|
|
|
|
function test_approval_flow_button_states() {
|
|
|
|
|
root.swapAdaptor.reset()
|
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
const maxFeesValue = findChild(controlUnderTest, "maxFeesValue")
|
|
|
|
|
verify(!!maxFeesValue)
|
|
|
|
|
const signButton = findChild(controlUnderTest, "signButton")
|
|
|
|
|
verify(!!signButton)
|
|
|
|
|
const errorTag = findChild(controlUnderTest, "errorTag")
|
|
|
|
|
verify(!!errorTag)
|
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const receivePanel = findChild(controlUnderTest, "receivePanel")
|
|
|
|
|
verify(!!receivePanel)
|
|
|
|
|
|
|
|
|
|
// Check max fees values and sign button state when nothing is set
|
|
|
|
|
compare(maxFeesValue.text, "--")
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.interactive)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
verify(!errorTag.visible)
|
|
|
|
|
|
|
|
|
|
// set input values in the form correctly
|
|
|
|
|
root.swapFormData.fromTokensKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(0).key
|
|
|
|
|
formValuesChanged.wait()
|
|
|
|
|
root.swapFormData.toTokenKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(1).key
|
|
|
|
|
root.swapFormData.fromTokenAmount = "0.001"
|
|
|
|
|
formValuesChanged.wait()
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
|
|
|
|
|
formValuesChanged.wait()
|
|
|
|
|
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
|
|
|
|
|
formValuesChanged.wait()
|
|
|
|
|
|
|
|
|
|
// wait for fetchSuggestedRoutes function to be called
|
|
|
|
|
fetchSuggestedRoutesCalled.wait()
|
|
|
|
|
|
|
|
|
|
// verify loading state was set and no errors currently
|
|
|
|
|
verifyLoadingAndNoErrorsState(payPanel, receivePanel)
|
|
|
|
|
|
|
|
|
|
// emit event with route that needs no approval
|
|
|
|
|
let txRoutes = root.dummySwapTransactionRoutes.txHasRoutesApprovalNeeded
|
|
|
|
|
txRoutes.uuid = root.swapAdaptor.uuid
|
2024-07-19 03:36:36 +00:00
|
|
|
|
root.swapStore.suggestedRoutesReady(txRoutes, "", "")
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
|
|
|
|
// calculation needed for total fees
|
|
|
|
|
let gasTimeEstimate = txRoutes.gasTimeEstimate
|
|
|
|
|
let totalTokenFeesInFiat = gasTimeEstimate.totalTokenFees * root.swapAdaptor.fromToken.marketDetails.currencyPrice.amount
|
|
|
|
|
let totalFees = root.swapAdaptor.currencyStore.getFiatValue(gasTimeEstimate.totalFeesInEth, Constants.ethToken) + totalTokenFeesInFiat
|
|
|
|
|
let bestPath = SQUtils.ModelUtils.get(txRoutes.suggestedRoutes, 0, "route")
|
|
|
|
|
|
|
|
|
|
// verify loading state removed and data is displayed as expected on the Modal
|
|
|
|
|
verify(root.swapAdaptor.validSwapProposalReceived)
|
|
|
|
|
verify(!root.swapAdaptor.swapProposalLoading)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.toTokenAmount, SQUtils.AmountsArithmetic.div(
|
|
|
|
|
SQUtils.AmountsArithmetic.fromString(txRoutes.amountToReceive),
|
|
|
|
|
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)).toString())
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.totalFees, totalFees)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.hasError, false)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.estimatedTime, bestPath.estimatedTime)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.txProviderName, bestPath.bridgeName)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalNeeded, true)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalGasFees, bestPath.approvalGasFees.toString())
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalAmountRequired, bestPath.approvalAmountRequired)
|
|
|
|
|
compare(root.swapAdaptor.swapOutputData.approvalContractAddress, bestPath.approvalContractAddress)
|
|
|
|
|
|
|
|
|
|
verify(!errorTag.visible)
|
|
|
|
|
verify(signButton.enabled)
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.loadingWithText)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
compare(signButton.text, qsTr("Approve %1").arg(root.swapAdaptor.fromToken.symbol))
|
|
|
|
|
// TODO: note that there is a loss of precision as the approvalGasFees is currently passes as float from the backend and not string.
|
|
|
|
|
compare(maxFeesValue.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(
|
2024-07-10 22:03:37 +00:00
|
|
|
|
root.swapAdaptor.swapOutputData.totalFees,
|
2024-06-24 13:52:10 +00:00
|
|
|
|
root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
|
|
|
|
|
// simulate user click on approve button and approval failed
|
2024-09-13 11:39:12 +00:00
|
|
|
|
root.swapStore.transactionSent(root.swapAdaptor.uuid, root.swapFormData.selectedNetworkChainId, true, "0x877ffe47fc29340312611d4e833ab189fe4f4152b01cc9a05bb4125b81b2a89a", "")
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
|
|
|
|
verify(root.swapAdaptor.approvalPending)
|
|
|
|
|
verify(!root.swapAdaptor.approvalSuccessful)
|
|
|
|
|
verify(!errorTag.visible)
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.interactive)
|
|
|
|
|
verify(signButton.loadingWithText)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
compare(signButton.text, qsTr("Approving %1").arg(root.swapAdaptor.fromToken.symbol))
|
|
|
|
|
// TODO: note that there is a loss of precision as the approvalGasFees is currently passes as float from the backend and not string.
|
|
|
|
|
compare(maxFeesValue.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(
|
2024-07-10 22:03:37 +00:00
|
|
|
|
root.swapAdaptor.swapOutputData.totalFees,
|
2024-06-24 13:52:10 +00:00
|
|
|
|
root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
|
|
|
|
|
// simulate approval tx was unsuccessful
|
2024-09-13 11:39:12 +00:00
|
|
|
|
root.swapStore.transactionSendingComplete("0x877ffe47fc29340312611d4e833ab189fe4f4152b01cc9a05bb4125b81b2a89a", "Failed")
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
|
|
|
|
verify(!root.swapAdaptor.approvalPending)
|
|
|
|
|
verify(!root.swapAdaptor.approvalSuccessful)
|
|
|
|
|
verify(!errorTag.visible)
|
|
|
|
|
verify(signButton.enabled)
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.loadingWithText)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
compare(signButton.text, qsTr("Approve %1").arg(root.swapAdaptor.fromToken.symbol))
|
|
|
|
|
// TODO: note that there is a loss of precision as the approvalGasFees is currently passes as float from the backend and not string.
|
|
|
|
|
compare(maxFeesValue.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(
|
2024-07-10 22:03:37 +00:00
|
|
|
|
root.swapAdaptor.swapOutputData.totalFees,
|
2024-06-24 13:52:10 +00:00
|
|
|
|
root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
|
|
|
|
|
// simulate user click on approve button and successful approval tx made
|
|
|
|
|
signButton.clicked()
|
2024-09-13 11:39:12 +00:00
|
|
|
|
root.swapStore.transactionSent(root.swapAdaptor.uuid, root.swapFormData.selectedNetworkChainId, true, "0x877ffe47fc29340312611d4e833ab189fe4f4152b01cc9a05bb4125b81b2a89a", "")
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
|
|
|
|
verify(root.swapAdaptor.approvalPending)
|
|
|
|
|
verify(!root.swapAdaptor.approvalSuccessful)
|
|
|
|
|
verify(!errorTag.visible)
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.interactive)
|
|
|
|
|
verify(signButton.loadingWithText)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
compare(signButton.text, qsTr("Approving %1").arg(root.swapAdaptor.fromToken.symbol))
|
|
|
|
|
// TODO: note that there is a loss of precision as the approvalGasFees is currently passes as float from the backend and not string.
|
|
|
|
|
compare(maxFeesValue.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(
|
2024-07-10 22:03:37 +00:00
|
|
|
|
root.swapAdaptor.swapOutputData.totalFees,
|
2024-06-24 13:52:10 +00:00
|
|
|
|
root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
|
2024-09-13 11:39:12 +00:00
|
|
|
|
root.swapStore.transactionSendingComplete("0x877ffe47fc29340312611d4e833ab189fe4f4152b01cc9a05bb4125b81b2a89a", "Success")
|
|
|
|
|
|
2024-06-24 13:52:10 +00:00
|
|
|
|
// simulate approval tx was successful
|
|
|
|
|
signButton.clicked()
|
|
|
|
|
|
2024-09-13 11:39:12 +00:00
|
|
|
|
root.swapStore.transactionSendingComplete("0x877ffe47fc29340312611d4e833ab189fe4f4152b01cc9a05bb4125b81b2a89a", "Success")
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
|
|
|
|
verify(!root.swapAdaptor.approvalPending)
|
2024-09-13 11:39:12 +00:00
|
|
|
|
verify(root.swapAdaptor.approvalSuccessful)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
verify(!errorTag.visible)
|
2024-09-13 11:39:12 +00:00
|
|
|
|
verify(signButton.interactive)
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.loadingWithText)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
compare(signButton.text, qsTr("Swap"))
|
2024-09-13 11:39:12 +00:00
|
|
|
|
compare(maxFeesValue.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(
|
|
|
|
|
root.swapAdaptor.swapOutputData.totalFees,
|
|
|
|
|
root.swapAdaptor.currencyStore.currentCurrency))
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
|
|
|
|
let txHasRouteNoApproval = root.dummySwapTransactionRoutes.txHasRouteNoApproval
|
|
|
|
|
txHasRouteNoApproval.uuid = root.swapAdaptor.uuid
|
2024-07-19 03:36:36 +00:00
|
|
|
|
root.swapStore.suggestedRoutesReady(txHasRouteNoApproval, "", "")
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
|
|
|
|
verify(!root.swapAdaptor.approvalPending)
|
2024-09-13 11:39:12 +00:00
|
|
|
|
verify(root.swapAdaptor.approvalSuccessful)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
verify(!errorTag.visible)
|
|
|
|
|
verify(signButton.enabled)
|
2024-08-19 09:00:35 +00:00
|
|
|
|
verify(!signButton.loadingWithText)
|
2024-06-24 13:52:10 +00:00
|
|
|
|
compare(signButton.text, qsTr("Swap"))
|
|
|
|
|
compare(maxFeesValue.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(
|
|
|
|
|
root.swapAdaptor.swapOutputData.totalFees,
|
|
|
|
|
root.swapAdaptor.currencyStore.currentCurrency))
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
2024-07-03 16:29:30 +00:00
|
|
|
|
|
|
|
|
|
function test_modal_switching_networks_payPanel_data() {
|
|
|
|
|
return [
|
|
|
|
|
{key: "ETH"},
|
|
|
|
|
{key: "aave"}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_switching_networks_payPanel(data) {
|
|
|
|
|
// try setting value before popup is launched and check values
|
|
|
|
|
let valueToExchange = 1
|
|
|
|
|
let valueToExchangeString = valueToExchange.toString()
|
|
|
|
|
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
|
|
|
|
|
root.swapFormData.fromTokensKey = data.key
|
|
|
|
|
root.swapFormData.fromTokenAmount = valueToExchangeString
|
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
const payPanel = findChild(controlUnderTest, "payPanel")
|
|
|
|
|
verify(!!payPanel)
|
|
|
|
|
const maxTagButton = findChild(payPanel, "maxTagButton")
|
|
|
|
|
verify(!!maxTagButton)
|
|
|
|
|
const networkComboBox = findChild(controlUnderTest, "networkFilter")
|
|
|
|
|
verify(!!networkComboBox)
|
|
|
|
|
const errorTag = findChild(controlUnderTest, "errorTag")
|
|
|
|
|
verify(!!errorTag)
|
|
|
|
|
|
|
|
|
|
for (let i=0; i<networkComboBox.control.popup.contentItem.count; i++) {
|
|
|
|
|
// launch network selection popup
|
|
|
|
|
verify(!networkComboBox.control.popup.opened)
|
|
|
|
|
mouseClick(networkComboBox)
|
|
|
|
|
verify(networkComboBox.control.popup.opened)
|
|
|
|
|
|
|
|
|
|
let delegateUnderTest = networkComboBox.control.popup.contentItem.itemAtIndex(i)
|
|
|
|
|
verify(!!delegateUnderTest)
|
|
|
|
|
mouseClick(delegateUnderTest)
|
|
|
|
|
|
|
|
|
|
waitForRendering(payPanel)
|
|
|
|
|
|
|
|
|
|
const tokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!tokenSelectorContentItemText)
|
|
|
|
|
|
|
|
|
|
let fromTokenExistsOnNetwork = false
|
|
|
|
|
let expectedToken = SQUtils.ModelUtils.getByKey(root.tokenSelectorAdaptor.plainTokensBySymbolModel, "key", root.swapFormData.fromTokensKey)
|
|
|
|
|
if(!!expectedToken) {
|
|
|
|
|
fromTokenExistsOnNetwork = !!SQUtils.ModelUtils.getByKey(expectedToken.addressPerChain, "chainId",networkComboBox.selection[0], "address")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fromTokenExistsOnNetwork) {
|
|
|
|
|
verify(!maxTagButton.visible)
|
|
|
|
|
compare(payPanel.selectedHoldingId, "")
|
|
|
|
|
verify(!payPanel.valueValid)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
tryCompare(payPanel, "rawValue", "0")
|
2024-07-03 16:29:30 +00:00
|
|
|
|
verify(!errorTag.visible)
|
|
|
|
|
compare(tokenSelectorContentItemText.text, qsTr("Select asset"))
|
|
|
|
|
} else {
|
|
|
|
|
// check states for the pay input selector
|
|
|
|
|
verify(maxTagButton.visible)
|
|
|
|
|
let balancesModel = SQUtils.ModelUtils.getByKey(root.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", root.swapFormData.fromTokensKey, "balances")
|
|
|
|
|
let balanceEntry = SQUtils.ModelUtils.getFirstModelEntryIf(balancesModel, (balance) => {
|
|
|
|
|
return balance.account.toLowerCase() === root.swapFormData.selectedAccountAddress.toLowerCase() &&
|
|
|
|
|
balance.chainId === root.swapFormData.selectedNetworkChainId
|
|
|
|
|
})
|
|
|
|
|
let balance = SQUtils.AmountsArithmetic.toNumber(
|
|
|
|
|
SQUtils.AmountsArithmetic.fromString(balanceEntry.balance),
|
|
|
|
|
expectedToken.decimals)
|
|
|
|
|
|
|
|
|
|
let maxPossibleValue = WalletUtils.calculateMaxSafeSendAmount(balance, expectedToken.symbol)
|
|
|
|
|
compare(maxTagButton.text, qsTr("Max. %1").arg(
|
|
|
|
|
maxPossibleValue === 0 ? "0" :
|
|
|
|
|
root.swapAdaptor.currencyStore.formatCurrencyAmount(maxPossibleValue, expectedToken.symbol, {noSymbol: true})))
|
|
|
|
|
compare(payPanel.selectedHoldingId.toLowerCase(), expectedToken.symbol.toLowerCase())
|
|
|
|
|
compare(payPanel.valueValid, valueToExchange <= maxPossibleValue)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
tryCompare(payPanel, "rawValue", SQUtils.AmountsArithmetic.fromNumber(valueToExchangeString, expectedToken.decimals).toString())
|
2024-07-03 16:29:30 +00:00
|
|
|
|
compare(errorTag.visible, valueToExchange > maxPossibleValue)
|
|
|
|
|
if(errorTag.visible)
|
|
|
|
|
compare(errorTag.text, qsTr("Insufficient funds for swap"))
|
|
|
|
|
compare(tokenSelectorContentItemText.text, expectedToken.symbol)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_switching_networks_receivePanel_data() {
|
|
|
|
|
return [
|
|
|
|
|
{key: "aave"},
|
|
|
|
|
{key: "STT"}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_modal_switching_networks_receivePanel(data) {
|
|
|
|
|
// try setting value before popup is launched and check values
|
|
|
|
|
let valueToExchange = 1
|
|
|
|
|
let valueToExchangeString = valueToExchange.toString()
|
|
|
|
|
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
|
|
|
|
|
root.swapFormData.fromTokensKey = "ETH"
|
|
|
|
|
root.swapFormData.fromTokenAmount = valueToExchangeString
|
|
|
|
|
root.swapFormData.toTokenKey = data.key
|
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
const receivePanel = findChild(controlUnderTest, "receivePanel")
|
|
|
|
|
verify(!!receivePanel)
|
|
|
|
|
const networkComboBox = findChild(controlUnderTest, "networkFilter")
|
|
|
|
|
verify(!!networkComboBox)
|
|
|
|
|
|
|
|
|
|
for (let i=0; i<networkComboBox.control.popup.contentItem.count; i++) {
|
|
|
|
|
// launch network selection popup
|
|
|
|
|
verify(!networkComboBox.control.popup.opened)
|
|
|
|
|
mouseClick(networkComboBox)
|
|
|
|
|
verify(networkComboBox.control.popup.opened)
|
|
|
|
|
|
|
|
|
|
let delegateUnderTest = networkComboBox.control.popup.contentItem.itemAtIndex(i)
|
|
|
|
|
verify(!!delegateUnderTest)
|
|
|
|
|
mouseClick(delegateUnderTest)
|
|
|
|
|
|
|
|
|
|
waitForRendering(receivePanel)
|
|
|
|
|
|
|
|
|
|
const tokenSelectorContentItemText = findChild(receivePanel, "tokenSelectorContentItemText")
|
|
|
|
|
verify(!!tokenSelectorContentItemText)
|
|
|
|
|
|
|
|
|
|
let fromTokenExistsOnNetwork = false
|
|
|
|
|
let expectedToken = SQUtils.ModelUtils.getByKey(root.tokenSelectorAdaptor.plainTokensBySymbolModel, "key", root.swapFormData.toTokenKey)
|
|
|
|
|
if(!!expectedToken) {
|
|
|
|
|
fromTokenExistsOnNetwork = !!SQUtils.ModelUtils.getByKey(expectedToken.addressPerChain, "chainId", networkComboBox.selection[0], "address")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fromTokenExistsOnNetwork) {
|
|
|
|
|
compare(receivePanel.selectedHoldingId, "")
|
|
|
|
|
compare(tokenSelectorContentItemText.text, qsTr("Select asset"))
|
|
|
|
|
} else {
|
|
|
|
|
compare(receivePanel.selectedHoldingId.toLowerCase(), expectedToken.symbol.toLowerCase())
|
|
|
|
|
compare(tokenSelectorContentItemText.text, expectedToken.symbol)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeAndVerfyModal()
|
|
|
|
|
}
|
2024-07-03 22:08:03 +00:00
|
|
|
|
|
|
|
|
|
function test_auto_refresh() {
|
|
|
|
|
// Asset chosen but no pay value set state -------------------------------------------------------------------------------
|
|
|
|
|
root.swapFormData.fromTokenAmount = "0.0001"
|
|
|
|
|
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = 11155111
|
|
|
|
|
root.swapFormData.fromTokensKey = "ETH"
|
2024-07-25 10:23:00 +00:00
|
|
|
|
// for testing making it 1.2 seconds so as to not make tests running too long
|
|
|
|
|
root.swapFormData.autoRefreshTime = 1200
|
2024-07-03 22:08:03 +00:00
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
|
|
|
|
|
|
|
|
|
// check if fetchSuggestedRoutes called
|
|
|
|
|
fetchSuggestedRoutesCalled.wait()
|
|
|
|
|
|
|
|
|
|
// emit routes ready
|
|
|
|
|
let txHasRouteNoApproval = root.dummySwapTransactionRoutes.txHasRouteNoApproval
|
|
|
|
|
txHasRouteNoApproval.uuid = root.swapAdaptor.uuid
|
2024-07-19 03:36:36 +00:00
|
|
|
|
root.swapStore.suggestedRoutesReady(txHasRouteNoApproval, "", "")
|
2024-07-03 22:08:03 +00:00
|
|
|
|
}
|
2024-07-11 12:55:04 +00:00
|
|
|
|
|
|
|
|
|
function test_deleteing_input_characters_data() {
|
|
|
|
|
return [
|
2024-07-30 09:18:15 +00:00
|
|
|
|
{input: "0.001", locale: Qt.locale("en_US")},
|
|
|
|
|
{input: "1.00015", locale: Qt.locale("en_US")},
|
|
|
|
|
{input: "0.001", locale: Qt.locale("pl_PL")},
|
|
|
|
|
{input: "1.90015", locale: Qt.locale("pl_PL")},
|
2024-08-14 13:04:28 +00:00
|
|
|
|
{input: "100.000000000000151001", locale: Qt.locale("en_US")},
|
|
|
|
|
{input: "1.020000000000015101", locale: Qt.locale("en_US")}
|
2024-07-11 12:55:04 +00:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_deleteing_input_characters(data) {
|
|
|
|
|
root.swapFormData.fromTokenAmount = data.input
|
|
|
|
|
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = 11155111
|
|
|
|
|
root.swapFormData.fromTokensKey = "ETH"
|
|
|
|
|
|
|
|
|
|
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
|
|
|
|
|
verify(!!amountToSendInput)
|
2024-08-14 13:04:28 +00:00
|
|
|
|
amountToSendInput.locale = data.locale
|
2024-07-11 12:55:04 +00:00
|
|
|
|
|
|
|
|
|
// Launch popup
|
|
|
|
|
launchAndVerfyModal()
|
2024-08-14 13:04:28 +00:00
|
|
|
|
mouseClick(amountToSendInput)
|
2024-07-11 12:55:04 +00:00
|
|
|
|
waitForRendering(amountToSendInput)
|
|
|
|
|
|
2024-08-14 13:04:28 +00:00
|
|
|
|
let amountToTestInLocale = data.input.replace('.', amountToSendInput.locale.decimalPoint)
|
2024-07-11 12:55:04 +00:00
|
|
|
|
for(let i =0; i< data.input.length; i++) {
|
|
|
|
|
keyClick(Qt.Key_Backspace)
|
2024-07-30 09:18:15 +00:00
|
|
|
|
let expectedAmount = amountToTestInLocale.substring(0, data.input.length - (i+1))
|
2024-08-14 13:04:28 +00:00
|
|
|
|
tryCompare(amountToSendInput, "text", expectedAmount)
|
2024-07-11 12:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-25 10:23:00 +00:00
|
|
|
|
|
|
|
|
|
function test_no_auto_refresh_when_proposalLoading_or_approvalPending() {
|
|
|
|
|
fetchSuggestedRoutesCalled.clear()
|
|
|
|
|
root.swapFormData.fromTokenAmount = "0.0001"
|
|
|
|
|
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
|
|
|
|
|
root.swapFormData.selectedNetworkChainId = 11155111
|
|
|
|
|
root.swapFormData.fromTokensKey = "ETH"
|
|
|
|
|
// for testing making it 1.2 seconds so as to not make tests running too long
|
|
|
|
|
root.swapFormData.autoRefreshTime = 1200
|
|
|
|
|
|
|
|
|
|
// Launch popup
|
2024-09-13 11:39:12 +00:00
|
|
|
|
// launchAndVerfyModal()
|
2024-07-25 10:23:00 +00:00
|
|
|
|
|
2024-09-13 11:39:12 +00:00
|
|
|
|
// // check if fetchSuggestedRoutes called
|
|
|
|
|
// tryCompare(fetchSuggestedRoutesCalled, "count", 1)
|
2024-07-25 10:23:00 +00:00
|
|
|
|
|
|
|
|
|
// no new calls to fetch new proposal should be made as the proposal is still loading
|
2024-09-13 11:39:12 +00:00
|
|
|
|
// wait(root.swapFormData.autoRefreshTime*2)
|
|
|
|
|
// compare(fetchSuggestedRoutesCalled.count, 1)
|
2024-07-25 10:23:00 +00:00
|
|
|
|
|
2024-09-13 11:39:12 +00:00
|
|
|
|
// // emit routes ready
|
|
|
|
|
// let txHasRouteApproval = root.dummySwapTransactionRoutes.txHasRoutesApprovalNeeded
|
|
|
|
|
// txHasRouteApproval.uuid = root.swapAdaptor.uuid
|
|
|
|
|
// root.swapStore.suggestedRoutesReady(txHasRouteApproval, "", "")
|
2024-07-25 10:23:00 +00:00
|
|
|
|
|
2024-09-13 11:39:12 +00:00
|
|
|
|
// // now refresh can occur as no propsal or signing is pending
|
|
|
|
|
// tryCompare(fetchSuggestedRoutesCalled, "count", 2)
|
2024-07-25 10:23:00 +00:00
|
|
|
|
|
2024-09-13 11:39:12 +00:00
|
|
|
|
// // emit routes ready
|
|
|
|
|
// txHasRouteApproval.uuid = root.swapAdaptor.uuid
|
|
|
|
|
// root.swapStore.suggestedRoutesReady(txHasRouteApproval, "", "")
|
2024-07-25 10:23:00 +00:00
|
|
|
|
|
2024-09-13 11:39:12 +00:00
|
|
|
|
// verify(root.swapAdaptor.swapOutputData.approvalNeeded)
|
|
|
|
|
// verify(!root.swapAdaptor.approvalPending)
|
2024-07-25 10:23:00 +00:00
|
|
|
|
|
2024-09-13 11:39:12 +00:00
|
|
|
|
// // sign approval and check that auto refresh doesnt occur
|
|
|
|
|
// root.swapAdaptor.sendApproveTx()
|
2024-07-25 10:23:00 +00:00
|
|
|
|
|
2024-09-13 11:39:12 +00:00
|
|
|
|
// // no new calls to fetch new proposal should be made as the approval is pending
|
|
|
|
|
// verify(root.swapAdaptor.swapOutputData.approvalNeeded)
|
|
|
|
|
// verify(root.swapAdaptor.approvalPending)
|
|
|
|
|
// wait(root.swapFormData.autoRefreshTime*2)
|
|
|
|
|
// compare(fetchSuggestedRoutesCalled.count, 2)
|
2024-07-25 10:23:00 +00:00
|
|
|
|
}
|
2024-05-15 21:22:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|