Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ERussel committed Jan 9, 2024
1 parent 9b9ca2e commit 1252415
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 0 deletions.
4 changes: 4 additions & 0 deletions novawallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
0CAC02F92B48534200DDEC3A /* ProxyUpdateStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CAC02F82B48534200DDEC3A /* ProxyUpdateStyle.swift */; };
0CAC02FB2B4BC10800DDEC3A /* ProxySignValidationError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CAC02FA2B4BC10800DDEC3A /* ProxySignValidationError.swift */; };
0CAC02FD2B4BFB9400DDEC3A /* WalletRemoteQueryWrapperFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CAC02FC2B4BFB9400DDEC3A /* WalletRemoteQueryWrapperFactory.swift */; };
0CAC03042B4D0C0100DDEC3A /* WalletRemoteQueryFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CAC03032B4D0C0100DDEC3A /* WalletRemoteQueryFactoryTests.swift */; };
0CAC44AA2A7A79C2001EDE61 /* StartStakingInfoParachainWireframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CAC44A92A7A79C2001EDE61 /* StartStakingInfoParachainWireframe.swift */; };
0CAC44AC2A7A7FFD001EDE61 /* RelaychainConsensusStateDepending.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CAC44AB2A7A7FFD001EDE61 /* RelaychainConsensusStateDepending.swift */; };
0CB064682A403ADE00BFBA3F /* AmountDecimal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CB064672A403ADE00BFBA3F /* AmountDecimal.swift */; };
Expand Down Expand Up @@ -4472,6 +4473,7 @@
0CAC02F82B48534200DDEC3A /* ProxyUpdateStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyUpdateStyle.swift; sourceTree = "<group>"; };
0CAC02FA2B4BC10800DDEC3A /* ProxySignValidationError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxySignValidationError.swift; sourceTree = "<group>"; };
0CAC02FC2B4BFB9400DDEC3A /* WalletRemoteQueryWrapperFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletRemoteQueryWrapperFactory.swift; sourceTree = "<group>"; };
0CAC03032B4D0C0100DDEC3A /* WalletRemoteQueryFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletRemoteQueryFactoryTests.swift; sourceTree = "<group>"; };
0CAC44A92A7A79C2001EDE61 /* StartStakingInfoParachainWireframe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartStakingInfoParachainWireframe.swift; sourceTree = "<group>"; };
0CAC44AB2A7A7FFD001EDE61 /* RelaychainConsensusStateDepending.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelaychainConsensusStateDepending.swift; sourceTree = "<group>"; };
0CB064672A403ADE00BFBA3F /* AmountDecimal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmountDecimal.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -11733,6 +11735,7 @@
0C59E8EA2AA71C3E001E11F3 /* ExternalAssetBalanceIntegrationTests.swift */,
0CCA24642AC6B51200AEF23D /* AssetHubSwapTests.swift */,
0C8AF7B52B36C75400005AC9 /* Pdc20OperationTests.swift */,
0CAC03032B4D0C0100DDEC3A /* WalletRemoteQueryFactoryTests.swift */,
);
path = novawalletIntegrationTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -20130,6 +20133,7 @@
840874E02978882700ACFA55 /* Gov2DelegationTests.swift in Sources */,
0C2F869A2A72948100593C01 /* NominationPoolsApyTests.swift in Sources */,
8438E1D224BFAAD2001BDB13 /* JSONRPCTests.swift in Sources */,
0CAC03042B4D0C0100DDEC3A /* WalletRemoteQueryFactoryTests.swift in Sources */,
8455F19A2A1DEEAF003F072D /* SubqueryMultistakingTests.swift in Sources */,
0C59E8EB2AA71C3E001E11F3 /* ExternalAssetBalanceIntegrationTests.swift in Sources */,
AEE4E37225ECF83F00D6DF31 /* StakingInfoTests.swift in Sources */,
Expand Down
170 changes: 170 additions & 0 deletions novawalletIntegrationTests/WalletRemoteQueryFactoryTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import XCTest
@testable import novawallet
import RobinHood
import SubstrateSdk

