fix(@desktop/wallet): Enabled unit tests previously marked as flaky and skipped

This commit is contained in:
Khushboo Mehta 2024-07-24 22:10:36 +02:00 committed by Khushboo-dev-cpp
parent 7d0e77d86f
commit 7af8ede0e2
3 changed files with 47 additions and 30 deletions

View File

@ -546,7 +546,6 @@ Item {
} }
function test_modal_swap_proposal_setup() { function test_modal_swap_proposal_setup() {
skip("Flaky test relying on wait()")
root.swapAdaptor.reset() root.swapAdaptor.reset()
// Launch popup // Launch popup
@ -587,7 +586,7 @@ Item {
formValuesChanged.wait() formValuesChanged.wait()
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
formValuesChanged.wait() formValuesChanged.wait()
root.swapFormData.selectedAccountAddress = root.swapAdaptor.nonWatchAccounts.get(0).address root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
formValuesChanged.wait() formValuesChanged.wait()
// wait for fetchSuggestedRoutes function to be called // wait for fetchSuggestedRoutes function to be called
@ -597,7 +596,9 @@ Item {
verifyLoadingAndNoErrorsState(payPanel, receivePanel) verifyLoadingAndNoErrorsState(payPanel, receivePanel)
// emit event that no routes were found with unknown error // emit event that no routes were found with unknown error
root.swapStore.suggestedRoutesReady(root.dummySwapTransactionRoutes.txNoRoutes, "NO_ROUTES", "No routes found") const txRoutes = root.dummySwapTransactionRoutes.txNoRoutes
txRoutes.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes, "NO_ROUTES", "No routes found")
// verify loading state was removed and that error was displayed // verify loading state was removed and that error was displayed
verify(!root.swapAdaptor.validSwapProposalReceived) verify(!root.swapAdaptor.validSwapProposalReceived)
@ -634,7 +635,8 @@ Item {
verifyLoadingAndNoErrorsState(payPanel, receivePanel) verifyLoadingAndNoErrorsState(payPanel, receivePanel)
// emit event that no routes were found due to not enough token balance // emit event that no routes were found due to not enough token balance
root.swapStore.suggestedRoutesReady(root.dummySwapTransactionRoutes.txNoRoutes, Constants.swap.errorCodes.errNotEnoughTokenBalance, "errNotEnoughTokenBalance") txRoutes.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes, Constants.swap.errorCodes.errNotEnoughTokenBalance, "errNotEnoughTokenBalance")
// verify loading state was removed and that error was displayed // verify loading state was removed and that error was displayed
verify(!root.swapAdaptor.validSwapProposalReceived) verify(!root.swapAdaptor.validSwapProposalReceived)
@ -671,7 +673,8 @@ Item {
verifyLoadingAndNoErrorsState(payPanel, receivePanel) verifyLoadingAndNoErrorsState(payPanel, receivePanel)
// emit event that no routes were found due to not enough eth balance // emit event that no routes were found due to not enough eth balance
root.swapStore.suggestedRoutesReady(root.dummySwapTransactionRoutes.txNoRoutes, Constants.swap.errorCodes.errNotEnoughNativeBalance, "errNotEnoughNativeBalance") txRoutes.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes, Constants.swap.errorCodes.errNotEnoughNativeBalance, "errNotEnoughNativeBalance")
// verify loading state was removed and that error was displayed // verify loading state was removed and that error was displayed
verify(!root.swapAdaptor.validSwapProposalReceived) verify(!root.swapAdaptor.validSwapProposalReceived)
@ -700,8 +703,6 @@ Item {
root.swapFormData.fromTokenAmount = "0.00013" root.swapFormData.fromTokenAmount = "0.00013"
waitForRendering(receivePanel) waitForRendering(receivePanel)
formValuesChanged.wait() formValuesChanged.wait()
// wait for fetchSuggestedRoutes function to be called
fetchSuggestedRoutesCalled.wait()
// wait for fetchSuggestedRoutes function to be called // wait for fetchSuggestedRoutes function to be called
fetchSuggestedRoutesCalled.wait() fetchSuggestedRoutesCalled.wait()
@ -710,7 +711,8 @@ Item {
verifyLoadingAndNoErrorsState(payPanel, receivePanel) verifyLoadingAndNoErrorsState(payPanel, receivePanel)
// emit event that no routes were found due to price timeout // emit event that no routes were found due to price timeout
root.swapStore.suggestedRoutesReady(root.dummySwapTransactionRoutes.txNoRoutes, Constants.swap.errorCodes.errPriceTimeout, "errPriceTimeout") txRoutes.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes, Constants.swap.errorCodes.errPriceTimeout, "errPriceTimeout")
// verify loading state was removed and that error was displayed // verify loading state was removed and that error was displayed
verify(!root.swapAdaptor.validSwapProposalReceived) verify(!root.swapAdaptor.validSwapProposalReceived)
@ -736,7 +738,7 @@ Item {
compare(receivePanel.rawValue, "0") compare(receivePanel.rawValue, "0")
// edit some params to retry swap // edit some params to retry swap
root.swapFormData.fromTokenAmount = "0.00013" root.swapFormData.fromTokenAmount = "0.00014"
waitForRendering(receivePanel) waitForRendering(receivePanel)
formValuesChanged.wait() formValuesChanged.wait()
@ -747,7 +749,8 @@ Item {
verifyLoadingAndNoErrorsState(payPanel, receivePanel) verifyLoadingAndNoErrorsState(payPanel, receivePanel)
// emit event that no routes were found due to not enough liquidity // emit event that no routes were found due to not enough liquidity
root.swapStore.suggestedRoutesReady(root.dummySwapTransactionRoutes.txNoRoutes, Constants.swap.errorCodes.errNotEnoughLiquidity, "errNotEnoughLiquidity") txRoutes.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes, Constants.swap.errorCodes.errNotEnoughLiquidity, "errNotEnoughLiquidity")
// verify loading state was removed and that error was displayed // verify loading state was removed and that error was displayed
verify(!root.swapAdaptor.validSwapProposalReceived) verify(!root.swapAdaptor.validSwapProposalReceived)
@ -773,15 +776,16 @@ Item {
compare(receivePanel.rawValue, "0") compare(receivePanel.rawValue, "0")
// edit some params to retry swap // edit some params to retry swap
root.swapFormData.fromTokenAmount = "0.00014" root.swapFormData.fromTokenAmount = "0.00015"
waitForRendering(receivePanel) waitForRendering(receivePanel)
formValuesChanged.wait() formValuesChanged.wait()
// verify loading state was set and no errors currently // verify loading state was set and no errors currently
verifyLoadingAndNoErrorsState(payPanel, receivePanel) verifyLoadingAndNoErrorsState(payPanel, receivePanel)
// emit event with route that needs no approval // emit event with route that needs no approval
let txRoutes = root.dummySwapTransactionRoutes.txHasRouteNoApproval const txHasRouteNoApproval = root.dummySwapTransactionRoutes.txHasRouteNoApproval
root.swapStore.suggestedRoutesReady(txRoutes, "", "") txHasRouteNoApproval.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txHasRouteNoApproval, "", "")
// verify loading state removed and data is displayed as expected on the Modal // verify loading state removed and data is displayed as expected on the Modal
verify(root.swapAdaptor.validSwapProposalReceived) verify(root.swapAdaptor.validSwapProposalReceived)
@ -789,12 +793,12 @@ Item {
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "") compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
compare(root.swapAdaptor.swapOutputData.toTokenAmount, compare(root.swapAdaptor.swapOutputData.toTokenAmount,
SQUtils.AmountsArithmetic.div( SQUtils.AmountsArithmetic.div(
SQUtils.AmountsArithmetic.fromString(txRoutes.amountToReceive), SQUtils.AmountsArithmetic.fromString(txHasRouteNoApproval.amountToReceive),
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals) SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)
).toString()) ).toString())
// calculation needed for total fees // calculation needed for total fees
let gasTimeEstimate = txRoutes.gasTimeEstimate let gasTimeEstimate = txHasRouteNoApproval.gasTimeEstimate
let totalTokenFeesInFiat = gasTimeEstimate.totalTokenFees * root.swapAdaptor.fromToken.marketDetails.currencyPrice.amount let totalTokenFeesInFiat = gasTimeEstimate.totalTokenFees * root.swapAdaptor.fromToken.marketDetails.currencyPrice.amount
let totalFees = root.swapAdaptor.currencyStore.getFiatValue(gasTimeEstimate.totalFeesInEth, Constants.ethToken) + totalTokenFeesInFiat let totalFees = root.swapAdaptor.currencyStore.getFiatValue(gasTimeEstimate.totalFeesInEth, Constants.ethToken) + totalTokenFeesInFiat
@ -812,7 +816,7 @@ Item {
verify(!receivePanel.bottomTextLoading) verify(!receivePanel.bottomTextLoading)
verify(!receivePanel.interactive) verify(!receivePanel.interactive)
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey) compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
compare(receivePanel.value, root.swapStore.getWei2Eth(txRoutes.amountToReceive, root.swapAdaptor.toToken.decimals)) compare(receivePanel.value, root.swapStore.getWei2Eth(txHasRouteNoApproval.amountToReceive, root.swapAdaptor.toToken.decimals))
compare(receivePanel.rawValue, SQUtils.AmountsArithmetic.fromNumber( compare(receivePanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(
LocaleUtils.numberFromLocaleString(root.swapAdaptor.swapOutputData.toTokenAmount, Qt.locale()), LocaleUtils.numberFromLocaleString(root.swapAdaptor.swapOutputData.toTokenAmount, Qt.locale()),
root.swapAdaptor.toToken.decimals).toString()) root.swapAdaptor.toToken.decimals).toString())
@ -830,6 +834,7 @@ Item {
// emit event with route that needs no approval // emit event with route that needs no approval
let txRoutes2 = root.dummySwapTransactionRoutes.txHasRoutesApprovalNeeded let txRoutes2 = root.dummySwapTransactionRoutes.txHasRoutesApprovalNeeded
txRoutes2.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes2, "", "") root.swapStore.suggestedRoutesReady(txRoutes2, "", "")
// verify loading state removed and data ius displayed as expected on the Modal // verify loading state removed and data ius displayed as expected on the Modal
@ -837,7 +842,7 @@ Item {
verify(!root.swapAdaptor.swapProposalLoading) verify(!root.swapAdaptor.swapProposalLoading)
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "") compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
compare(root.swapAdaptor.swapOutputData.toTokenAmount, SQUtils.AmountsArithmetic.div( compare(root.swapAdaptor.swapOutputData.toTokenAmount, SQUtils.AmountsArithmetic.div(
SQUtils.AmountsArithmetic.fromString(txRoutes.amountToReceive), SQUtils.AmountsArithmetic.fromString(txRoutes2.amountToReceive),
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)).toString()) SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)).toString())
// calculation needed for total fees // calculation needed for total fees
@ -859,7 +864,7 @@ Item {
verify(!receivePanel.bottomTextLoading) verify(!receivePanel.bottomTextLoading)
verify(!receivePanel.interactive) verify(!receivePanel.interactive)
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey) compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
compare(receivePanel.value, root.swapStore.getWei2Eth(txRoutes.amountToReceive, root.swapAdaptor.toToken.decimals)) compare(receivePanel.value, root.swapStore.getWei2Eth(txRoutes2.amountToReceive, root.swapAdaptor.toToken.decimals))
compare(receivePanel.rawValue, SQUtils.AmountsArithmetic.fromNumber( compare(receivePanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(
LocaleUtils.numberFromLocaleString(root.swapAdaptor.swapOutputData.toTokenAmount, Qt.locale()), LocaleUtils.numberFromLocaleString(root.swapAdaptor.swapOutputData.toTokenAmount, Qt.locale()),
root.swapAdaptor.toToken.decimals).toString()) root.swapAdaptor.toToken.decimals).toString())
@ -1250,7 +1255,6 @@ Item {
} }
function test_modal_pay_input_switching_accounts() { function test_modal_pay_input_switching_accounts() {
skip("flaky test")
// test with pay value being set and not set // test with pay value being set and not set
let payValuesToTestWith = ["", "0.2"] let payValuesToTestWith = ["", "0.2"]
@ -1298,8 +1302,8 @@ Item {
let amountEnteredGreaterThanMaxBalance = valueToExchange > maxPossibleValue let amountEnteredGreaterThanMaxBalance = valueToExchange > maxPossibleValue
let errortext = amountEnteredGreaterThanMaxBalance ? qsTr("Insufficient funds for swap"): qsTr("An error has occured, please try again") let errortext = amountEnteredGreaterThanMaxBalance ? qsTr("Insufficient funds for swap"): qsTr("An error has occured, please try again")
compare(errorTag.visible, amountEnteredGreaterThanMaxBalance) compare(errorTag.visible, amountEnteredGreaterThanMaxBalance)
compare(errorTag.text, errortext) compare(errorTag.text, root.swapAdaptor.errorMessage)
compare(errorTag.buttonText, qsTr("Buy crypto")) compare(errorTag.buttonText, root.swapAdaptor.isTokenBalanceInsufficient ? qsTr("Buy crypto") : qsTr("Buy ETH"))
compare(errorTag.buttonVisible, amountEnteredGreaterThanMaxBalance) compare(errorTag.buttonVisible, amountEnteredGreaterThanMaxBalance)
} }

View File

@ -88,6 +88,13 @@ StatusDialog {
} }
} }
// needed as the first time the value not loaded correctly without this Binding
Binding {
target: root.swapAdaptor
property: "amountEnteredGreaterThanBalance"
value: payPanel.amountEnteredGreaterThanBalance
}
Behavior on implicitHeight { Behavior on implicitHeight {
NumberAnimation { duration: 1000; easing.type: Easing.OutExpo; alwaysRunToEnd: true} NumberAnimation { duration: 1000; easing.type: Easing.OutExpo; alwaysRunToEnd: true}
} }
@ -226,9 +233,6 @@ StatusDialog {
root.swapInputParamsForm.fromTokenAmount = amount root.swapInputParamsForm.fromTokenAmount = amount
} }
} }
onAmountEnteredGreaterThanBalanceChanged: {
root.swapAdaptor.amountEnteredGreaterThanBalance = payPanel.amountEnteredGreaterThanBalance
}
} }
SwapInputPanel { SwapInputPanel {

View File

@ -155,19 +155,28 @@ QObject {
readonly property bool isRouteTokenBalanceInsufficient: root.validSwapProposalReceived && root.swapOutputData.errCode === Constants.swap.errorCodes.errNotEnoughTokenBalance readonly property bool isRouteTokenBalanceInsufficient: root.validSwapProposalReceived && root.swapOutputData.errCode === Constants.swap.errorCodes.errNotEnoughTokenBalance
readonly property bool isTokenBalanceInsufficient: { readonly property bool isTokenBalanceInsufficient: {
if (!!root.fromToken && !!root.fromToken.symbol) {
return (root.amountEnteredGreaterThanBalance || isRouteTokenBalanceInsufficient) && return (root.amountEnteredGreaterThanBalance || isRouteTokenBalanceInsufficient) &&
root.fromToken.symbol !== Constants.ethToken root.fromToken.symbol !== Constants.ethToken
} }
return false
}
readonly property bool isEthBalanceInsufficient: { readonly property bool isEthBalanceInsufficient: {
if (!!root.fromToken && !!root.fromToken.symbol) {
return (root.amountEnteredGreaterThanBalance && root.fromToken.symbol === Constants.ethToken) || return (root.amountEnteredGreaterThanBalance && root.fromToken.symbol === Constants.ethToken) ||
isRouteEthBalanceInsufficient isRouteEthBalanceInsufficient
} }
return false
}
readonly property bool isBalanceInsufficientForSwap: { readonly property bool isBalanceInsufficientForSwap: {
if (!!root.fromToken && !!root.fromToken.symbol) {
return (root.amountEnteredGreaterThanBalance && root.fromToken.symbol === Constants.ethToken) || return (root.amountEnteredGreaterThanBalance && root.fromToken.symbol === Constants.ethToken) ||
(isTokenBalanceInsufficient && root.fromToken.symbol !== Constants.ethToken) (isTokenBalanceInsufficient && root.fromToken.symbol !== Constants.ethToken)
} }
return false
}
readonly property bool isBalanceInsufficientForFees: !isBalanceInsufficientForSwap && isEthBalanceInsufficient readonly property bool isBalanceInsufficientForFees: !isBalanceInsufficientForSwap && isEthBalanceInsufficient