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

Migrate to latest darkside.proto to help fix Darkside tests #1191

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SDKSynchronizerAliasDarksideTests: ZcashTestCase {
endpoint: endpoint
)

try await coordinator.reset(saplingActivation: birthday, branchID: branchID, chainName: chainName)
try await coordinator.reset(saplingActivation: birthday, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: branchID, chainName: chainName)

coordinators.append(coordinator)
}
Expand Down
14 changes: 10 additions & 4 deletions Tests/DarksideTests/AdvancedReOrgTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AdvancedReOrgTests: ZcashTestCase {
walletBirthday: birthday + 50,
network: network
)
try await coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName)
try await coordinator.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: self.branchID, chainName: self.chainName)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of the tests reference block height 663150, which corresponds to a persisted mainnet block elsewhere in the codebase. So everywhere I see that reference, I applied the Sapling tree size corresponding to it. There's likely a nicer way to do this, but that's refactoring I don't know how to do in Swift.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coupled to the datasets for these tests here https://github.com/zcash-hackworks/darksidewalletd-test-data

These tests start from 663150 onwards. that's why they have that height. If you were to use another height then you need to reference a new dataset.

I think that this change makes sense.

Does Sbs require the wallet to get TreeStates to make node spendable? If so you should get those into dlwd as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@str4d how do you obtain this tree size?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obtaining the tree states is what enables fast spendability; I believe that @str4d has already made the required change to lightwalletd here: zcash/lightwalletd#448

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, the wallets should still function when connected to a LWD that doesn't support retrieval of tree states, but they'll be limited to linear scanning.

Copy link
Collaborator Author

@str4d str4d Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pacu I fetched the tree size for that block height from my mainnet zcashd node. One of the RPCs exposes it.

}

override func tearDown() async throws {
Expand Down Expand Up @@ -453,7 +453,13 @@ class AdvancedReOrgTests: ZcashTestCase {
await hookToReOrgNotification()
self.expectedReorgHeight = 663196
self.expectedRewindHeight = 663175
try await coordinator.reset(saplingActivation: birthday, branchID: "2bb40e60", chainName: "main")
try await coordinator.reset(
saplingActivation: birthday,
startSaplingTreeSize: 128607,
startOrchardTreeSize: 0,
branchID: "2bb40e60",
chainName: "main"
)
try coordinator.resetBlocks(dataset: .predefined(dataset: .txIndexChangeBefore))
try coordinator.applyStaged(blockheight: 663195)
sleep(1)
Expand Down Expand Up @@ -1031,7 +1037,7 @@ class AdvancedReOrgTests: ZcashTestCase {
/// 8. sync to latest height
/// 9. verify that the balance is equal to the one before the reorg
func testReOrgChangesInboundMinedHeight() async throws {
try await coordinator.reset(saplingActivation: 663150, branchID: branchID, chainName: chainName)
try await coordinator.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: branchID, chainName: chainName)
sleep(2)
try coordinator.resetBlocks(dataset: .predefined(dataset: .txHeightReOrgBefore))
sleep(2)
Expand Down Expand Up @@ -1096,7 +1102,7 @@ class AdvancedReOrgTests: ZcashTestCase {
// FIXME [#644]: Test works with lightwalletd v0.4.13 but is broken when using newer lightwalletd. More info is in #644.
func testReOrgRemovesIncomingTxForever() async throws {
await hookToReOrgNotification()
try await coordinator.reset(saplingActivation: 663150, branchID: branchID, chainName: chainName)
try await coordinator.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: branchID, chainName: chainName)

try coordinator.resetBlocks(dataset: .predefined(dataset: .txReOrgRemovesInboundTxBefore))

Expand Down
2 changes: 1 addition & 1 deletion Tests/DarksideTests/BalanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BalanceTests: ZcashTestCase {
walletBirthday: birthday,
network: network
)
try await coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
try await coordinator.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: "e9ff75a6", chainName: "main")
}

override func tearDown() async throws {
Expand Down
2 changes: 1 addition & 1 deletion Tests/DarksideTests/DarksideSanityCheckTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DarksideSanityCheckTests: ZcashTestCase {
network: network
)

try await coordinator.reset(saplingActivation: self.birthday, branchID: self.branchID, chainName: self.chainName)
try await coordinator.reset(saplingActivation: self.birthday, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: self.branchID, chainName: self.chainName)
try self.coordinator.resetBlocks(dataset: .default)
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/DarksideTests/PendingTransactionUpdatesTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PendingTransactionUpdatesTest: ZcashTestCase {
walletBirthday: birthday,
network: network
)
try await coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
try await coordinator.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: "e9ff75a6", chainName: "main")
}

override func tearDown() async throws {
Expand Down
4 changes: 2 additions & 2 deletions Tests/DarksideTests/ReOrgTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ReOrgTests: ZcashTestCase {
network: self.network
)

try await coordinator.reset(saplingActivation: self.birthday, branchID: self.branchID, chainName: self.chainName)
try await coordinator.reset(saplingActivation: self.birthday, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: self.branchID, chainName: self.chainName)

try self.coordinator.resetBlocks(dataset: .default)

Expand Down Expand Up @@ -128,7 +128,7 @@ class ReOrgTests: ZcashTestCase {
targetHeight: BlockHeight
) async throws {
do {
try await coordinator.reset(saplingActivation: birthday, branchID: branchID, chainName: chainName)
try await coordinator.reset(saplingActivation: birthday, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: branchID, chainName: chainName)
try coordinator.resetBlocks(dataset: .predefined(dataset: .beforeReOrg))
try coordinator.applyStaged(blockheight: firstLatestHeight)
sleep(1)
Expand Down
2 changes: 1 addition & 1 deletion Tests/DarksideTests/RewindRescanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RewindRescanTests: ZcashTestCase {
walletBirthday: birthday,
network: network
)
try await coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
try await coordinator.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: "e9ff75a6", chainName: "main")
}

override func tearDown() async throws {
Expand Down
2 changes: 1 addition & 1 deletion Tests/DarksideTests/ShieldFundsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ShieldFundsTests: ZcashTestCase {
walletBirthday: birthday,
network: network
)
try await coordinator.reset(saplingActivation: birthday, branchID: self.branchID, chainName: self.chainName)
try await coordinator.reset(saplingActivation: birthday, startSaplingTreeSize: 1120954, startOrchardTreeSize: 0, branchID: self.branchID, chainName: self.chainName)
try coordinator.service.clearAddedUTXOs()
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/DarksideTests/SynchronizerDarksideTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SynchronizerDarksideTests: ZcashTestCase {
network: network
)

try await coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
try await coordinator.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: "e9ff75a6", chainName: "main")
}

override func tearDown() async throws {
Expand Down
2 changes: 1 addition & 1 deletion Tests/DarksideTests/SynchronizerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class SynchronizerTests: ZcashTestCase {
walletBirthday: birthday + 50,
network: network
)
try await coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName)
try await coordinator.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: self.branchID, chainName: self.chainName)

