-
Notifications
You must be signed in to change notification settings - Fork 979
fix(wallet): Transaction Details status not updated automatically on iOS #22405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
ios/brave-ios/Tests/BraveWalletTests/TransactionDetailsStoreTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// Copyright 2021 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import BraveCore | ||
import Combine | ||
import XCTest | ||
|
||
@testable import BraveWallet | ||
|
||
class TransactionDetailsStoreTests: XCTestCase { | ||
|
||
private var cancellables: Set<AnyCancellable> = [] | ||
|
||
private func setupServices() -> ( | ||
BraveWalletKeyringService, | ||
BraveWalletBraveWalletService, | ||
BraveWalletJsonRpcService, | ||
BraveWalletAssetRatioService, | ||
BraveWalletBlockchainRegistry, | ||
BraveWalletTxService, | ||
BraveWalletSolanaTxManagerProxy, | ||
IpfsAPI, | ||
WalletUserAssetManagerType | ||
) { | ||
let keyringService = BraveWallet.TestKeyringService() | ||
keyringService._allAccounts = { completion in | ||
let allAccounts = [BraveWallet.AccountInfo.previewAccount] | ||
let allAccountsInfo: BraveWallet.AllAccountsInfo = .init( | ||
accounts: allAccounts, | ||
selectedAccount: allAccounts.first, | ||
ethDappSelectedAccount: allAccounts.first(where: { $0.coin == .eth }), | ||
solDappSelectedAccount: allAccounts.first(where: { $0.coin == .sol }) | ||
) | ||
completion(allAccountsInfo) | ||
} | ||
let walletService = BraveWallet.TestBraveWalletService() | ||
walletService._defaultBaseCurrency = { $0(CurrencyCode.usd.code) } | ||
let rpcService = BraveWallet.TestJsonRpcService() | ||
rpcService._allNetworks = { $1([.mockSepolia]) } | ||
let assetRatioService = BraveWallet.TestAssetRatioService() | ||
assetRatioService._price = { _, _, _, completion in | ||
let mockAssetPrices: [BraveWallet.AssetPrice] = [ | ||
.init(fromAsset: "eth", toAsset: "usd", price: "3059.99", assetTimeframeChange: "-57.23") | ||
] | ||
completion(true, mockAssetPrices) | ||
} | ||
let blockchainRegistry = BraveWallet.TestBlockchainRegistry() | ||
blockchainRegistry._allTokens = { _, _, completion in | ||
completion([]) | ||
} | ||
let txService = BraveWallet.TestTxService() | ||
txService._addObserver = { _ in } | ||
let solTxManagerProxy = BraveWallet.TestSolanaTxManagerProxy() | ||
let userAssetManager = TestableWalletUserAssetManager() | ||
userAssetManager._getAllUserAssetsInNetworkAssetsByVisibility = { _, _ in | ||
return [ | ||
NetworkAssets( | ||
network: .mockSepolia, | ||
tokens: [ | ||
.previewToken.copy(asVisibleAsset: true).then { | ||
$0.chainId = BraveWallet.SepoliaChainId | ||
} | ||
], | ||
sortOrder: 0 | ||
) | ||
] | ||
} | ||
let ipfsApi = TestIpfsAPI() | ||
|
||
return ( | ||
keyringService, walletService, rpcService, assetRatioService, blockchainRegistry, txService, | ||
solTxManagerProxy, ipfsApi, userAssetManager | ||
) | ||
} | ||
|
||
/// Test `update()` will populate `parsedTransaction` | ||
func testUpdate() { | ||
let transaction: BraveWallet.TransactionInfo = .previewConfirmedSend.then { | ||
$0.chainId = BraveWallet.SepoliaChainId | ||
} | ||
let ( | ||
keyringService, walletService, rpcService, assetRatioService, blockchainRegistry, txService, | ||
solTxManagerProxy, ipfsApi, userAssetManager | ||
) = setupServices() | ||
let store = TransactionDetailsStore( | ||
transaction: transaction, | ||
parsedTransaction: nil, | ||
keyringService: keyringService, | ||
walletService: walletService, | ||
rpcService: rpcService, | ||
assetRatioService: assetRatioService, | ||
blockchainRegistry: blockchainRegistry, | ||
txService: txService, | ||
solanaTxManagerProxy: solTxManagerProxy, | ||
ipfsApi: ipfsApi, | ||
userAssetManager: userAssetManager | ||
) | ||
let parsedTransactionExpectation = expectation(description: "update-parsedTransaction") | ||
store.$parsedTransaction | ||
.dropFirst() | ||
.first() | ||
.sink { parsedTransaction in | ||
defer { parsedTransactionExpectation.fulfill() } | ||
XCTAssertNotNil(parsedTransaction) | ||
XCTAssertEqual(parsedTransaction?.transaction.txHash, transaction.txHash) | ||
} | ||
.store(in: &cancellables) | ||
let networkExpectation = expectation(description: "update-network") | ||
store.$network | ||
.dropFirst() | ||
.first() | ||
.sink { network in | ||
defer { networkExpectation.fulfill() } | ||
XCTAssertEqual(network, .mockSepolia) | ||
} | ||
.store(in: &cancellables) | ||
store.update() | ||
waitForExpectations(timeout: 1) { error in | ||
XCTAssertNil(error) | ||
} | ||
} | ||
|
||
/// Test `updateTransaction(_:)` will update `parsedTransaction` with the new transaction | ||
func testUpdateTransaction() { | ||
let submittedTx: BraveWallet.TransactionInfo = .previewConfirmedSend.then { | ||
$0.chainId = BraveWallet.SepoliaChainId | ||
$0.txStatus = .submitted | ||
} | ||
let confirmedTx: BraveWallet.TransactionInfo = .previewConfirmedSend.then { | ||
$0.chainId = BraveWallet.SepoliaChainId | ||
$0.txStatus = .confirmed | ||
} | ||
XCTAssertEqual(submittedTx.txHash, confirmedTx.txHash) | ||
let ( | ||
keyringService, walletService, rpcService, assetRatioService, blockchainRegistry, txService, | ||
solTxManagerProxy, ipfsApi, userAssetManager | ||
) = setupServices() | ||
let store = TransactionDetailsStore( | ||
transaction: submittedTx, | ||
parsedTransaction: nil, | ||
keyringService: keyringService, | ||
walletService: walletService, | ||
rpcService: rpcService, | ||
assetRatioService: assetRatioService, | ||
blockchainRegistry: blockchainRegistry, | ||
txService: txService, | ||
solanaTxManagerProxy: solTxManagerProxy, | ||
ipfsApi: ipfsApi, | ||
userAssetManager: userAssetManager | ||
) | ||
let parsedTxExpectation = expectation(description: "update-parsedTx") | ||
store.$parsedTransaction | ||
.dropFirst() | ||
.sink { parsedTransaction in | ||
defer { parsedTxExpectation.fulfill() } | ||
XCTAssertNotNil(parsedTransaction) | ||
XCTAssertEqual(parsedTransaction?.transaction.txHash, submittedTx.txHash) | ||
XCTAssertEqual(parsedTransaction?.transaction.txStatus, .submitted) | ||
} | ||
.store(in: &cancellables) | ||
store.update() | ||
wait(for: [parsedTxExpectation], timeout: 1) | ||
cancellables.removeAll() | ||
let confirmedParsedTxExpectation = expectation(description: "update-parsedTx-confirmed") | ||
store.$parsedTransaction | ||
.dropFirst() | ||
.sink { parsedTransaction in | ||
defer { confirmedParsedTxExpectation.fulfill() } | ||
XCTAssertNotNil(parsedTransaction) | ||
XCTAssertEqual(parsedTransaction?.transaction.txHash, confirmedTx.txHash) | ||
XCTAssertEqual(parsedTransaction?.transaction.txStatus, .confirmed) | ||
} | ||
.store(in: &cancellables) | ||
store.updateTransaction(confirmedTx) | ||
waitForExpectations(timeout: 1) { error in | ||
XCTAssertNil(error) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.