[#394] adopt ZcashLightClientKit 0.16.x-beta (#397)

Closes #394

This removes Zatoshi and Balance from the wallet codebase and relies on
the types present on the SDK.

point to master
This commit is contained in:
Francisco Gindre 2022-07-19 15:56:46 -03:00 committed by GitHub
parent 78dd14e711
commit 63554b7408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 209 additions and 257 deletions

View File

@ -42,6 +42,8 @@
0DACFA9927209FA70039EEA5 /* Roboto-BlackItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0DACFA8C27209FA70039EEA5 /* Roboto-BlackItalic.ttf */; }; 0DACFA9927209FA70039EEA5 /* Roboto-BlackItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0DACFA8C27209FA70039EEA5 /* Roboto-BlackItalic.ttf */; };
0DACFA9A27209FA70039EEA5 /* Roboto-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0DACFA8D27209FA70039EEA5 /* Roboto-Light.ttf */; }; 0DACFA9A27209FA70039EEA5 /* Roboto-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0DACFA8D27209FA70039EEA5 /* Roboto-Light.ttf */; };
0DACFA9C27209FA70039EEA5 /* Roboto-ThinItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0DACFA8F27209FA70039EEA5 /* Roboto-ThinItalic.ttf */; }; 0DACFA9C27209FA70039EEA5 /* Roboto-ThinItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0DACFA8F27209FA70039EEA5 /* Roboto-ThinItalic.ttf */; };
0DB4E0B12881F2DB00947B78 /* WalletBalance+testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB4E0B02881F2DB00947B78 /* WalletBalance+testing.swift */; };
0DB4E0B42881FD9100947B78 /* ZcashLightClientKit in Frameworks */ = {isa = PBXBuildFile; productRef = 0DB4E0B32881FD9100947B78 /* ZcashLightClientKit */; };
0DB8AA81271DC7520035BC9D /* DesignGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB8AA80271DC7520035BC9D /* DesignGuide.swift */; }; 0DB8AA81271DC7520035BC9D /* DesignGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB8AA80271DC7520035BC9D /* DesignGuide.swift */; };
0DC487C32772574C00BE6A63 /* RecoveryPhraseBackupSucceededView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DC487C22772574C00BE6A63 /* RecoveryPhraseBackupSucceededView.swift */; }; 0DC487C32772574C00BE6A63 /* RecoveryPhraseBackupSucceededView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DC487C22772574C00BE6A63 /* RecoveryPhraseBackupSucceededView.swift */; };
0DDB6A5127737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DDB6A5027737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift */; }; 0DDB6A5127737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DDB6A5027737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift */; };
@ -97,7 +99,6 @@
9E2F1C8F280EDE09004E65FE /* Drawer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E2F1C8E280EDE09004E65FE /* Drawer.swift */; }; 9E2F1C8F280EDE09004E65FE /* Drawer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E2F1C8E280EDE09004E65FE /* Drawer.swift */; };
9E37A2B827C8F59F00AE57B3 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9E37A2B727C8F59F00AE57B3 /* Localizable.strings */; }; 9E37A2B827C8F59F00AE57B3 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9E37A2B727C8F59F00AE57B3 /* Localizable.strings */; };
9E391124283E4CAC0073DD9A /* ImportWalletTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E391123283E4CAC0073DD9A /* ImportWalletTests.swift */; }; 9E391124283E4CAC0073DD9A /* ImportWalletTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E391123283E4CAC0073DD9A /* ImportWalletTests.swift */; };
9E391129283F74590073DD9A /* Zatoshi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E391128283F74590073DD9A /* Zatoshi.swift */; };
9E39112E283F91600073DD9A /* ZatoshiTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E39112D283F91600073DD9A /* ZatoshiTests.swift */; }; 9E39112E283F91600073DD9A /* ZatoshiTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E39112D283F91600073DD9A /* ZatoshiTests.swift */; };
9E391132284644580073DD9A /* AppInitializationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E391131284644580073DD9A /* AppInitializationTests.swift */; }; 9E391132284644580073DD9A /* AppInitializationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E391131284644580073DD9A /* AppInitializationTests.swift */; };
9E3911392848AD500073DD9A /* HomeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E3911382848AD500073DD9A /* HomeTests.swift */; }; 9E3911392848AD500073DD9A /* HomeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E3911382848AD500073DD9A /* HomeTests.swift */; };
@ -266,6 +267,7 @@
0DACFA8C27209FA70039EEA5 /* Roboto-BlackItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-BlackItalic.ttf"; sourceTree = "<group>"; }; 0DACFA8C27209FA70039EEA5 /* Roboto-BlackItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-BlackItalic.ttf"; sourceTree = "<group>"; };
0DACFA8D27209FA70039EEA5 /* Roboto-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Light.ttf"; sourceTree = "<group>"; }; 0DACFA8D27209FA70039EEA5 /* Roboto-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Light.ttf"; sourceTree = "<group>"; };
0DACFA8F27209FA70039EEA5 /* Roboto-ThinItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-ThinItalic.ttf"; sourceTree = "<group>"; }; 0DACFA8F27209FA70039EEA5 /* Roboto-ThinItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-ThinItalic.ttf"; sourceTree = "<group>"; };
0DB4E0B02881F2DB00947B78 /* WalletBalance+testing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WalletBalance+testing.swift"; sourceTree = "<group>"; };
0DB8AA80271DC7520035BC9D /* DesignGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DesignGuide.swift; sourceTree = "<group>"; }; 0DB8AA80271DC7520035BC9D /* DesignGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DesignGuide.swift; sourceTree = "<group>"; };
0DC487C22772574C00BE6A63 /* RecoveryPhraseBackupSucceededView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecoveryPhraseBackupSucceededView.swift; sourceTree = "<group>"; }; 0DC487C22772574C00BE6A63 /* RecoveryPhraseBackupSucceededView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecoveryPhraseBackupSucceededView.swift; sourceTree = "<group>"; };
0DDB6A5027737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecoveryPhraseBackupFailedView.swift; sourceTree = "<group>"; }; 0DDB6A5027737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecoveryPhraseBackupFailedView.swift; sourceTree = "<group>"; };
@ -319,7 +321,6 @@
9E2F1C8E280EDE09004E65FE /* Drawer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Drawer.swift; sourceTree = "<group>"; }; 9E2F1C8E280EDE09004E65FE /* Drawer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Drawer.swift; sourceTree = "<group>"; };
9E37A2B727C8F59F00AE57B3 /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; }; 9E37A2B727C8F59F00AE57B3 /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
9E391123283E4CAC0073DD9A /* ImportWalletTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportWalletTests.swift; sourceTree = "<group>"; }; 9E391123283E4CAC0073DD9A /* ImportWalletTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportWalletTests.swift; sourceTree = "<group>"; };
9E391128283F74590073DD9A /* Zatoshi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Zatoshi.swift; sourceTree = "<group>"; };
9E39112D283F91600073DD9A /* ZatoshiTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZatoshiTests.swift; sourceTree = "<group>"; }; 9E39112D283F91600073DD9A /* ZatoshiTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZatoshiTests.swift; sourceTree = "<group>"; };
9E391131284644580073DD9A /* AppInitializationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInitializationTests.swift; sourceTree = "<group>"; }; 9E391131284644580073DD9A /* AppInitializationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInitializationTests.swift; sourceTree = "<group>"; };
9E3911382848AD500073DD9A /* HomeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTests.swift; sourceTree = "<group>"; }; 9E3911382848AD500073DD9A /* HomeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTests.swift; sourceTree = "<group>"; };
@ -430,6 +431,7 @@
9EF8139827F1FAEC0075AF48 /* ZcashLightClientKit in Frameworks */, 9EF8139827F1FAEC0075AF48 /* ZcashLightClientKit in Frameworks */,
9E6612312878337F00C75B70 /* Lottie in Frameworks */, 9E6612312878337F00C75B70 /* Lottie in Frameworks */,
9E7CB6182872D3DF00A02233 /* URLRouting in Frameworks */, 9E7CB6182872D3DF00A02233 /* URLRouting in Frameworks */,
0DB4E0B42881FD9100947B78 /* ZcashLightClientKit in Frameworks */,
9E2AC0FF27D8EC120042AA47 /* MnemonicSwift in Frameworks */, 9E2AC0FF27D8EC120042AA47 /* MnemonicSwift in Frameworks */,
6654C73A2715A38000901167 /* ComposableArchitecture in Frameworks */, 6654C73A2715A38000901167 /* ComposableArchitecture in Frameworks */,
9EAB466F285A0468002904A0 /* _URLRouting in Frameworks */, 9EAB466F285A0468002904A0 /* _URLRouting in Frameworks */,
@ -977,7 +979,6 @@
0D35CC45277A36E00074316A /* ScrollableWhenScaled.swift */, 0D35CC45277A36E00074316A /* ScrollableWhenScaled.swift */,
2EDA07A327EDE2A900D6F09B /* DebugFrame.swift */, 2EDA07A327EDE2A900D6F09B /* DebugFrame.swift */,
9E2F1C832809B606004E65FE /* DebugMenu.swift */, 9E2F1C832809B606004E65FE /* DebugMenu.swift */,
9E391128283F74590073DD9A /* Zatoshi.swift */,
9E7CB619287310EC00A02233 /* QRCodeGenerator.swift */, 9E7CB619287310EC00A02233 /* QRCodeGenerator.swift */,
); );
path = Utils; path = Utils;
@ -1164,6 +1165,7 @@
9EF8135B27ECC25E0075AF48 /* UserPreferencesStorageTests.swift */, 9EF8135B27ECC25E0075AF48 /* UserPreferencesStorageTests.swift */,
9E02B56B27FED475005B809B /* DatabaseFilesTests.swift */, 9E02B56B27FED475005B809B /* DatabaseFilesTests.swift */,
9E39112D283F91600073DD9A /* ZatoshiTests.swift */, 9E39112D283F91600073DD9A /* ZatoshiTests.swift */,
0DB4E0B02881F2DB00947B78 /* WalletBalance+testing.swift */,
); );
path = UtilTests; path = UtilTests;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1298,6 +1300,7 @@
9EAB466E285A0468002904A0 /* _URLRouting */, 9EAB466E285A0468002904A0 /* _URLRouting */,
9E7CB6172872D3DF00A02233 /* URLRouting */, 9E7CB6172872D3DF00A02233 /* URLRouting */,
9E6612302878337F00C75B70 /* Lottie */, 9E6612302878337F00C75B70 /* Lottie */,
0DB4E0B32881FD9100947B78 /* ZcashLightClientKit */,
); );
productName = secant; productName = secant;
productReference = 0D4E7A0526B364170058B01E /* secant-testnet.app */; productReference = 0D4E7A0526B364170058B01E /* secant-testnet.app */;
@ -1379,6 +1382,7 @@
9EAB466B285A0468002904A0 /* XCRemoteSwiftPackageReference "swift-parsing" */, 9EAB466B285A0468002904A0 /* XCRemoteSwiftPackageReference "swift-parsing" */,
9E7CB6162872D3DF00A02233 /* XCRemoteSwiftPackageReference "swift-url-routing" */, 9E7CB6162872D3DF00A02233 /* XCRemoteSwiftPackageReference "swift-url-routing" */,
9E66122F2878337F00C75B70 /* XCRemoteSwiftPackageReference "lottie-ios" */, 9E66122F2878337F00C75B70 /* XCRemoteSwiftPackageReference "lottie-ios" */,
0DB4E0B22881FD9100947B78 /* XCRemoteSwiftPackageReference "ZcashLightClientKit" */,
); );
productRefGroup = 0D4E7A0626B364170058B01E /* Products */; productRefGroup = 0D4E7A0626B364170058B01E /* Products */;
projectDirPath = ""; projectDirPath = "";
@ -1523,7 +1527,6 @@
9E66122C2877188700C75B70 /* SyncStatusSnapshot.swift in Sources */, 9E66122C2877188700C75B70 /* SyncStatusSnapshot.swift in Sources */,
9E4DC6E227C4C6B700E657F4 /* SecantButtonStyles.swift in Sources */, 9E4DC6E227C4C6B700E657F4 /* SecantButtonStyles.swift in Sources */,
0DDB6A5127737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift in Sources */, 0DDB6A5127737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift in Sources */,
9E391129283F74590073DD9A /* Zatoshi.swift in Sources */,
0D6D628B276A528E002FB4CC /* DropDelegate.swift in Sources */, 0D6D628B276A528E002FB4CC /* DropDelegate.swift in Sources */,
9E2DF99D27CF704D00649636 /* ImportSeedEditor.swift in Sources */, 9E2DF99D27CF704D00649636 /* ImportSeedEditor.swift in Sources */,
F9971A5327680DD000A2DB75 /* ProfileStore.swift in Sources */, F9971A5327680DD000A2DB75 /* ProfileStore.swift in Sources */,
@ -1658,6 +1661,7 @@
9E9ECC9C28589E150099D5A2 /* OnboardingSnapshotTests.swift in Sources */, 9E9ECC9C28589E150099D5A2 /* OnboardingSnapshotTests.swift in Sources */,
9E9ECC9728589E150099D5A2 /* HomeSnapshotTests.swift in Sources */, 9E9ECC9728589E150099D5A2 /* HomeSnapshotTests.swift in Sources */,
9EF8135C27ECC25E0075AF48 /* WalletStorageTests.swift in Sources */, 9EF8135C27ECC25E0075AF48 /* WalletStorageTests.swift in Sources */,
0DB4E0B12881F2DB00947B78 /* WalletBalance+testing.swift in Sources */,
9E02B56C27FED475005B809B /* DatabaseFilesTests.swift in Sources */, 9E02B56C27FED475005B809B /* DatabaseFilesTests.swift in Sources */,
9EF8135D27ECC25E0075AF48 /* UserPreferencesStorageTests.swift in Sources */, 9EF8135D27ECC25E0075AF48 /* UserPreferencesStorageTests.swift in Sources */,
); );
@ -1977,6 +1981,14 @@
/* End XCConfigurationList section */ /* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */ /* Begin XCRemoteSwiftPackageReference section */
0DB4E0B22881FD9100947B78 /* XCRemoteSwiftPackageReference "ZcashLightClientKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/zcash/ZcashLightClientKit/";
requirement = {
branch = master;
kind = branch;
};
};
6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = { 6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = {
isa = XCRemoteSwiftPackageReference; isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swift-composable-architecture"; repositoryURL = "https://github.com/pointfreeco/swift-composable-architecture";
@ -2021,13 +2033,18 @@
isa = XCRemoteSwiftPackageReference; isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/zcash/ZcashLightClientKit"; repositoryURL = "https://github.com/zcash/ZcashLightClientKit";
requirement = { requirement = {
kind = exactVersion; branch = master;
version = "0.14.0-beta"; kind = branch;
}; };
}; };
/* End XCRemoteSwiftPackageReference section */ /* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */ /* Begin XCSwiftPackageProductDependency section */
0DB4E0B32881FD9100947B78 /* ZcashLightClientKit */ = {
isa = XCSwiftPackageProductDependency;
package = 0DB4E0B22881FD9100947B78 /* XCRemoteSwiftPackageReference "ZcashLightClientKit" */;
productName = ZcashLightClientKit;
};
6654C7392715A38000901167 /* ComposableArchitecture */ = { 6654C7392715A38000901167 /* ComposableArchitecture */ = {
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
package = 6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */; package = 6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */;

View File

@ -14,8 +14,8 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "https://github.com/grpc/grpc-swift.git", "location" : "https://github.com/grpc/grpc-swift.git",
"state" : { "state" : {
"revision" : "d772b688d718c2eb29f99b535fc4d92ebba031c5", "revision" : "4c63368b7462305903507e8acebd77264c0fb695",
"version" : "1.8.1" "version" : "1.8.2"
} }
}, },
{ {
@ -140,8 +140,8 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git", "location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : { "state" : {
"revision" : "42436a25ff32c390465567f5c089a9a8ce8d7baf", "revision" : "c30c680c78c99afdabf84805a83c8745387c4ac7",
"version" : "2.20.0" "version" : "2.20.2"
} }
}, },
{ {
@ -203,8 +203,8 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "https://github.com/zcash/ZcashLightClientKit", "location" : "https://github.com/zcash/ZcashLightClientKit",
"state" : { "state" : {
"revision" : "74f3ae20f26748e162c051e5fa343c71febc4294", "branch" : "master",
"version" : "0.14.0-beta" "revision" : "4e260419e1e07af094e9795f47f350a9d4008383"
} }
} }
], ],

