Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #7757: Resolve flakey Tx Confirmation Test #8687

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class TransactionConfirmationStore: ObservableObject, WalletObserverStore
@Published var symbol: String = ""
/// The fiat value of `value`
@Published var fiat: String = ""
/// The network name that this transaction is made on
@Published var network: BraveWallet.NetworkInfo?
/// The gas value for this transaction
@Published var gasValue: String = ""
/// The symbol of the gas token for this transaction
Expand Down Expand Up @@ -479,7 +477,6 @@ public class TransactionConfirmationStore: ObservableObject, WalletObserverStore
) async {
originInfo = activeParsedTransaction.transaction.originInfo
transactionDetails = activeTransactionDetails
self.network = network

switch activeParsedTransaction.details {
case let .ethSend(details),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ struct PendingTransactionView: View {
// Current network, transaction buttons
HStack(alignment: .top) {
if confirmationStore.activeParsedTransaction.transaction.txType != .ethSwap {
Text(confirmationStore.network?.chainName ?? "") // network shown below each token for swap
Text(confirmationStore.activeParsedTransaction.network.chainName) // network shown below each token for swap
}
Spacer()
VStack(alignment: .trailing) {
Expand Down
20 changes: 3 additions & 17 deletions Tests/BraveWalletTests/TransactionConfirmationStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ import Preferences
await fulfillment(of: [prepareExpectation], timeout: 1)
}

/// Test `network` property is updated for the `activeTransaction`, regardess of the current selected network for that coin type.
func testPrepareTransactionNotOnSelectedNetwork() async {
/// Test that `nextTransaction` will update `activeTransactionId` property in order of transaction created time.
func testNextTransaction() async {
let firstTransactionDate = Date(timeIntervalSince1970: 1636399671) // Monday, November 8, 2021 7:27:51 PM
let sendCopy = BraveWallet.TransactionInfo.previewConfirmedSend.copy() as! BraveWallet.TransactionInfo
sendCopy.chainId = BraveWallet.GoerliChainId
Expand All @@ -342,20 +342,6 @@ import Preferences
allTokens: allTokens,
transactions: pendingTransactions
)
let networkExpectation = expectation(description: "network-expectation")
store.$network
.dropFirst(8) // `network` is assigned multiple times during setup
.collect(6) // collect all updates (1 extra for final tx network)
.sink { networks in
defer { networkExpectation.fulfill() }
XCTAssertEqual(networks.count, 6)
XCTAssertEqual(networks[safe: 0], BraveWallet.NetworkInfo.mockFilecoinMainnet)
XCTAssertEqual(networks[safe: 1], BraveWallet.NetworkInfo.mockSolanaTestnet)
XCTAssertEqual(networks[safe: 2], BraveWallet.NetworkInfo.mockSolana)
XCTAssertEqual(networks[safe: 3], BraveWallet.NetworkInfo.mockMainnet)
XCTAssertEqual(networks[safe: 4], BraveWallet.NetworkInfo.mockGoerli)
}
.store(in: &cancellables)
let activeTransactionIdExpectation = expectation(description: "activeTransactionId-expectation")
store.$activeTransactionId
.dropFirst()
Expand All @@ -376,7 +362,7 @@ import Preferences
store.nextTransaction() // `solanaSendCopy` on Solana Mainnet
store.nextTransaction() // `solanaSPLSendCopy` on Solana Testnet
store.nextTransaction() // `filecoinSendCopy` on filecoin mainnet
await fulfillment(of: [networkExpectation, activeTransactionIdExpectation], timeout: 1)
await fulfillment(of: [activeTransactionIdExpectation], timeout: 1)
}

/// Test `editAllowance(txMetaId:spenderAddress:amount:completion)` will return false if we fail to make ERC20 approve data with `BraveWalletEthTxManagerProxy`
Expand Down