Skip to content
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

[#1330] Ability to provide custom checkpoints on Testing environments #1331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -7,7 +7,7 @@

import Foundation

struct CheckpointSourceFactory {
enum CheckpointSourceFactory {
static func fromBundle(for network: NetworkType) -> CheckpointSource {
BundleCheckpointSource(network: network)
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/DarksideTests/AdvancedReOrgTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class AdvancedReOrgTests: ZcashTestCase {
override func setUp() async throws {
try await super.setUp()

mockContainer.mock(type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

// don't use an exact birthday, users never do.
self.coordinator = try await TestCoordinator(
container: mockContainer,
Expand Down
4 changes: 4 additions & 0 deletions Tests/DarksideTests/BalanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class BalanceTests: ZcashTestCase {
override func setUp() async throws {
try await super.setUp()

mockContainer.mock(type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

self.coordinator = try await TestCoordinator(
container: mockContainer,
walletBirthday: birthday,
Expand Down
8 changes: 6 additions & 2 deletions Tests/DarksideTests/BlockDownloaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import XCTest
@testable import TestUtils
@testable import ZcashLightClientKit

class BlockDownloaderTests: XCTestCase {
class BlockDownloaderTests: ZcashTestCase {
let branchID = "2bb40e60"
let chainName = "main"

Expand All @@ -21,10 +21,14 @@ class BlockDownloaderTests: XCTestCase {
var storage: CompactBlockRepository!
var network = DarksideWalletDNetwork()
var rustBackend: ZcashRustBackendWelding!
var testTempDirectory: URL!

override func setUp() async throws {
try await super.setUp()

mockContainer.mock(type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

testTempDirectory = Environment.uniqueTestTempDirectory

service = LightWalletServiceFactory(endpoint: LightWalletEndpointBuilder.default).make()
Expand Down
4 changes: 4 additions & 0 deletions Tests/DarksideTests/DarksideSanityCheckTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class DarksideSanityCheckTests: ZcashTestCase {
override func setUp() async throws {
try await super.setUp()

mockContainer.mock (type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

self.coordinator = try await TestCoordinator(
container: mockContainer,
walletBirthday: birthday,
Expand Down
4 changes: 4 additions & 0 deletions Tests/DarksideTests/PendingTransactionUpdatesTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class PendingTransactionUpdatesTest: ZcashTestCase {
override func setUp() async throws {
try await super.setUp()

mockContainer.mock(type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

self.coordinator = try await TestCoordinator(
container: mockContainer,
walletBirthday: birthday,
Expand Down
4 changes: 4 additions & 0 deletions Tests/DarksideTests/ReOrgTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class ReOrgTests: ZcashTestCase {
override func setUp() async throws {
try await super.setUp()

mockContainer.mock(type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

self.coordinator = try await TestCoordinator(
container: mockContainer,
walletBirthday: self.birthday,
Expand Down
4 changes: 4 additions & 0 deletions Tests/DarksideTests/ShieldFundsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class ShieldFundsTests: ZcashTestCase {
override func setUp() async throws {
try await super.setUp()

mockContainer.mock(type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

self.coordinator = try await TestCoordinator(
container: mockContainer,
walletBirthday: birthday,
Expand Down
5 changes: 5 additions & 0 deletions Tests/DarksideTests/SynchronizerDarksideTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class SynchronizerDarksideTests: ZcashTestCase {

override func setUp() async throws {
try await super.setUp()

mockContainer.mock(type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

let idGenerator = MockSyncSessionIDGenerator(ids: [.deadbeef])
mockContainer.mock(type: SyncSessionIDGenerator.self, isSingleton: false) { _ in idGenerator }
self.idGenerator = idGenerator
Expand Down
6 changes: 5 additions & 1 deletion Tests/DarksideTests/SynchronizerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ final class SynchronizerTests: ZcashTestCase {

override func setUp() async throws {
try await super.setUp()


mockContainer.mock(type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

// don't use an exact birthday, users never do.
self.coordinator = try await TestCoordinator(
container: mockContainer,
Expand Down
4 changes: 4 additions & 0 deletions Tests/DarksideTests/Z2TReceiveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Z2TReceiveTests: ZcashTestCase {
override func setUp() async throws {
try await super.setUp()

mockContainer.mock(type: CheckpointSource.self, isSingleton: true) { _ in
return DarksideMainnetCheckpointSource()
}

self.coordinator = try await TestCoordinator(
container: mockContainer,
walletBirthday: birthday,
Expand Down
35 changes: 35 additions & 0 deletions Tests/TestUtils/DarksideMainnetCheckpointSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// TestingCheckpoints.swift
//
//
// Created by Francisco Gindre on 2023-10-31.
//

import Foundation
@testable import ZcashLightClientKit

struct DarksideMainnetCheckpointSource: CheckpointSource {
private let treeState = Checkpoint(
height: 663150,
hash: "0000000002fd3be4c24c437bd22620901617125ec2a3a6c902ec9a6c06f734fc",
time: 1576821833,
saplingTree: "01ec6278a1bed9e1b080fd60ef50eb17411645e3746ff129283712bc4757ecc833001001b4e1d4a26ac4a2810b57a14f4ffb69395f55dde5674ecd2462af96f9126e054701a36afb68534f640938bdffd80dfcb3f4d5e232488abbf67d049b33a761e7ed6901a16e35205fb7fe626a9b13fc43e1d2b98a9c241f99f93d5e93a735454073025401f5b9bcbf3d0e3c83f95ee79299e8aeadf30af07717bda15ffb7a3d00243b58570001fa6d4c2390e205f81d86b85ace0b48f3ce0afb78eeef3e14c70bcfd7c5f0191c0000011bc9521263584de20822f9483e7edb5af54150c4823c775b2efc6a1eded9625501a6030f8d4b588681eddb66cad63f09c5c7519db49500fc56ebd481ce5e903c22000163f4eec5a2fe00a5f45e71e1542ff01e937d2210c99f03addcce5314a5278b2d0163ab01f46a3bb6ea46f5a19d5bdd59eb3f81e19cfa6d10ab0fd5566c7a16992601fa6980c053d84f809b6abcf35690f03a11f87b28e3240828e32e3f57af41e54e01319312241b0031e3a255b0d708750b4cb3f3fe79e3503fe488cc8db1dd00753801754bb593ea42d231a7ddf367640f09bbf59dc00f2c1d2003cc340e0c016b5b13",
orchardTree: nil
)

var network: NetworkType {
DarksideWalletDNetwork().networkType
}

var saplingActivation: Checkpoint {
treeState
}

func latestKnownCheckpoint() -> Checkpoint {
treeState
}

func birthday(for height: BlockHeight) -> Checkpoint {
treeState
}
}
Loading