View File

@ -501,7 +501,7 @@ extension AppReducer {
case .home: case .home:
return Effect(value: .deeplinkHome) return Effect(value: .deeplinkHome)
case let .send(amount, address, memo): case let .send(amount, address, memo):
return Effect(value: .deeplinkSend(Zatoshi(amount: amount), address, memo)) return Effect(value: .deeplinkSend(Zatoshi(amount), address, memo))
} }
} }
} }

View File

@ -65,7 +65,7 @@ enum HomeAction: Equatable {
case scan(ScanAction) case scan(ScanAction)
case synchronizerStateChanged(WrappedSDKSynchronizerState) case synchronizerStateChanged(WrappedSDKSynchronizerState)
case walletEvents(WalletEventsFlowAction) case walletEvents(WalletEventsFlowAction)
case updateBalance(Balance) case updateBalance(WalletBalance)
case updateDrawer(DrawerOverlay) case updateDrawer(DrawerOverlay)
case updateRoute(HomeState.Route?) case updateRoute(HomeState.Route?)
case updateSynchronizerStatus case updateSynchronizerStatus
@ -139,8 +139,8 @@ extension HomeReducer {
return Effect(value: .updateSynchronizerStatus) return Effect(value: .updateSynchronizerStatus)
case .updateBalance(let balance): case .updateBalance(let balance):
state.totalBalance = Zatoshi(amount: balance.total) state.totalBalance = balance.total
state.verifiedBalance = Zatoshi(amount: balance.verified) state.verifiedBalance = balance.verified
return .none return .none
case .updateDrawer(let drawerOverlay): case .updateDrawer(let drawerOverlay):
@ -155,7 +155,7 @@ extension HomeReducer {
state.synchronizerStatusSnapshot = environment.SDKSynchronizer.statusSnapshot() state.synchronizerStatusSnapshot = environment.SDKSynchronizer.statusSnapshot()
return environment.SDKSynchronizer.getShieldedBalance() return environment.SDKSynchronizer.getShieldedBalance()
.receive(on: environment.scheduler) .receive(on: environment.scheduler)
.map({ Balance(verified: $0.verified, total: $0.total) }) .map({ WalletBalance(verified: $0.verified, total: $0.total) })
.map(HomeAction.updateBalance) .map(HomeAction.updateBalance)
.eraseToEffect() .eraseToEffect()

View File

@ -36,7 +36,7 @@ struct SendFlowState: Equatable {
} }
var amount: Zatoshi { var amount: Zatoshi {
get { Zatoshi(amount: transactionAmountInputState.amount) } get { Zatoshi(transactionAmountInputState.amount) }
set { set {
transactionAmountInputState.amount = newValue.amount transactionAmountInputState.amount = newValue.amount
transactionAmountInputState.textFieldState.text = newValue.amount == 0 ? transactionAmountInputState.textFieldState.text = newValue.amount == 0 ?
@ -119,7 +119,7 @@ extension SendFlowReducer {
return .none return .none
case .updateRoute(.confirmation): case .updateRoute(.confirmation):
state.amount = Zatoshi(amount: state.transactionAmountInputState.amount) state.amount = Zatoshi(state.transactionAmountInputState.amount)
state.address = state.transactionAddressInputState.textFieldState.text state.address = state.transactionAddressInputState.textFieldState.text
state.route = .confirmation state.route = .confirmation
return .none return .none
@ -183,7 +183,7 @@ extension SendFlowReducer {
case .synchronizerStateChanged(.synced): case .synchronizerStateChanged(.synced):
return environment.SDKSynchronizer.getShieldedBalance() return environment.SDKSynchronizer.getShieldedBalance()
.receive(on: environment.scheduler) .receive(on: environment.scheduler)
.map({ Zatoshi(amount: $0.total) }) .map({ $0.total })
.map(SendFlowAction.updateBalance) .map(SendFlowAction.updateBalance)
.eraseToEffect() .eraseToEffect()

View File

@ -10,7 +10,7 @@ struct CreateTransaction: View {
return WithViewStore(store) { viewStore in return WithViewStore(store) { viewStore in
VStack { VStack {
VStack(spacing: 0) { VStack(spacing: 0) {
Text("Balance \(viewStore.totalBalance.decimalString()) ZEC") Text("WalletBalance \(viewStore.totalBalance.decimalString()) ZEC")
Text("($\(viewStore.totalCurrencyBalance.decimalString()))") Text("($\(viewStore.totalCurrencyBalance.decimalString()))")
.font(.system(size: 13)) .font(.system(size: 13))
.opacity(0.6) .opacity(0.6)

View File

@ -1,5 +1,6 @@
import SwiftUI import SwiftUI
import ComposableArchitecture import ComposableArchitecture
import ZcashLightClientKit
struct TransactionDetailView: View { struct TransactionDetailView: View {
enum RowMark { enum RowMark {
@ -259,11 +260,11 @@ struct TransactionDetail_Previews: PreviewProvider {
""", """,
minedHeight: 1_875_256, minedHeight: 1_875_256,
zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po",
fee: Zatoshi(amount: 1_000_000), fee: Zatoshi(1_000_000),
id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8",
status: .paid(success: true), status: .paid(success: true),
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 25_000_000) zecAmount: Zatoshi(25_000_000)
), ),
viewStore: ViewStore( viewStore: ViewStore(
WalletEventsFlowStore( WalletEventsFlowStore(

View File

@ -6,6 +6,7 @@
// //
import SwiftUI import SwiftUI
import ZcashLightClientKit
struct TransactionRowView: View { struct TransactionRowView: View {
var transaction: TransactionState var transaction: TransactionState
@ -107,11 +108,11 @@ struct TransactionRowView_Previews: PreviewProvider {
transaction: transaction:
.init( .init(
zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po",
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
id: "2", id: "2",
status: .paid(success: true), status: .paid(success: true),
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 123_000_000) zecAmount: Zatoshi(123_000_000)
) )
) )
.preferredColorScheme(.dark) .preferredColorScheme(.dark)

View File

@ -135,22 +135,22 @@ extension TransactionState {
static var placeholder: Self { static var placeholder: Self {
.init( .init(
zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po",
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
id: "2", id: "2",
status: .paid(success: true), status: .paid(success: true),
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 123_000_000) zecAmount: Zatoshi(123_000_000)
) )
} }
static func statePlaceholder(_ status: Status) -> Self { static func statePlaceholder(_ status: Status) -> Self {
.init( .init(
zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po",
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
id: "2", id: "2",
status: status, status: status,
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 123_000_000) zecAmount: Zatoshi(123_000_000)
) )
} }
} }
@ -185,11 +185,11 @@ extension IdentifiedArrayOf where Element == TransactionState {
return .init( return .init(
uniqueElements: (0..<30).map { uniqueElements: (0..<30).map {
TransactionState( TransactionState(
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
id: String($0), id: String($0),
status: .paid(success: true), status: .paid(success: true),
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 25) zecAmount: Zatoshi(25)
) )
} }
) )

View File

@ -32,7 +32,7 @@ struct TransactionState: Equatable, Identifiable {
var address: String { zAddress ?? "" } var address: String { zAddress ?? "" }
var date: Date { Date(timeIntervalSince1970: timestamp) } var date: Date { Date(timeIntervalSince1970: timestamp) }
var totalAmount: Zatoshi { Zatoshi(amount: zecAmount.amount + fee.amount) } var totalAmount: Zatoshi { Zatoshi(zecAmount.amount + fee.amount) }
var viewOnlineURL: URL? { var viewOnlineURL: URL? {
URL(string: "https://blockchair.com/zcash/transaction/\(id)") URL(string: "https://blockchair.com/zcash/transaction/\(id)")
} }
@ -53,8 +53,8 @@ extension TransactionState {
shielded = true shielded = true
status = sent ? .paid(success: confirmedTransaction.minedHeight > 0) : .received status = sent ? .paid(success: confirmedTransaction.minedHeight > 0) : .received
zAddress = confirmedTransaction.toAddress zAddress = confirmedTransaction.toAddress
zecAmount = sent ? Zatoshi(amount: -Int64(confirmedTransaction.value)) : Zatoshi(amount: Int64(confirmedTransaction.value)) zecAmount = sent ? Zatoshi(-confirmedTransaction.value.amount) : confirmedTransaction.value
fee = Zatoshi(amount: 10) fee = Zatoshi(10)
if let memo = confirmedTransaction.memo { if let memo = confirmedTransaction.memo {
self.memo = memo.asZcashTransactionMemo() self.memo = memo.asZcashTransactionMemo()
} }
@ -71,8 +71,8 @@ extension TransactionState {
.pending .pending
expirationHeight = pendingTransaction.expiryHeight expirationHeight = pendingTransaction.expiryHeight
zAddress = pendingTransaction.toAddress zAddress = pendingTransaction.toAddress
zecAmount = Zatoshi(amount: -Int64(pendingTransaction.value)) zecAmount = pendingTransaction.value
fee = Zatoshi(amount: 10) fee = Zatoshi(10)
if let memo = pendingTransaction.memo { if let memo = pendingTransaction.memo {
self.memo = memo.asZcashTransactionMemo() self.memo = memo.asZcashTransactionMemo()
} }
@ -102,7 +102,7 @@ extension TransactionState {
id: uuid, id: uuid,
status: status, status: status,
timestamp: timestamp, timestamp: timestamp,
zecAmount: status == .received ? amount : Zatoshi(amount: -amount.amount) zecAmount: status == .received ? amount : Zatoshi(-amount.amount)
) )
} }
} }

View File

@ -78,7 +78,7 @@ private extension WalletEvent {
switch Int.random(in: 0..<6) { switch Int.random(in: 0..<6) {
case 1: return .received(.statePlaceholder(.received)) case 1: return .received(.statePlaceholder(.received))
case 2: return .failed(.statePlaceholder(.failed)) case 2: return .failed(.statePlaceholder(.failed))
case 3: return .shielded(Zatoshi(amount: 234_000_000)) case 3: return .shielded(Zatoshi(234_000_000))
case 4: return .walletImport(BlockHeight(1_629_724)) case 4: return .walletImport(BlockHeight(1_629_724))
case 5: return .pending(.statePlaceholder(.pending)) case 5: return .pending(.statePlaceholder(.pending))
default: return .send(.placeholder) default: return .send(.placeholder)

View File

@ -7,6 +7,7 @@
import SwiftUI import SwiftUI
import ComposableArchitecture import ComposableArchitecture
import ZcashLightClientKit
final class AppDelegate: NSObject, UIApplicationDelegate { final class AppDelegate: NSObject, UIApplicationDelegate {
var appStore: AppStore = .placeholder var appStore: AppStore = .placeholder

View File

@ -6,7 +6,7 @@
// //
import ComposableArchitecture import ComposableArchitecture
import ZcashLightClientKit
typealias TransactionAmountTextFieldReducer = Reducer< typealias TransactionAmountTextFieldReducer = Reducer<
TransactionAmountTextFieldState, TransactionAmountTextFieldState,
TransactionAmountTextFieldAction, TransactionAmountTextFieldAction,

View File

@ -1,82 +0,0 @@
//
// Zatoshi.swift
// secant-testnet
//
// Created by Lukáš Korba on 26.05.2022.
//
import Foundation
struct Zatoshi {
enum Constants {
static let oneZecInZatoshi: Int64 = 100_000_000
static let maxZecSupply: Int64 = 21_000_000
static let maxZatoshi: Int64 = Constants.oneZecInZatoshi * Constants.maxZecSupply
}
static var zero: Zatoshi { Zatoshi() }
static let decimalHandler = NSDecimalNumberHandler(
roundingMode: NSDecimalNumber.RoundingMode.bankers,
scale: 8,
raiseOnExactness: true,
raiseOnOverflow: true,
raiseOnUnderflow: true,
raiseOnDivideByZero: true
)
@Clamped(-Constants.maxZatoshi...Constants.maxZatoshi)
var amount: Int64 = 0
/// Converts `Zatoshi` to `NSDecimalNumber`
var decimalValue: NSDecimalNumber {
NSDecimalNumber(decimal: Decimal(amount) / Decimal(Constants.oneZecInZatoshi))
}
/// Converts `Zatoshi` to human readable format, up to 8 fraction digits
func decimalString(formatter: NumberFormatter = NumberFormatter.zcashNumberFormatter) -> String {
formatter.string(from: decimalValue.roundedZec) ?? ""
}
/// Converts `Decimal` to `Zatoshi`
static func from(decimal: Decimal) -> Zatoshi {
let roundedZec = NSDecimalNumber(decimal: decimal).roundedZec
let zec2zatoshi = Decimal(Constants.oneZecInZatoshi) * roundedZec.decimalValue
return Zatoshi(amount: NSDecimalNumber(decimal: zec2zatoshi).int64Value)
}
/// Converts `String` to `Zatoshi`
static func from(decimalString: String, formatter: NumberFormatter = NumberFormatter.zcashNumberFormatter) -> Zatoshi? {
if let number = formatter.number(from: decimalString) {
return Zatoshi.from(decimal: number.decimalValue)
}
return nil
}
static func + (left: Zatoshi, right: Zatoshi) -> Zatoshi {
Zatoshi(amount: left.amount + right.amount)
}
static func - (left: Zatoshi, right: Zatoshi) -> Zatoshi {
Zatoshi(amount: left.amount - right.amount)
}
}
extension Zatoshi: Equatable {
static func == (lhs: Zatoshi, rhs: Zatoshi) -> Bool {
lhs.amount == rhs.amount
}
}
extension NSDecimalNumber {
/// Round the decimal to 8 fraction digits
var roundedZec: NSDecimalNumber {
self.rounding(accordingToBehavior: Zatoshi.decimalHandler)
}
/// Converts `NSDecimalNumber` to human readable format, up to 8 fraction digits
var decimalString: String {
self.roundedZec.stringValue
}
}

View File

@ -12,7 +12,6 @@ import ComposableArchitecture
enum WrappedSDKSynchronizerState: Equatable { enum WrappedSDKSynchronizerState: Equatable {
case unknown case unknown
case transactionsUpdated case transactionsUpdated
case started case started
case progressUpdated case progressUpdated
@ -32,11 +31,6 @@ enum WrappedSDKSynchronizerState: Equatable {
case connectionStateChanged case connectionStateChanged
} }
struct Balance: WalletBalance, Equatable {
var verified: Int64
var total: Int64
}
protocol WrappedSDKSynchronizer { protocol WrappedSDKSynchronizer {
var synchronizer: SDKSynchronizer? { get } var synchronizer: SDKSynchronizer? { get }
var stateChanged: CurrentValueSubject<WrappedSDKSynchronizerState, Never> { get } var stateChanged: CurrentValueSubject<WrappedSDKSynchronizerState, Never> { get }
@ -47,7 +41,7 @@ protocol WrappedSDKSynchronizer {
func stop() func stop()
func statusSnapshot() -> SyncStatusSnapshot func statusSnapshot() -> SyncStatusSnapshot
func getShieldedBalance() -> Effect<Balance, Never> func getShieldedBalance() -> Effect<WalletBalance, Never>
func getAllClearedTransactions() -> Effect<[WalletEvent], Never> func getAllClearedTransactions() -> Effect<[WalletEvent], Never>
func getAllPendingTransactions() -> Effect<[WalletEvent], Never> func getAllPendingTransactions() -> Effect<[WalletEvent], Never>
func getAllTransactions() -> Effect<[WalletEvent], Never> func getAllTransactions() -> Effect<[WalletEvent], Never>
@ -151,10 +145,10 @@ class LiveWrappedSDKSynchronizer: WrappedSDKSynchronizer {
return SyncStatusSnapshot.snapshotFor(state: synchronizer.status) return SyncStatusSnapshot.snapshotFor(state: synchronizer.status)
} }
func getShieldedBalance() -> Effect<Balance, Never> { func getShieldedBalance() -> Effect<WalletBalance, Never> {
if let shieldedVerifiedBalance = synchronizer?.getShieldedVerifiedBalance(), if let shieldedVerifiedBalance: Zatoshi = synchronizer?.getShieldedVerifiedBalance(),
let shieldedTotalBalance = synchronizer?.getShieldedBalance(accountIndex: 0) { let shieldedTotalBalance: Zatoshi = synchronizer?.getShieldedBalance(accountIndex: 0) {
return Effect(value: Balance(verified: shieldedVerifiedBalance, total: shieldedTotalBalance)) return Effect(value: WalletBalance(verified: shieldedVerifiedBalance, total: shieldedTotalBalance))
} }
return .none return .none
@ -232,7 +226,7 @@ class LiveWrappedSDKSynchronizer: WrappedSDKSynchronizer {
Future { [weak self] promise in Future { [weak self] promise in
self?.synchronizer?.sendToAddress( self?.synchronizer?.sendToAddress(
spendingKey: spendingKey, spendingKey: spendingKey,
zatoshi: zatoshi.amount, zatoshi: zatoshi,
toAddress: recipientAddress, toAddress: recipientAddress,
memo: memo, memo: memo,
from: account) { result in from: account) { result in
@ -289,17 +283,17 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer {
return SyncStatusSnapshot.snapshotFor(state: synchronizer.status) return SyncStatusSnapshot.snapshotFor(state: synchronizer.status)
} }
func getShieldedBalance() -> Effect<Balance, Never> { func getShieldedBalance() -> Effect<WalletBalance, Never> {
return Effect(value: Balance(verified: 12345000, total: 12345000)) return Effect(value: WalletBalance(verified: Zatoshi(12345000), total: Zatoshi(12345000)))
} }
func getAllClearedTransactions() -> Effect<[WalletEvent], Never> { func getAllClearedTransactions() -> Effect<[WalletEvent], Never> {
let mocked: [TransactionStateMockHelper] = [ let mocked: [TransactionStateMockHelper] = [
TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: false), uuid: "1"), TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: false), uuid: "1"),
TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), uuid: "2"), TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), uuid: "2"),
TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .paid(success: true), uuid: "3"), TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .paid(success: true), uuid: "3"),
TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), uuid: "4"), TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), uuid: "4"),
TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(amount: 5), uuid: "5") TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(5), uuid: "5")
] ]
return Effect( return Effect(
@ -307,7 +301,7 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer {
mocked.map { mocked.map {
let transaction = TransactionState.placeholder( let transaction = TransactionState.placeholder(
amount: $0.amount, amount: $0.amount,
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
shielded: $0.shielded, shielded: $0.shielded,
status: $0.status, status: $0.status,
timestamp: $0.date, timestamp: $0.date,
@ -320,10 +314,10 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer {
func getAllPendingTransactions() -> Effect<[WalletEvent], Never> { func getAllPendingTransactions() -> Effect<[WalletEvent], Never> {
let mocked: [TransactionStateMockHelper] = [ let mocked: [TransactionStateMockHelper] = [
TransactionStateMockHelper(date: 1651039606, amount: Zatoshi(amount: 6), status: .paid(success: false)), TransactionStateMockHelper(date: 1651039606, amount: Zatoshi(6), status: .paid(success: false)),
TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(amount: 7)), TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(7)),
TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(amount: 8), status: .paid(success: true)), TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(8), status: .paid(success: true)),
TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(amount: 9)) TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(9))
] ]
return Effect( return Effect(
@ -331,7 +325,7 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer {
mocked.map { mocked.map {
let transaction = TransactionState.placeholder( let transaction = TransactionState.placeholder(
amount: $0.amount, amount: $0.amount,
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
shielded: $0.shielded, shielded: $0.shielded,
status: $0.status, status: $0.status,
timestamp: $0.date timestamp: $0.date
@ -368,11 +362,11 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer {
minedHeight: 50, minedHeight: 50,
shielded: true, shielded: true,
zAddress: "tteafadlamnelkqe", zAddress: "tteafadlamnelkqe",
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
id: "id", id: "id",
status: .paid(success: true), status: .paid(success: true),
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 10) zecAmount: Zatoshi(10)
) )
return Effect(value: Result.success(transactionState)) return Effect(value: Result.success(transactionState))
@ -399,17 +393,17 @@ class TestWrappedSDKSynchronizer: WrappedSDKSynchronizer {
func statusSnapshot() -> SyncStatusSnapshot { .default } func statusSnapshot() -> SyncStatusSnapshot { .default }
func getShieldedBalance() -> Effect<Balance, Never> { func getShieldedBalance() -> Effect<WalletBalance, Never> {
return .none return .none
} }
func getAllClearedTransactions() -> Effect<[WalletEvent], Never> { func getAllClearedTransactions() -> Effect<[WalletEvent], Never> {
let mocked: [TransactionStateMockHelper] = [ let mocked: [TransactionStateMockHelper] = [
TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: false), uuid: "aa11"), TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: false), uuid: "aa11"),
TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), uuid: "bb22"), TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), uuid: "bb22"),
TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .paid(success: true), uuid: "cc33"), TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .paid(success: true), uuid: "cc33"),
TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), uuid: "dd44"), TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), uuid: "dd44"),
TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(amount: 5), uuid: "ee55") TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(5), uuid: "ee55")
] ]
return Effect( return Effect(
@ -417,7 +411,7 @@ class TestWrappedSDKSynchronizer: WrappedSDKSynchronizer {
mocked.map { mocked.map {
let transaction = TransactionState.placeholder( let transaction = TransactionState.placeholder(
amount: $0.amount, amount: $0.amount,
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
shielded: $0.shielded, shielded: $0.shielded,
status: $0.status, status: $0.status,
timestamp: $0.date, timestamp: $0.date,
@ -432,13 +426,13 @@ class TestWrappedSDKSynchronizer: WrappedSDKSynchronizer {
let mocked: [TransactionStateMockHelper] = [ let mocked: [TransactionStateMockHelper] = [
TransactionStateMockHelper( TransactionStateMockHelper(
date: 1651039606, date: 1651039606,
amount: Zatoshi(amount: 6), amount: Zatoshi(6),
status: .paid(success: false), status: .paid(success: false),
uuid: "ff66" uuid: "ff66"
), ),
TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(amount: 7), uuid: "gg77"), TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(7), uuid: "gg77"),
TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(amount: 8), status: .paid(success: true), uuid: "hh88"), TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(8), status: .paid(success: true), uuid: "hh88"),
TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(amount: 9), uuid: "ii99") TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(9), uuid: "ii99")
] ]
return Effect( return Effect(
@ -446,7 +440,7 @@ class TestWrappedSDKSynchronizer: WrappedSDKSynchronizer {
mocked.map { mocked.map {
let transaction = TransactionState.placeholder( let transaction = TransactionState.placeholder(
amount: $0.amount, amount: $0.amount,
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
shielded: $0.shielded, shielded: $0.shielded,
status: $0.amount.amount > 5 ? .pending : $0.status, status: $0.amount.amount > 5 ? .pending : $0.status,
timestamp: $0.date, timestamp: $0.date,

View File

@ -60,7 +60,7 @@ class DeeplinkTests: XCTestCase {
environment: testEnvironment environment: testEnvironment
) )
let amount = Zatoshi(amount: 123_000_000) let amount = Zatoshi(123_000_000)
let address = "address" let address = "address"
let memo = "testing some memo" let memo = "testing some memo"
@ -150,7 +150,7 @@ class DeeplinkTests: XCTestCase {
store.send(.deeplink(url)) store.send(.deeplink(url))
let amount = Zatoshi(amount: 123_000_000) let amount = Zatoshi(123_000_000)
let address = "" let address = ""
let memo = "" let memo = ""
@ -199,7 +199,7 @@ class DeeplinkTests: XCTestCase {
store.send(.deeplink(url)) store.send(.deeplink(url))
let amount = Zatoshi(amount: 123_000_000) let amount = Zatoshi(123_000_000)
let address = "address" let address = "address"
let memo = "some text" let memo = "some text"

View File

@ -8,6 +8,7 @@
import XCTest import XCTest
@testable import secant_testnet @testable import secant_testnet
import ComposableArchitecture import ComposableArchitecture
import ZcashLightClientKit
class HomeTests: XCTestCase { class HomeTests: XCTestCase {
func testSynchronizerStateChanged_AnyButSynced() throws { func testSynchronizerStateChanged_AnyButSynced() throws {
@ -37,10 +38,10 @@ class HomeTests: XCTestCase {
store.receive(.updateSynchronizerStatus) store.receive(.updateSynchronizerStatus)
let balance = Balance(verified: 12_345_000, total: 12_345_000) let balance = WalletBalance(verified: Zatoshi(12_345_000), total: Zatoshi(12_345_000))
store.receive(.updateBalance(balance)) { state in store.receive(.updateBalance(balance)) { state in
state.totalBalance = Zatoshi(amount: 12_345_000) state.totalBalance = Zatoshi(12_345_000)
state.verifiedBalance = Zatoshi(amount: 12_345_000) state.verifiedBalance = Zatoshi(12_345_000)
} }
} }
@ -78,16 +79,16 @@ class HomeTests: XCTestCase {
// ad 2. // ad 2.
let transactionsHelper: [TransactionStateMockHelper] = [ let transactionsHelper: [TransactionStateMockHelper] = [
TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: false), uuid: "1"), TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: false), uuid: "1"),
TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), uuid: "2"), TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), uuid: "2"),
TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .paid(success: true), uuid: "3"), TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .paid(success: true), uuid: "3"),
TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), uuid: "4"), TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), uuid: "4"),
TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(amount: 5), uuid: "5") TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(5), uuid: "5")
] ]
let walletEvents: [WalletEvent] = transactionsHelper.map { let walletEvents: [WalletEvent] = transactionsHelper.map {
let transaction = TransactionState.placeholder( let transaction = TransactionState.placeholder(
amount: $0.amount, amount: $0.amount,
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
shielded: $0.shielded, shielded: $0.shielded,
status: $0.status, status: $0.status,
timestamp: $0.date, timestamp: $0.date,
@ -99,11 +100,11 @@ class HomeTests: XCTestCase {
store.receive(.updateWalletEvents(walletEvents)) store.receive(.updateWalletEvents(walletEvents))
// ad 3. // ad 3.
let balance = Balance(verified: 12_345_000, total: 12_345_000) let balance = WalletBalance(verified: Zatoshi(12_345_000), total: Zatoshi(12_345_000))
store.receive(.updateBalance(balance)) { state in store.receive(.updateBalance(balance)) { state in
state.verifiedBalance = Zatoshi(amount: 12_345_000) state.verifiedBalance = Zatoshi(12_345_000)
state.totalBalance = Zatoshi(amount: 12_345_000) state.totalBalance = Zatoshi(12_345_000)
} }
} }
@ -226,10 +227,10 @@ class HomeTests: XCTestCase {
store.receive(.synchronizerStateChanged(.unknown)) store.receive(.synchronizerStateChanged(.unknown))
store.receive(.updateSynchronizerStatus) store.receive(.updateSynchronizerStatus)
let balance = Balance(verified: 12_345_000, total: 12_345_000) let balance = WalletBalance(verified: Zatoshi(12_345_000), total: Zatoshi(12_345_000))
store.receive(.updateBalance(balance)) { state in store.receive(.updateBalance(balance)) { state in
state.totalBalance = Zatoshi(amount: 12_345_000) state.totalBalance = Zatoshi(12_345_000)
state.verifiedBalance = Zatoshi(amount: 12_345_000) state.verifiedBalance = Zatoshi(12_345_000)
} }
// long-living (cancelable) effects need to be properly canceled. // long-living (cancelable) effects need to be properly canceled.

View File

@ -64,11 +64,11 @@ class SendTests: XCTestCase {
minedHeight: 50, minedHeight: 50,
shielded: true, shielded: true,
zAddress: "tteafadlamnelkqe", zAddress: "tteafadlamnelkqe",
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
id: "id", id: "id",
status: .paid(success: true), status: .paid(success: true),
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 10) zecAmount: Zatoshi(10)
) )
// check the success transaction to be received back // check the success transaction to be received back

View File

@ -25,7 +25,7 @@ class HomeCircularProgressSnapshotTests: XCTestCase {
} }
} }
let balance = Balance(verified: 15_345_000, total: 15_345_000) let balance = WalletBalance(verified: Zatoshi(15_345_000), total: Zatoshi(15_345_000))
let testScheduler = DispatchQueue.test let testScheduler = DispatchQueue.test
@ -48,9 +48,9 @@ class HomeCircularProgressSnapshotTests: XCTestCase {
sendState: .placeholder, sendState: .placeholder,
scanState: .placeholder, scanState: .placeholder,
synchronizerStatusSnapshot: .default, synchronizerStatusSnapshot: .default,
totalBalance: Zatoshi(amount: balance.total), totalBalance: balance.total,
walletEventsState: .emptyPlaceHolder, walletEventsState: .emptyPlaceHolder,
verifiedBalance: Zatoshi(amount: balance.verified) verifiedBalance: balance.verified
), ),
reducer: .default, reducer: .default,
environment: testEnvironment environment: testEnvironment
@ -73,7 +73,7 @@ class HomeCircularProgressSnapshotTests: XCTestCase {
} }
} }
let balance = Balance(verified: 15_345_000, total: 15_345_000) let balance = WalletBalance(verified: 15_345_000, total: 15_345_000)
let testScheduler = DispatchQueue.test let testScheduler = DispatchQueue.test
@ -96,9 +96,9 @@ class HomeCircularProgressSnapshotTests: XCTestCase {
sendState: .placeholder, sendState: .placeholder,
scanState: .placeholder, scanState: .placeholder,
synchronizerStatusSnapshot: .default, synchronizerStatusSnapshot: .default,
totalBalance: Zatoshi(amount: balance.total), totalBalance: balance.total,
walletEventsState: .emptyPlaceHolder, walletEventsState: .emptyPlaceHolder,
verifiedBalance: Zatoshi(amount: balance.verified) verifiedBalance: balance.verified
), ),
reducer: .default, reducer: .default,
environment: testEnvironment environment: testEnvironment
@ -114,7 +114,7 @@ class HomeCircularProgressSnapshotTests: XCTestCase {
} }
} }
let balance = Balance(verified: 15_345_000, total: 15_345_000) let balance = WalletBalance(verified: 15_345_000, total: 15_345_000)
let testScheduler = DispatchQueue.test let testScheduler = DispatchQueue.test
@ -137,9 +137,9 @@ class HomeCircularProgressSnapshotTests: XCTestCase {
sendState: .placeholder, sendState: .placeholder,
scanState: .placeholder, scanState: .placeholder,
synchronizerStatusSnapshot: .default, synchronizerStatusSnapshot: .default,
totalBalance: Zatoshi(amount: balance.total), totalBalance: balance.total,
walletEventsState: .emptyPlaceHolder, walletEventsState: .emptyPlaceHolder,
verifiedBalance: Zatoshi(amount: balance.verified) verifiedBalance: balance.verified
), ),
reducer: .default, reducer: .default,
environment: testEnvironment environment: testEnvironment

