fix(@desktop/wallet): [SwapModal] Fix for flaky tests and remove the skip flag

fixes #15272
This commit is contained in:
Khushboo Mehta 2024-06-25 23:33:25 +02:00 committed by Khushboo-dev-cpp
parent 13815bf81c
commit 64efd47805
4 changed files with 22 additions and 21 deletions

View File

@ -348,8 +348,9 @@ Item {
tryCompare(amountToSendInput.input, "text", modelItemToTest.currentBalance === 0 ? "" : maxTagButton.maxSafeValueAsString)
compare(controlUnderTest.value, maxTagButton.maxSafeValue)
verify(modelItemToTest.currentBalance === 0 ? !controlUnderTest.valueValid : controlUnderTest.valueValid)
const marketPrice = !!amountToSendInput.selectedHolding ? amountToSendInput.selectedHolding.marketDetails.currencyPrice.amount : 0
compare(bottomItemText.text, d.adaptor.formatCurrencyAmount(
maxTagButton.maxSafeValue * amountToSendInput.selectedHolding.marketDetails.currencyPrice.amount,
maxTagButton.maxSafeValue * marketPrice,
d.adaptor.currencyStore.currentCurrency))
amountToSendInput.input.input.edit.clear()
@ -402,8 +403,9 @@ Item {
waitForItemPolished(controlUnderTest)
compare(amountToSendInput.input.text, "5.42")
const marketPrice = !!amountToSendInput.selectedHolding ? amountToSendInput.selectedHolding.marketDetails.currencyPrice.amount : 0
tryCompare(bottomItemText, "text", d.adaptor.formatCurrencyAmount(
numberTested * amountToSendInput.selectedHolding.marketDetails.currencyPrice.amount,
numberTested * marketPrice,
d.adaptor.currencyStore.currentCurrency))
compare(controlUnderTest.value, numberTested)
compare(controlUnderTest.rawValue, AmountsArithmetic.fromNumber(amountToSendInput.input.text, modelItemToTest.decimals).toString())

View File

@ -56,18 +56,13 @@ Item {
readonly property var tokenSelectorAdaptor: TokenSelectorViewAdaptor {
assetsModel: swapAdaptor.walletAssetsStore.groupedAccountAssetsModel
flatNetworksModel: swapStore.flatNetworks
currentCurrency: swapAdaptor.currencyStore
currentCurrency: swapAdaptor.currencyStore.currentCurrency
enabledChainIds: !!root.swapFormData && root.swapFormData.selectedNetworkChainId !== - 1 ? [root.swapFormData.selectedNetworkChainId] : []
accountAddress: !!root.swapFormData && root.swapFormData.selectedAccountAddress
}
property SwapInputParamsForm swapFormData: null
Component {
id: swapFormDataComponent
SwapInputParamsForm { }
}
property SwapInputParamsForm swapFormData: SwapInputParamsForm { }
Component {
id: componentUnderTest
@ -92,7 +87,6 @@ Item {
// helper functions -------------------------------------------------------------
function init() {
root.swapFormData = createTemporaryObject(swapFormDataComponent, root)
swapAdaptor.swapFormData = root.swapFormData
controlUnderTest = createTemporaryObject(componentUnderTest, root, { swapInputParamsForm: root.swapFormData})
}
@ -213,7 +207,6 @@ Item {
}
function test_floating_header_list_items() {
skip("Randomly failing")
// Launch popup and account selection modal
launchAndVerfyModal()
const accountsModalHeader = getAndVerifyAccountsModalHeader()
@ -221,6 +214,7 @@ Item {
const comboBoxList = findChild(controlUnderTest, "accountSelectorList")
verify(!!comboBoxList)
waitForRendering(comboBoxList)
for(let i =0; i< comboBoxList.model.count; i++) {
let delegateUnderTest = comboBoxList.itemAtIndex(i)
@ -515,7 +509,6 @@ Item {
}
function test_modal_swap_proposal_setup() {
skip("Randomly failing")
root.swapAdaptor.reset()
// Launch popup
@ -610,7 +603,11 @@ Item {
verify(root.swapAdaptor.validSwapProposalReceived)
verify(!root.swapAdaptor.swapProposalLoading)
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
compare(root.swapAdaptor.swapOutputData.toTokenAmount, root.swapStore.getWei2Eth(txRoutes.amountToReceive, root.swapAdaptor.toToken.decimals).toString())
compare(root.swapAdaptor.swapOutputData.toTokenAmount,
SQUtils.AmountsArithmetic.div(
SQUtils.AmountsArithmetic.fromString(txRoutes.amountToReceive),
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)
).toString())
// calculation needed for total fees
let gasTimeEstimate = txRoutes.gasTimeEstimate
@ -633,7 +630,9 @@ Item {
verify(!receivePanel.interactive)
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
compare(receivePanel.value, root.swapStore.getWei2Eth(txRoutes.amountToReceive, root.swapAdaptor.toToken.decimals))
compare(receivePanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(root.swapAdaptor.swapOutputData.toTokenAmount, root.swapAdaptor.toToken.decimals).toString())
compare(receivePanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(
LocaleUtils.numberFromLocaleString(root.swapAdaptor.swapOutputData.toTokenAmount, Qt.locale()),
root.swapAdaptor.toToken.decimals).toString())
// edit some params to retry swap
root.swapFormData.fromTokenAmount = "0.012"
@ -653,7 +652,9 @@ Item {
verify(root.swapAdaptor.validSwapProposalReceived)
verify(!root.swapAdaptor.swapProposalLoading)
compare(root.swapAdaptor.swapOutputData.fromTokenAmount, "")
compare(root.swapAdaptor.swapOutputData.toTokenAmount, root.swapStore.getWei2Eth(txRoutes2.amountToReceive, root.swapAdaptor.toToken.decimals).toString())
compare(root.swapAdaptor.swapOutputData.toTokenAmount, SQUtils.AmountsArithmetic.div(
SQUtils.AmountsArithmetic.fromString(txRoutes.amountToReceive),
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.toToken.decimals)).toString())
// calculation needed for total fees
gasTimeEstimate = txRoutes2.gasTimeEstimate
@ -676,7 +677,9 @@ Item {
verify(!receivePanel.interactive)
compare(receivePanel.selectedHoldingId, root.swapFormData.toTokenKey)
compare(receivePanel.value, root.swapStore.getWei2Eth(txRoutes.amountToReceive, root.swapAdaptor.toToken.decimals))
compare(receivePanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(root.swapAdaptor.swapOutputData.toTokenAmount, root.swapAdaptor.toToken.decimals).toString())
compare(receivePanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(
LocaleUtils.numberFromLocaleString(root.swapAdaptor.swapOutputData.toTokenAmount, Qt.locale()),
root.swapAdaptor.toToken.decimals).toString())
}
function test_modal_pay_input_default() {

View File

@ -42,7 +42,6 @@ ListModel {
}
],
preferredSharingChainIds: "5:420:421613",
colorizedChainPrefixes: "eth:opt",
currencyBalance: ({amount: 1.25,
symbol: "USD",
displayDecimals: 4,
@ -69,7 +68,6 @@ ListModel {
}
],
preferredSharingChainIds: "5:420:421613",
colorizedChainPrefixes: "eth:opt",
currencyBalance: ({amount: 10,
symbol: "USD",
displayDecimals: 4,
@ -105,7 +103,6 @@ ListModel {
}
],
preferredSharingChainIds: "5:420:421613",
colorizedChainPrefixes: "eth:opt",
currencyBalance: ({amount: 110.05,
symbol: "USD",
displayDecimals: 4,
@ -149,7 +146,6 @@ ListModel {
}
],
preferredSharingChainIds: "5:420:421613",
colorizedChainPrefixes: "eth:opt",
currencyBalance: ({amount: 999,
symbol: "USD",
displayDecimals: 4,

View File

@ -107,7 +107,7 @@ QObject {
}
function processAccountBalance(address) {
if (!root.swapFormData.fromTokensKey) {
if (!root.swapFormData.fromTokensKey || !root.fromToken) {
return null
}