Skip to content

Commit

Permalink
CORE-532: Fix more tests (#1)
Browse files Browse the repository at this point in the history
BRD wallet name is "BRD"; ETH wallet name is "eth".  WalletEvents balancedUpdate/transferAdded can be either order, it seems.  The address scheme id for BCH Testnet is "bitcoincash-testnet"
  • Loading branch information
Ed Gamble committed Sep 10, 2019
1 parent 7c36fea commit 1c9c3ed
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Swift/BRCrypto/BRCryptoSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public final class System {
"ethereum-mainnet": [.ethDefault],
"ripple-mainnet": [.genDefault],
"bitcoin-testnet": [.btcSegwit, .btcLegacy],
"bitcoin-cash-testnet": [.btcLegacy],
"bitcoincash-testnet": [.btcLegacy],
"ethereum-ropsten": [.ethDefault],
"ripple-testnet": [.genDefault]
]
Expand All @@ -156,7 +156,7 @@ public final class System {
"ethereum-mainnet": .ethDefault,
"ripple-mainnet": .genDefault,
"bitcoin-testnet": .btcSegwit,
"bitcoin-cash-testnet": .btcLegacy,
"bitcoincash-testnet": .btcLegacy,
"ethereum-ropsten": .ethDefault,
"ripple-testnet": .genDefault
]
Expand Down
41 changes: 19 additions & 22 deletions Swift/BRCryptoTests/BRCryptoTransferTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ class BRCryptoTransferTests: BRCryptoSystemBaseTests {

/// MARK: - BTC

func runTransferBTCTest () {
func runTransferBTCTest (mode: WalletManagerMode) {
isMainnet = false
currencyCodesNeeded = ["btc"]
modeMap = ["btc":mode]
prepareAccount (knownAccountSpecification)
prepareSystem()

let walletManagerDisconnectExpectation = XCTestExpectation (description: "Wallet Manager Disconnect")
listener.managerHandlers += [
Expand Down Expand Up @@ -146,19 +151,23 @@ class BRCryptoTransferTests: BRCryptoSystemBaseTests {
EventMatcher (event: WalletManagerEvent.syncStarted),
EventMatcher (event: WalletManagerEvent.changed(oldState: WalletManagerState.connected, newState: WalletManagerState.syncing)),

EventMatcher (event: WalletManagerEvent.syncProgress(timestamp: nil, percentComplete: 0), strict: false),
// Not in API_MODE
// EventMatcher (event: WalletManagerEvent.syncProgress(timestamp: nil, percentComplete: 0), strict: false),
EventMatcher (event: WalletManagerEvent.walletChanged(wallet: wallet), strict: true, scan: true),

EventMatcher (event: WalletManagerEvent.syncEnded(error: nil), strict: false, scan: true),
EventMatcher (event: WalletManagerEvent.changed(oldState: WalletManagerState.syncing, newState: WalletManagerState.connected)),
EventMatcher (event: WalletManagerEvent.changed(oldState: WalletManagerState.connected, newState: WalletManagerState.disconnected))
]))

XCTAssertTrue (listener.checkWalletEvents(
[EventMatcher (event: WalletEvent.created),
EventMatcher (event: WalletEvent.transferAdded(transfer: transfer), strict: true, scan: true),
EventMatcher (event: WalletEvent.balanceUpdated(amount: wallet.balance), strict: true, scan: true)
]))

XCTAssertTrue (
listener.checkWalletEvents ([EventMatcher (event: WalletEvent.created),
EventMatcher (event: WalletEvent.transferAdded(transfer: transfer), strict: true, scan: true),
EventMatcher (event: WalletEvent.balanceUpdated(amount: wallet.balance), strict: true, scan: true)])
|| listener.checkWalletEvents ([EventMatcher (event: WalletEvent.created),
EventMatcher (event: WalletEvent.balanceUpdated(amount: wallet.balance), strict: true, scan: true),
EventMatcher (event: WalletEvent.transferAdded(transfer: transfer), strict: true, scan: true)])
)

XCTAssertTrue (listener.checkTransferEvents(
[EventMatcher (event: TransferEvent.created),
Expand All @@ -168,23 +177,11 @@ class BRCryptoTransferTests: BRCryptoSystemBaseTests {
}

func testTransferBTC_API() {
isMainnet = false
currencyCodesNeeded = ["btc"]
modeMap = ["btc":WalletManagerMode.api_only]
prepareAccount (knownAccountSpecification)
prepareSystem()

runTransferBTCTest()
runTransferBTCTest(mode: WalletManagerMode.api_only)
}

func testTransferBTC_P2P() {
isMainnet = false
currencyCodesNeeded = ["btc"]
modeMap = ["btc":WalletManagerMode.p2p_only]
prepareAccount (knownAccountSpecification)
prepareSystem()

runTransferBTCTest()
runTransferBTCTest(mode: WalletManagerMode.p2p_only)
}

/// MARK: - BCH
Expand Down
29 changes: 23 additions & 6 deletions Swift/BRCryptoTests/BRCryptoWalletTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ class BRCryptoWalletTests: BRCryptoSystemBaseTests {
override func tearDown() {
}

func testWalletBTC() {
func testWalletBTCAsAPI_ONLY() {
runWalletBTCTest(mode: WalletManagerMode.api_only)
}

func testWalletBTCAsP2P_ONLY() {
runWalletBTCTest(mode: WalletManagerMode.p2p_only)
}

func runWalletBTCTest (mode: WalletManagerMode) {
isMainnet = false
currencyCodesNeeded = ["btc"]
modeMap = ["btc":WalletManagerMode.api_only]
modeMap = ["btc":mode]
prepareAccount (AccountSpecification (dict: [
"identifier": "ginger",
"paperKey": "ginger settle marine tissue robot crane night number ramp coast roast critic",
"timestamp": "2018-01-01",
"network": (isMainnet ? "mainnet" : "testnet")
]))
prepareSystem ()

prepareSystem ()

let walletManagerDisconnectExpectation = XCTestExpectation (description: "Wallet Manager Disconnect")
listener.managerHandlers += [
Expand Down Expand Up @@ -152,19 +161,27 @@ class BRCryptoWalletTests: BRCryptoSystemBaseTests {
EventMatcher (event: WalletManagerEvent.syncStarted),
EventMatcher (event: WalletManagerEvent.changed(oldState: WalletManagerState.connected, newState: WalletManagerState.syncing)),

EventMatcher (event: WalletManagerEvent.syncProgress(timestamp: nil, percentComplete: 0), strict: false),
// On API_ONLY here is no .syncProgress
// EventMatcher (event: WalletManagerEvent.syncProgress(timestamp: nil, percentComplete: 0), strict: false),
EventMatcher (event: WalletManagerEvent.walletChanged(wallet: wallet), strict: true, scan: true),

EventMatcher (event: WalletManagerEvent.syncEnded(error: nil), strict: false, scan: true),
EventMatcher (event: WalletManagerEvent.changed(oldState: WalletManagerState.syncing, newState: WalletManagerState.connected)),
EventMatcher (event: WalletManagerEvent.changed(oldState: WalletManagerState.connected, newState: WalletManagerState.disconnected))
]))

// It seems `balanceUpdated` may occur before `transferAdded`
XCTAssertTrue (listener.checkWalletEvents(
[EventMatcher (event: WalletEvent.created),
EventMatcher (event: WalletEvent.transferAdded(transfer: wallet.transfers[0]), strict: true, scan: true),
EventMatcher (event: WalletEvent.balanceUpdated(amount: wallet.balance), strict: true, scan: true)
]))
])
|| listener.checkWalletEvents(
[EventMatcher (event: WalletEvent.created),
EventMatcher (event: WalletEvent.balanceUpdated(amount: wallet.balance), strict: true, scan: true),
EventMatcher (event: WalletEvent.transferAdded(transfer: wallet.transfers[0]), strict: true, scan: true)
]))

}

func testWalletBCH() {
Expand Down Expand Up @@ -249,7 +266,7 @@ class BRCryptoWalletTests: BRCryptoSystemBaseTests {
XCTAssertNotEqual (w0, w1)

XCTAssertEqual ("eth", w0.name)
XCTAssertEqual ("brd", w1.name)
XCTAssertEqual ("BRD", w1.name)

let walletETH = manager.primaryWallet
XCTAssertNotNil(walletETH)
Expand Down
2 changes: 1 addition & 1 deletion Swift/BRCryptoTests/BRSupportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class BRSupportTests: XCTestCase {
func testAsComparableInvert () {
XCTAssertFalse (AsComparableInvert(value: AsComparable (item: p1, value: p1.age)) > AsComparableInvert (value: AsComparable (item: p2, value: p2.age)))
XCTAssertTrue (AsComparableInvert(value: AsComparable (item: p1, value: p1.age)) <= AsComparableInvert (value: AsComparable (item: p2, value: p2.age)))
XCTAssertTrue (AsComparableInvert(value: AsComparable (item: p1, value: p1.age)) == AsComparableInvert (value: AsComparable (item: p2, value: p2.age)))
XCTAssertTrue (AsComparableInvert(value: AsComparable (item: p1, value: p1.age)) == AsComparableInvert (value: AsComparable (item: p3, value: p3.age)))
}

func testAsHashable () {
Expand Down

0 comments on commit 1c9c3ed

Please sign in to comment.