let eventClosure: CompactBlockProcessor.EventClosure = { [weak self] event in
switch event {
Expand Down
2 changes: 1 addition & 1 deletion Tests/DarksideTests/Z2TReceiveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Z2TReceiveTests: ZcashTestCase {
walletBirthday: birthday,
network: network
)
try await coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName)
try await coordinator.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: self.branchID, chainName: self.chainName)
}

override func tearDown() async throws {
Expand Down
10 changes: 9 additions & 1 deletion Tests/TestUtils/DarkSideWalletService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,19 @@ class DarksideWalletService: LightWalletService {
}
}

func reset(saplingActivation: BlockHeight, branchID: String = "d3adb33f", chainName: String = "test") throws {
func reset(
saplingActivation: BlockHeight,
startSaplingTreeSize: UInt32,
startOrchardTreeSize: UInt32,
branchID: String = "d3adb33f",
chainName: String = "test"
) throws {
var metaState = DarksideMetaState()
metaState.saplingActivation = Int32(saplingActivation)
metaState.branchID = branchID
metaState.chainName = chainName
metaState.startSaplingCommitmentTreeSize = startSaplingTreeSize
metaState.startOrchardCommitmentTreeSize = startOrchardTreeSize
// TODO: [#718] complete meta state correctly, https://github.com/zcash/ZcashLightClientKit/issues/718
_ = try darksideService.reset(metaState).response.wait()
}
Expand Down
20 changes: 13 additions & 7 deletions Tests/TestUtils/FakeChainBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum FakeChainBuilder {
static let testnetPostCanopyTx = "https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/testnet-canopy/post-activation-txs/ecaa6c03709d70aa25446a81690b18ddb11daac96a03fe4b5cfd0d89a49fb963.txt"

static func buildSingleNoteChain(darksideWallet: DarksideWalletService, branchID: String, chainName: String) throws {
try darksideWallet.reset(saplingActivation: 663150, branchID: branchID, chainName: chainName)
try darksideWallet.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: branchID, chainName: chainName)
try darksideWallet.useDataset(from: txMainnetBlockUrl)

try darksideWallet.stageBlocksCreate(from: 663151, count: 100)
Expand All @@ -33,7 +33,7 @@ enum FakeChainBuilder {
}

static func buildChain(darksideWallet: DarksideWalletService, branchID: String, chainName: String) throws {
try darksideWallet.reset(saplingActivation: 663150, branchID: branchID, chainName: chainName)
try darksideWallet.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: branchID, chainName: chainName)
try darksideWallet.useDataset(from: txMainnetBlockUrl)

try darksideWallet.stageBlocksCreate(from: 663151, count: 100)
Expand All @@ -44,7 +44,7 @@ enum FakeChainBuilder {
}

static func buildChainWithTxsFarFromEachOther(darksideWallet: DarksideWalletService, branchID: String, chainName: String, length: Int) throws {
try darksideWallet.reset(saplingActivation: 663150, branchID: branchID, chainName: chainName)
try darksideWallet.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: branchID, chainName: chainName)
try darksideWallet.useDataset(from: txMainnetBlockUrl)

try darksideWallet.stageBlocksCreate(from: 663151, count: length)
Expand All @@ -55,7 +55,7 @@ enum FakeChainBuilder {
}

static func buildChain(darksideWallet: DarksideWalletService, branchID: String, chainName: String, length: Int) throws {
try darksideWallet.reset(saplingActivation: 663150, branchID: branchID, chainName: chainName)
try darksideWallet.reset(saplingActivation: 663150, startSaplingTreeSize: 128607, startOrchardTreeSize: 0, branchID: branchID, chainName: chainName)
try darksideWallet.useDataset(from: txMainnetBlockUrl)

try darksideWallet.stageBlocksCreate(from: 663151, count: length)
Expand All @@ -72,20 +72,22 @@ enum FakeChainBuilder {
static func buildChain(
darksideWallet: DarksideWalletService,
birthday: BlockHeight,
startSaplingTreeSize: UInt32,
startOrchardTreeSize: UInt32,
networkActivationHeight: BlockHeight,
branchID: String,
chainName: String,
length: Int
) throws {
try darksideWallet.reset(saplingActivation: birthday, branchID: branchID, chainName: chainName)
try darksideWallet.reset(saplingActivation: birthday, startSaplingTreeSize: startSaplingTreeSize, startOrchardTreeSize: startOrchardTreeSize, branchID: branchID, chainName: chainName)

try darksideWallet.useDataset(testnetCanopyStartBlock)
try darksideWallet.stageBlocksCreate(from: birthday + 1, count: length)
try darksideWallet.stageTransaction(from: testnetPreCanopyTx, at: networkActivationHeight - ZcashSDK.expiryOffset)
}

static func buildChainPostActivationFunds(darksideWallet: DarksideWalletService, birthday: BlockHeight, networkActivationHeight: BlockHeight, length: Int) throws {
try darksideWallet.reset(saplingActivation: birthday, branchID: "e9ff75a6", chainName: "testnet")
static func buildChainPostActivationFunds(darksideWallet: DarksideWalletService, birthday: BlockHeight, startSaplingTreeSize: UInt32, startOrchardTreeSize: UInt32, networkActivationHeight: BlockHeight, length: Int) throws {
try darksideWallet.reset(saplingActivation: birthday, startSaplingTreeSize: startSaplingTreeSize, startOrchardTreeSize: startOrchardTreeSize, branchID: "e9ff75a6", chainName: "testnet")

try darksideWallet.useDataset(testnetCanopyStartBlock)
try darksideWallet.stageBlocksCreate(from: birthday + 1, count: length)
Expand All @@ -95,6 +97,8 @@ enum FakeChainBuilder {
static func buildChainMixedFunds(
darksideWallet: DarksideWalletService,
birthday: BlockHeight,
startSaplingTreeSize: UInt32,
startOrchardTreeSize: UInt32,
networkActivationHeight: BlockHeight,
branchID: String,
chainName: String,
Expand All @@ -103,6 +107,8 @@ enum FakeChainBuilder {
try buildChain(
darksideWallet: darksideWallet,
birthday: birthday,
startSaplingTreeSize: startSaplingTreeSize,
startOrchardTreeSize: startOrchardTreeSize,
networkActivationHeight: networkActivationHeight,
branchID: branchID,
chainName: chainName,
Expand Down
4 changes: 2 additions & 2 deletions Tests/TestUtils/TestCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ extension TestCoordinator {
try await service.latestBlockHeight()
}

func reset(saplingActivation: BlockHeight, branchID: String, chainName: String) async throws {
func reset(saplingActivation: BlockHeight, startSaplingTreeSize: UInt32, startOrchardTreeSize: UInt32, branchID: String, chainName: String) async throws {
await self.synchronizer.blockProcessor.stop()

let config = await self.synchronizer.blockProcessor.config
Expand All @@ -229,7 +229,7 @@ extension TestCoordinator {

await self.synchronizer.blockProcessor.update(config: newConfig)

try service.reset(saplingActivation: saplingActivation, branchID: branchID, chainName: chainName)
try service.reset(saplingActivation: saplingActivation, startSaplingTreeSize: startSaplingTreeSize, startOrchardTreeSize: startOrchardTreeSize, branchID: branchID, chainName: chainName)
}

func getIncomingTransactions() throws -> [RawTransaction]? {
Expand Down
Loading
Loading