Files
lez-programs/apps/shared/wallet/tests/qml/tst_ProgramAccountSelector.qml
T
r4bbit 4cb7c7e51c refactor(amm): drop the Raw suffix from amount/value field names
The `*Raw` suffix on the module's amount/price/balance/LP fields was
redundant — every such field is already a base-unit integer, and there was
no formatted sibling to disambiguate from. Drop it across the whole wire
contract in lockstep: the amm_ffi request/response fields (snake_case
`amount_in_raw` → `amount_in`, serde `rename_all="camelCase"` keeps the JSON
keys mapped), the C++ module API, the QtRO `.rep`, the QML/app that consumes
it, the mjs tests, and the module README.

Examples: expectedOutRaw→expectedOut, minReceivedRaw→minReceived,
maxInRaw→maxIn, requiredInRaw→requiredIn, priceRaw→price, reserve{A,B}Raw→
reserve{A,B}, amount{In,Out}Raw→amount{In,Out}, expectedLpRaw→expectedLp,
lpAmountRaw→lpAmount, {max,min,minimum,actual}Amount{A,B}Raw, minimumLpRaw,
minLpRaw, selectedBalance*Raw, totalSupplyRaw, quote*Raw. This also unifies a
pre-existing inconsistency where resolvePoolAccount already emitted `reserveA`
and resolveTokens already emitted `balance`.

Kept where a formatted UI sibling of the same base name exists, so `Raw`
still disambiguates the base-unit value: amountARaw / amountBRaw (vs the
user-input `amountA`/`amountB`), balanceRaw (vs display `balance`), and
initialPriceRaw (vs formatted `initialPrice`). Also kept the format-boundary
helpers formatRaw / rawLpText / probeRaw / displayRaw / displayQuoteRaw /
boundRaw.

BREAKING: the `amm_module` public API field names change (logoscore /
Basecamp / QtRO consumers must update).
2026-08-21 08:11:58 +02:00

153 lines
5.5 KiB
QML

import QtQuick
import QtTest
import Logos.Wallet as Wallet
Item {
id: root
width: 480
height: 320
readonly property var holdingA: ({
"accountId": "holding-a",
"accountType": "TokenHolding",
"definitionId": "token-a",
"balanceRaw": "120"
})
readonly property var holdingB: ({
"accountId": "holding-b",
"accountType": "TokenHolding",
"state": {
"definitionId": "token-a",
"balanceRaw": "80"
}
})
readonly property var otherToken: ({
"accountId": "holding-c",
"accountType": "TokenHolding",
"definitionId": "token-b",
"balanceRaw": "50"
})
readonly property var otherType: ({
"accountId": "pool-a",
"accountType": "Pool",
"definitionId": "token-a"
})
Component {
id: selectorComponent
Wallet.ProgramAccountSelector {
width: 260
accountType: "TokenHolding"
stateField: "definitionId"
stateValue: "token-a"
}
}
TestCase {
name: "ProgramAccountSelector"
when: windowShown
function test_inputNoFunds() {
const selector = createTemporaryObject(selectorComponent, root, {
"sourceModel": [root.otherToken, root.otherType],
"selectionMode": Wallet.ProgramAccountSelector.Input
})
verify(!!selector, "Component exists")
tryCompare(selector, "showEmptyInput", true)
compare(selector.showCombo, false)
compare(selector.hasFunds, false)
compare(selector.ready, false)
compare(selector.selectedAccountId, "")
}
function test_inputSingleHoldingAutoSelectsWithoutCombo() {
const selector = createTemporaryObject(selectorComponent, root, {
"sourceModel": [root.holdingA, root.otherToken],
"selectionMode": Wallet.ProgramAccountSelector.Input
})
verify(!!selector, "Component exists")
tryCompare(selector, "selectedAccountId", "holding-a")
compare(selector.showCombo, false)
compare(selector.hasFunds, true)
compare(selector.ready, true)
compare(selector.selectedBalance, "120")
}
function test_inputMultipleHoldingsRequiresSelection() {
const selector = createTemporaryObject(selectorComponent, root, {
"sourceModel": [root.holdingA, root.holdingB],
"selectionMode": Wallet.ProgramAccountSelector.Input
})
verify(!!selector, "Component exists")
tryCompare(selector, "showCombo", true)
compare(selector.matchingAccounts.length, 2)
compare(selector.ready, false)
selector.setSelection("holding-b", false)
compare(selector.selectedAccountId, "holding-b")
compare(selector.selectedBalance, "80")
compare(selector.ready, true)
}
function test_outputNoHoldingSelectsCreateNew() {
const selector = createTemporaryObject(selectorComponent, root, {
"sourceModel": [],
"selectionMode": Wallet.ProgramAccountSelector.Output
})
verify(!!selector, "Component exists")
tryCompare(selector, "createNewSelected", true)
compare(selector.showCombo, true)
compare(selector.choices.length, 1)
compare(selector.ready, true)
}
function test_outputSingleHoldingOffersExistingAndCreateNew() {
const selector = createTemporaryObject(selectorComponent, root, {
"sourceModel": [root.holdingA],
"selectionMode": Wallet.ProgramAccountSelector.Output
})
verify(!!selector, "Component exists")
tryCompare(selector, "selectedAccountId", "holding-a")
compare(selector.choices.length, 2)
compare(selector.createNewSelected, false)
compare(selector.ready, true)
selector.setSelection("", true)
compare(selector.selectedAccountId, "")
compare(selector.createNewSelected, true)
compare(selector.ready, true)
}
function test_outputMultipleHoldingsRequiresDestination() {
const selector = createTemporaryObject(selectorComponent, root, {
"sourceModel": [root.holdingA, root.holdingB],
"selectionMode": Wallet.ProgramAccountSelector.Output
})
verify(!!selector, "Component exists")
tryCompare(selector, "showCombo", true)
compare(selector.choices.length, 3)
compare(selector.selectedAccountId, "")
compare(selector.createNewSelected, false)
compare(selector.ready, false)
}
function test_matchesNumericZeroState() {
const selector = createTemporaryObject(selectorComponent, root, {
"sourceModel": [{
"accountId": "zero-state",
"accountType": "TokenHolding",
"state": { "version": 0 }
}],
"stateField": "version",
"stateValue": 0,
"selectionMode": Wallet.ProgramAccountSelector.Input
})
verify(!!selector, "Component exists")
tryCompare(selector, "selectedAccountId", "zero-state")
compare(selector.ready, true)
}
}
}