View File

@ -8,20 +8,21 @@
import XCTest import XCTest
@testable import secant_testnet @testable import secant_testnet
import ComposableArchitecture import ComposableArchitecture
import ZcashLightClientKit
class HomeSnapshotTests: XCTestCase { class HomeSnapshotTests: XCTestCase {
func testHomeSnapshot() throws { func testHomeSnapshot() throws {
let transactionsHelper: [TransactionStateMockHelper] = [ let transactionsHelper: [TransactionStateMockHelper] = [
TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: true), uuid: "1"), TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: true), uuid: "1"),
TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), status: .pending, uuid: "2"), TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), status: .pending, uuid: "2"),
TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .received, uuid: "3"), TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .received, uuid: "3"),
TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), status: .failed, uuid: "4") TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), status: .failed, uuid: "4")
] ]
let walletEvents: [WalletEvent] = transactionsHelper.map { let walletEvents: [WalletEvent] = transactionsHelper.map {
var transaction = TransactionState.placeholder( var transaction = TransactionState.placeholder(
amount: $0.amount, amount: $0.amount,
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
shielded: $0.shielded, shielded: $0.shielded,
status: $0.status, status: $0.status,
timestamp: $0.date, timestamp: $0.date,
@ -32,7 +33,7 @@ class HomeSnapshotTests: XCTestCase {
return WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) return WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp)
} }
let balance = Balance(verified: 12_345_000, total: 12_345_000) let balance = WalletBalance(verified: 12_345_000, total: 12_345_000)
let store = HomeStore( let store = HomeStore(
initialState: .init( initialState: .init(
@ -42,9 +43,9 @@ class HomeSnapshotTests: XCTestCase {
sendState: .placeholder, sendState: .placeholder,
scanState: .placeholder, scanState: .placeholder,
synchronizerStatusSnapshot: .default, synchronizerStatusSnapshot: .default,
totalBalance: Zatoshi(amount: balance.total), totalBalance: balance.total,
walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: walletEvents)), walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: walletEvents)),
verifiedBalance: Zatoshi(amount: balance.verified) verifiedBalance: balance.verified
), ),
reducer: .default, reducer: .default,
environment: .demo environment: .demo