final class WalletRemoteQueryFactoryTests: XCTestCase {
func testPolkadotExistingBalance() throws {
do {
let accountId = try "1ChFWeNRLarAPRCTM3bfJmncJbSAbSS9yqjueWz7jX7iTVZ".toAccountId()
let balance = try performQuery(for: accountId, chainId: KnowChainId.polkadot)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

func testPolkadotNotExistingBalance() throws {
do {
let accountId = try "123gpPmcSD3BjqXJboFNLT3ArShcsZ9veDdZnmiHNF3sNQng".toAccountId()
let balance = try performQuery(for: accountId, chainId: KnowChainId.polkadot)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

func testInterlayExistingBalance() throws {
do {
let accountId = try "wd7haPUigB22TB9HEKs2k2JrwBf1onbtdNXWZAXHnRN7FVHMf".toAccountId()
let balance = try performQuery(
for: accountId,
chainId: "bf88efe70e9e0e916416e8bed61f2b45717f517d7f3523e33c7b001e5ffcbc72"
)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

func testInterlayNotExistingBalance() throws {
do {
let accountId = try "wd8YZxMqvBtUnkbPLUKEWhT8KRo7zVZc7rmJP3eV5fse18stt".toAccountId()
let balance = try performQuery(
for: accountId,
chainId: "bf88efe70e9e0e916416e8bed61f2b45717f517d7f3523e33c7b001e5ffcbc72"
)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

func testEquilibriumExistingBalance() throws {
do {
let accountId = try "cg7h2eLBseFrAbdeZ4X1CHkiWybwwCfhxGBDhvrmFNUBuzs1o".toAccountId()
let balance = try performQuery(
for: accountId,
chainId: "89d3ec46d2fb43ef5a9713833373d5ea666b092fa8fd68fbc34596036571b907"
)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

func testEquilibriumNotExistingBalance() throws {
do {
let accountId = try "cg49kkSwuqAkkP2GZqq7tNRieU3y2wqrt6D89FsVcXAxyA8EN".toAccountId()
let balance = try performQuery(
for: accountId,
chainId: "89d3ec46d2fb43ef5a9713833373d5ea666b092fa8fd68fbc34596036571b907"
)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

func testMoonbeamExistingBalance() throws {
do {
let accountId = try "0x7aa98aeb3afacf10021539d5412c7ac6afe0fb00".toAccountId()
let balance = try performQuery(
for: accountId,
chainId: KnowChainId.moonbeam
)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

func testMoonbeamNotExistingBalance() throws {
do {
let accountId = try "0x7aa98aeb3afacf10021539d5412c7ac6afe0fc00".toAccountId()
let balance = try performQuery(
for: accountId,
chainId: KnowChainId.moonbeam
)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

func testStatemineExistingBalance() throws {
do {
let accountId = try "F53d3jeyFvb2eYsgAERhjC8mogao4Kg4GsdezrqiT8aj55v".toAccountId()
let balance = try performQuery(
for: accountId,
chainId: KnowChainId.statemine,
assetId: 7
)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

func testStatemineNotExistingBalance() throws {
do {
let accountId = try "Cn1mVjBBvLJUWE8GQoeR7JduGt2GxhUXrx191ob3Si6HA9E".toAccountId()
let balance = try performQuery(
for: accountId,
chainId: KnowChainId.statemine,
assetId: 7
)
Logger.shared.info("Did receive: \(balance)")
} catch {
XCTFail("Did receive error: \(error)")
}
}

private func performQuery(for accountId: AccountId, chainId: ChainModel.Id, assetId: AssetModel.Id = 0) throws -> AssetBalance {
let storageFacade = SubstrateStorageTestFacade()
let chainRegistry = ChainRegistryFacade.setupForIntegrationTest(with: storageFacade)
let operationQueue = OperationQueue()

let requestFactory = StorageRequestFactory(
remoteFactory: StorageKeyFactory(),
operationManager: OperationManager(operationQueue: operationQueue)
)

guard
let chain = chainRegistry.getChain(for: chainId),
let asset = chain.asset(for: assetId),
let runtimeProvider = chainRegistry.getRuntimeProvider(for: chainId),
let connection = chainRegistry.getConnection(for: chainId) else {
throw ChainRegistryError.connectionUnavailable
}

let chainAsset = ChainAsset(chain: chain, asset: asset)

let operationFactory = WalletRemoteQueryWrapperFactory(
requestFactory: requestFactory,
assetInfoOperationFactory: AssetStorageInfoOperationFactory(),
runtimeProvider: runtimeProvider,
connection: connection,
operationQueue: operationQueue
)

let queryWrapper = operationFactory.queryBalance(
for: accountId,
chainAsset: chainAsset
)

operationQueue.addOperations(queryWrapper.allOperations, waitUntilFinished: true)

return try queryWrapper.targetOperation.extractNoCancellableResultData()
}
}

0 comments on commit 1252415

Please sign in to comment.