View File

@ -8,21 +8,22 @@
import XCTest import XCTest
@testable import secant_testnet @testable import secant_testnet
import ComposableArchitecture import ComposableArchitecture
import ZcashLightClientKit
// swiftlint:disable type_body_length // swiftlint:disable type_body_length
class WalletEventsSnapshotTests: XCTestCase { class WalletEventsSnapshotTests: XCTestCase {
func testFullWalletEventsSnapshot() throws { func testFullWalletEventsSnapshot() throws {
let transactionsHelper: [TransactionStateMockHelper] = [ let transactionsHelper: [TransactionStateMockHelper] = [
TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: true), uuid: "1"), TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: true), uuid: "1"),
TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), status: .pending, uuid: "2"), TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), status: .pending, uuid: "2"),
TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .received, uuid: "3"), TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .received, uuid: "3"),
TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), status: .failed, uuid: "4") TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), status: .failed, uuid: "4")
] ]
let walletEvents: [WalletEvent] = transactionsHelper.map { let walletEvents: [WalletEvent] = transactionsHelper.map {
var transaction = TransactionState.placeholder( var transaction = TransactionState.placeholder(
amount: $0.amount, amount: $0.amount,
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
shielded: $0.shielded, shielded: $0.shielded,
status: $0.status, status: $0.status,
timestamp: $0.date, timestamp: $0.date,
@ -33,7 +34,7 @@ class WalletEventsSnapshotTests: XCTestCase {
return WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) return WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp)
} }
let balance = Balance(verified: 12_345_000, total: 12_345_000) let balance = WalletBalance(verified: 12_345_000, total: 12_345_000)
let store = HomeStore( let store = HomeStore(
initialState: .init( initialState: .init(
@ -43,9 +44,9 @@ class WalletEventsSnapshotTests: XCTestCase {
sendState: .placeholder, sendState: .placeholder,
scanState: .placeholder, scanState: .placeholder,
synchronizerStatusSnapshot: .default, synchronizerStatusSnapshot: .default,
totalBalance: Zatoshi(amount: balance.total), totalBalance: balance.total,
walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: walletEvents)), walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: walletEvents)),
verifiedBalance: Zatoshi(amount: balance.verified) verifiedBalance: balance.verified
), ),
reducer: .default, reducer: .default,
environment: .demo environment: .demo
@ -72,16 +73,16 @@ class WalletEventsSnapshotTests: XCTestCase {
""", """,
minedHeight: 1_875_256, minedHeight: 1_875_256,
zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po",
fee: Zatoshi(amount: 1_000_000), fee: Zatoshi(1_000_000),
id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8",
status: .paid(success: true), status: .paid(success: true),
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 25_000_000) zecAmount: Zatoshi(25_000_000)
) )
let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp)
let balance = Balance(verified: 12_345_000, total: 12_345_000) let balance = WalletBalance(verified: 12_345_000, total: 12_345_000)
let store = HomeStore( let store = HomeStore(
initialState: .init( initialState: .init(
drawerOverlay: .partial, drawerOverlay: .partial,
@ -90,9 +91,9 @@ class WalletEventsSnapshotTests: XCTestCase {
sendState: .placeholder, sendState: .placeholder,
scanState: .placeholder, scanState: .placeholder,
synchronizerStatusSnapshot: .default, synchronizerStatusSnapshot: .default,
totalBalance: Zatoshi(amount: balance.total), totalBalance: balance.total,
walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])), walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])),
verifiedBalance: Zatoshi(amount: balance.verified) verifiedBalance: balance.verified
), ),
reducer: .default, reducer: .default,
environment: .demo environment: .demo
@ -129,16 +130,16 @@ class WalletEventsSnapshotTests: XCTestCase {
""", """,
minedHeight: 1_875_256, minedHeight: 1_875_256,
zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po",
fee: Zatoshi(amount: 1_000_000), fee: Zatoshi(1_000_000),
id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8",
status: .received, status: .received,
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 25_000_000) zecAmount: Zatoshi(25_000_000)
) )
let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp)
let balance = Balance(verified: 12_345_000, total: 12_345_000) let balance = WalletBalance(verified: 12_345_000, total: 12_345_000)
let store = HomeStore( let store = HomeStore(
initialState: .init( initialState: .init(
drawerOverlay: .partial, drawerOverlay: .partial,
@ -147,9 +148,9 @@ class WalletEventsSnapshotTests: XCTestCase {
sendState: .placeholder, sendState: .placeholder,
scanState: .placeholder, scanState: .placeholder,
synchronizerStatusSnapshot: .default, synchronizerStatusSnapshot: .default,
totalBalance: Zatoshi(amount: balance.total), totalBalance: balance.total,
walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])), walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])),
verifiedBalance: Zatoshi(amount: balance.verified) verifiedBalance: balance.verified
), ),
reducer: .default, reducer: .default,
environment: .demo environment: .demo
@ -186,16 +187,16 @@ class WalletEventsSnapshotTests: XCTestCase {
""", """,
minedHeight: 1_875_256, minedHeight: 1_875_256,
zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po",
fee: Zatoshi(amount: 1_000_000), fee: Zatoshi(1_000_000),
id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8",
status: .pending, status: .pending,
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 25_000_000) zecAmount: Zatoshi(25_000_000)
) )
let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp)
let balance = Balance(verified: 12_345_000, total: 12_345_000) let balance = WalletBalance(verified: 12_345_000, total: 12_345_000)
let store = HomeStore( let store = HomeStore(
initialState: .init( initialState: .init(
drawerOverlay: .partial, drawerOverlay: .partial,
@ -204,9 +205,9 @@ class WalletEventsSnapshotTests: XCTestCase {
sendState: .placeholder, sendState: .placeholder,
scanState: .placeholder, scanState: .placeholder,
synchronizerStatusSnapshot: .default, synchronizerStatusSnapshot: .default,
totalBalance: Zatoshi(amount: balance.total), totalBalance: balance.total,
walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])), walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])),
verifiedBalance: Zatoshi(amount: balance.verified) verifiedBalance: balance.verified
), ),
reducer: .default, reducer: .default,
environment: .demo environment: .demo
@ -249,16 +250,16 @@ class WalletEventsSnapshotTests: XCTestCase {
""", """,
minedHeight: 1_875_256, minedHeight: 1_875_256,
zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po",
fee: Zatoshi(amount: 1_000_000), fee: Zatoshi(1_000_000),
id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8",
status: .failed, status: .failed,
timestamp: 1234567, timestamp: 1234567,
zecAmount: Zatoshi(amount: 25_000_000) zecAmount: Zatoshi(25_000_000)
) )
let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp)
let balance = Balance(verified: 12_345_000, total: 12_345_000) let balance = WalletBalance(verified: 12_345_000, total: 12_345_000)
let store = HomeStore( let store = HomeStore(
initialState: .init( initialState: .init(
drawerOverlay: .partial, drawerOverlay: .partial,
@ -267,9 +268,9 @@ class WalletEventsSnapshotTests: XCTestCase {
sendState: .placeholder, sendState: .placeholder,
scanState: .placeholder, scanState: .placeholder,
synchronizerStatusSnapshot: .default, synchronizerStatusSnapshot: .default,
totalBalance: Zatoshi(amount: balance.total), totalBalance: balance.total,
walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])), walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])),
verifiedBalance: Zatoshi(amount: balance.verified) verifiedBalance: balance.verified
), ),
reducer: .default, reducer: .default,
environment: .demo environment: .demo

View File

@ -0,0 +1,15 @@
//
// WalletBalance+testing.swift
// secantTests
//
// Created by Francisco Gindre on 7/15/22.
//
import Foundation
import ZcashLightClientKit
extension WalletBalance {
init(verified: Int, total: Int) {
self.init(verified: Zatoshi(Int64(verified)), total: Zatoshi(Int64(verified)))
}
}

View File

@ -7,6 +7,7 @@
import XCTest import XCTest
@testable import secant_testnet @testable import secant_testnet
import ZcashLightClientKit
class ZatoshiTests: XCTestCase { class ZatoshiTests: XCTestCase {
let usNumberFormatter = NumberFormatter() let usNumberFormatter = NumberFormatter()
@ -21,7 +22,7 @@ class ZatoshiTests: XCTestCase {
} }
func testLowerBound() throws { func testLowerBound() throws {
let number = Zatoshi(amount: -Zatoshi.Constants.maxZatoshi - 1) let number = Zatoshi(-Zatoshi.Constants.maxZatoshi - 1)
XCTAssertEqual( XCTAssertEqual(
-Zatoshi.Constants.maxZatoshi, -Zatoshi.Constants.maxZatoshi,
@ -31,7 +32,7 @@ class ZatoshiTests: XCTestCase {
} }
func testUpperBound() throws { func testUpperBound() throws {
let number = Zatoshi(amount: Zatoshi.Constants.maxZatoshi + 1) let number = Zatoshi(Zatoshi.Constants.maxZatoshi + 1)
XCTAssertEqual( XCTAssertEqual(
Zatoshi.Constants.maxZatoshi, Zatoshi.Constants.maxZatoshi,
@ -41,37 +42,37 @@ class ZatoshiTests: XCTestCase {
} }
func testAddingZatoshi() throws { func testAddingZatoshi() throws {
let numberA1 = Zatoshi(amount: 100_000) let numberA1 = Zatoshi(100_000)
let numberB1 = Zatoshi(amount: 200_000) let numberB1 = Zatoshi(200_000)
let result1 = numberA1 + numberB1 let result1 = numberA1 + numberB1
XCTAssertEqual( XCTAssertEqual(
result1.amount, result1.amount,
Zatoshi(amount: 300_000).amount, Zatoshi(300_000).amount,
"Zatoshi tests: `testAddingZatoshi` the value is expected to be 300_000 but it's \(result1.amount)" "Zatoshi tests: `testAddingZatoshi` the value is expected to be 300_000 but it's \(result1.amount)"
) )
let numberA2 = Zatoshi(amount: -100_000) let numberA2 = Zatoshi(-100_000)
let numberB2 = Zatoshi(amount: 200_000) let numberB2 = Zatoshi(200_000)
let result2 = numberA2 + numberB2 let result2 = numberA2 + numberB2
XCTAssertEqual( XCTAssertEqual(
result2.amount, result2.amount,
Zatoshi(amount: 100_000).amount, Zatoshi(100_000).amount,
"Zatoshi tests: `testAddingZatoshi` the value is expected to be 100_000 but it's \(result2.amount)" "Zatoshi tests: `testAddingZatoshi` the value is expected to be 100_000 but it's \(result2.amount)"
) )
let numberA3 = Zatoshi(amount: 100_000) let numberA3 = Zatoshi(100_000)
let numberB3 = Zatoshi(amount: -200_000) let numberB3 = Zatoshi(-200_000)
let result3 = numberA3 + numberB3 let result3 = numberA3 + numberB3
XCTAssertEqual( XCTAssertEqual(
result3.amount, result3.amount,
Zatoshi(amount: -100_000).amount, Zatoshi(-100_000).amount,
"Zatoshi tests: `testAddingZatoshi` the value is expected to be -100_000 but it's \(result3.amount)" "Zatoshi tests: `testAddingZatoshi` the value is expected to be -100_000 but it's \(result3.amount)"
) )
let number = Zatoshi(amount: Zatoshi.Constants.maxZatoshi) let number = Zatoshi(Zatoshi.Constants.maxZatoshi)
let result4 = number + number let result4 = number + number
XCTAssertEqual( XCTAssertEqual(
@ -82,37 +83,37 @@ class ZatoshiTests: XCTestCase {
} }
func testSubtractingZatoshi() throws { func testSubtractingZatoshi() throws {
let numberA1 = Zatoshi(amount: 100_000) let numberA1 = Zatoshi(100_000)
let numberB1 = Zatoshi(amount: 200_000) let numberB1 = Zatoshi(200_000)
let result1 = numberA1 - numberB1 let result1 = numberA1 - numberB1
XCTAssertEqual( XCTAssertEqual(
result1.amount, result1.amount,
Zatoshi(amount: -100_000).amount, Zatoshi(-100_000).amount,
"Zatoshi tests: `testSubtractingZatoshi` the value is expected to be -100_000 but it's \(result1.amount)" "Zatoshi tests: `testSubtractingZatoshi` the value is expected to be -100_000 but it's \(result1.amount)"
) )
let numberA2 = Zatoshi(amount: -100_000) let numberA2 = Zatoshi(-100_000)
let numberB2 = Zatoshi(amount: 200_000) let numberB2 = Zatoshi(200_000)
let result2 = numberA2 - numberB2 let result2 = numberA2 - numberB2
XCTAssertEqual( XCTAssertEqual(
result2.amount, result2.amount,
Zatoshi(amount: -300_000).amount, Zatoshi(-300_000).amount,
"Zatoshi tests: `testSubtractingZatoshi` the value is expected to be -300_000 but it's \(result2.amount)" "Zatoshi tests: `testSubtractingZatoshi` the value is expected to be -300_000 but it's \(result2.amount)"
) )
let numberA3 = Zatoshi(amount: 100_000) let numberA3 = Zatoshi(100_000)
let numberB3 = Zatoshi(amount: -200_000) let numberB3 = Zatoshi(-200_000)
let result3 = numberA3 - numberB3 let result3 = numberA3 - numberB3
XCTAssertEqual( XCTAssertEqual(
result3.amount, result3.amount,
Zatoshi(amount: 300_000).amount, Zatoshi(300_000).amount,
"Zatoshi tests: `testSubtractingZatoshi` the value is expected to be 300_000 but it's \(result3.amount)" "Zatoshi tests: `testSubtractingZatoshi` the value is expected to be 300_000 but it's \(result3.amount)"
) )
let number = Zatoshi(amount: -Zatoshi.Constants.maxZatoshi) let number = Zatoshi(-Zatoshi.Constants.maxZatoshi)
let result4 = number + number let result4 = number + number
XCTAssertEqual( XCTAssertEqual(

View File

@ -8,6 +8,7 @@
import XCTest import XCTest
@testable import secant_testnet @testable import secant_testnet
import ComposableArchitecture import ComposableArchitecture
import ZcashLightClientKit
class WalletEventsTests: XCTestCase { class WalletEventsTests: XCTestCase {
static let testScheduler = DispatchQueue.test static let testScheduler = DispatchQueue.test
@ -42,26 +43,26 @@ class WalletEventsTests: XCTestCase {
func testSynchronizerStateChanged2Synced() throws { func testSynchronizerStateChanged2Synced() throws {
let mocked: [TransactionStateMockHelper] = [ let mocked: [TransactionStateMockHelper] = [
TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: false), uuid: "aa11"), TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: false), uuid: "aa11"),
TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), uuid: "bb22"), TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), uuid: "bb22"),
TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .paid(success: true), uuid: "cc33"), TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .paid(success: true), uuid: "cc33"),
TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), uuid: "dd44"), TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), uuid: "dd44"),
TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(amount: 5), uuid: "ee55"), TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(5), uuid: "ee55"),
TransactionStateMockHelper( TransactionStateMockHelper(
date: 1651039606, date: 1651039606,
amount: Zatoshi(amount: 6), amount: Zatoshi(6),
status: .paid(success: false), status: .paid(success: false),
uuid: "ff66" uuid: "ff66"
), ),
TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(amount: 7), uuid: "gg77"), TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(7), uuid: "gg77"),
TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(amount: 8), status: .paid(success: true), uuid: "hh88"), TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(8), status: .paid(success: true), uuid: "hh88"),
TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(amount: 9), uuid: "ii99") TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(9), uuid: "ii99")
] ]
let walletEvents: [WalletEvent] = mocked.map { let walletEvents: [WalletEvent] = mocked.map {
let transaction = TransactionState.placeholder( let transaction = TransactionState.placeholder(
amount: $0.amount, amount: $0.amount,
fee: Zatoshi(amount: 10), fee: Zatoshi(10),
shielded: $0.shielded, shielded: $0.shielded,
status: $0.amount.amount > 5 ? .pending : $0.status, status: $0.amount.amount > 5 ? .pending : $0.status,
timestamp: $0.date, timestamp: $0.date,