Skip to content

Commit

Permalink
[#1341] Add Support for GetSubTreeRoots in Advanced Re Org tests
Browse files Browse the repository at this point in the history
closes #1341

Updates Proto files and compile new swift versions

Adds setSubTree darkside service
adds subtrees into buildFakeChain() methods
  • Loading branch information
pacu committed Jun 26, 2024
1 parent 5e41914 commit eb6daba
Show file tree
Hide file tree
Showing 8 changed files with 1,063 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ message TxFilter {
bytes hash = 3; // transaction ID (hash, txid)
}

// RawTransaction contains the complete transaction data. It also optionally includes
// RawTransaction contains the complete transaction data. It also optionally includes
// the block height in which the transaction was included, or, when returned
// by GetMempoolStream(), the latest block height.
message RawTransaction {
Expand Down Expand Up @@ -170,7 +170,8 @@ service CompactTxStreamer {
// Submit the given transaction to the Zcash network
rpc SendTransaction(RawTransaction) returns (SendResponse) {}

// Return the txids corresponding to the given t-address within the given block range
// Return the transactions corresponding to the given t-address within the given block range
// NB - this method is misnamed, it returns transactions, not transaction IDs.
rpc GetTaddressTxids(TransparentAddressBlockFilter) returns (stream RawTransaction) {}
rpc GetTaddressBalance(AddressList) returns (Balance) {}
rpc GetTaddressBalanceStream(stream Address) returns (Balance) {}
Expand All @@ -197,8 +198,8 @@ service CompactTxStreamer {
rpc GetTreeState(BlockID) returns (TreeState) {}
rpc GetLatestTreeState(Empty) returns (TreeState) {}

// Returns a stream of information about roots of subtrees of the Sapling and Orchard
// note commitment trees.
// Returns a stream of information about roots of subtrees of the note commitment tree
// for the specified shielded protocol (Sapling or Orchard).
rpc GetSubtreeRoots(GetSubtreeRootsArg) returns (stream SubtreeRoot) {}

rpc GetAddressUtxos(GetAddressUtxosArg) returns (GetAddressUtxosReplyList) {}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ enum ShieldedProtocol: SwiftProtobuf.Enum {

extension ShieldedProtocol: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
static var allCases: [ShieldedProtocol] = [
static let allCases: [ShieldedProtocol] = [
.sapling,
.orchard,
]
Expand Down Expand Up @@ -144,7 +144,7 @@ struct TxFilter {
fileprivate var _block: BlockID? = nil
}

/// RawTransaction contains the complete transaction data. It also optionally includes
/// RawTransaction contains the complete transaction data. It also optionally includes
/// the block height in which the transaction was included, or, when returned
/// by GetMempoolStream(), the latest block height.
struct RawTransaction {
Expand Down
4 changes: 4 additions & 0 deletions Tests/TestUtils/DarkSideWalletService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ class DarksideWalletService: LightWalletService {
func getTreeState(_ id: BlockID) async throws -> TreeState {
try await service.getTreeState(id)
}

func setSubtreeRoots(_ request: DarksideSubtreeRoots) {
_ = darksideService.setSubtreeRoots(request)
}
}

enum DarksideWalletDConstants: NetworkConstants {
Expand Down
84 changes: 58 additions & 26 deletions Tests/TestUtils/FakeChainBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ enum FakeChainBuilderError: Error {
enum FakeChainBuilder {
static let someOtherTxUrl = "https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/transactions/t-shielded-spend.txt"
static let txMainnetBlockUrl = "https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/basic-reorg/663150.txt"

static let testnetCanopyUpdateUrl = "https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/testnet-canopy/1028400-1028600.txt"

static let testnetCanopyStartBlock = "https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/testnet-canopy/1013250.txt"
static let testnetPreCanopyTx = "https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/testnet-canopy/pre-activation-txs/61088726aaa7c25b0568dd7bf19955f4a57f7173034e720c924107ff05cd3649.txt"

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,
Expand All @@ -31,14 +31,14 @@ enum FakeChainBuilder {
branchID: branchID,
chainName: chainName
)

try darksideWallet.useDataset(from: txMainnetBlockUrl)

try darksideWallet.stageBlocksCreate(from: 663151, count: 100)

try darksideWallet.stageTransaction(from: txUrls[663174]!, at: 663174)
}

static func buildChain(darksideWallet: DarksideWalletService, branchID: String, chainName: String) throws {
try darksideWallet.reset(
saplingActivation: 663150,
Expand All @@ -47,7 +47,7 @@ enum FakeChainBuilder {
branchID: branchID,
chainName: chainName
)

try darksideWallet.useDataset(from: txMainnetBlockUrl)


Expand Down Expand Up @@ -78,12 +78,14 @@ enum FakeChainBuilder {
)

try darksideWallet.stageBlocksCreate(from: 663151, count: 100)

try darksideWallet.stageTransaction(from: txUrls[663174]!, at: 663174)

try darksideWallet.stageTransaction(from: txUrls[663188]!, at: 663188)

try setSubTreeRoots(service: darksideWallet)
}

static func buildChainWithTxsFarFromEachOther(darksideWallet: DarksideWalletService, branchID: String, chainName: String, length: Int) throws {
try darksideWallet.reset(
saplingActivation: 663150,
Expand All @@ -92,16 +94,16 @@ enum FakeChainBuilder {
branchID: branchID,
chainName: chainName
)

try darksideWallet.useDataset(from: txMainnetBlockUrl)

try darksideWallet.stageBlocksCreate(from: 663151, count: length)

try darksideWallet.stageTransaction(from: txUrls[663188]!, at: 663188)

try darksideWallet.stageTransaction(from: txUrls[663974]!, at: 663974)
}

static func buildChain(darksideWallet: DarksideWalletService, branchID: String, chainName: String, length: Int) throws {
try darksideWallet.reset(
saplingActivation: 663150,
Expand All @@ -110,20 +112,20 @@ enum FakeChainBuilder {
branchID: branchID,
chainName: chainName
)

try darksideWallet.useDataset(from: txMainnetBlockUrl)

try darksideWallet.stageBlocksCreate(from: 663151, count: length)
try darksideWallet.stageTransaction(from: txUrls[663174]!, at: 663174)
try darksideWallet.stageTransaction(from: txUrls[663188]!, at: 663188)
try darksideWallet.stageTransaction(from: txUrls[663202]!, at: 663202)
try darksideWallet.stageTransaction(from: txUrls[663218]!, at: 663218)
try darksideWallet.stageTransaction(from: txUrls[663229]!, at: 663229)

try darksideWallet.stageTransaction(from: txUrls[663953]!, at: 663953)
try darksideWallet.stageTransaction(from: txUrls[663974]!, at: 663974)
}

static func buildChain(
darksideWallet: DarksideWalletService,
birthday: BlockHeight,
Expand All @@ -146,7 +148,7 @@ enum FakeChainBuilder {
try darksideWallet.stageBlocksCreate(from: birthday + 1, count: length)
try darksideWallet.stageTransaction(from: testnetPreCanopyTx, at: networkActivationHeight - ZcashSDK.expiryOffset)
}

static func buildChainPostActivationFunds(darksideWallet: DarksideWalletService, birthday: BlockHeight, startSaplingTreeSize: UInt32, startOrchardTreeSize: UInt32, networkActivationHeight: BlockHeight, length: Int) throws {
try darksideWallet.reset(
saplingActivation: birthday,
Expand All @@ -160,7 +162,7 @@ enum FakeChainBuilder {
try darksideWallet.stageBlocksCreate(from: birthday + 1, count: length)
try darksideWallet.stageTransaction(from: testnetPostCanopyTx, at: networkActivationHeight + 1)
}

static func buildChainMixedFunds(
darksideWallet: DarksideWalletService,
birthday: BlockHeight,
Expand All @@ -181,14 +183,14 @@ enum FakeChainBuilder {
chainName: chainName,
length: length
)

try darksideWallet.stageTransaction(from: testnetPostCanopyTx, at: networkActivationHeight + ZcashSDK.expiryOffset)
}

static func buildTxUrl(for id: String) -> String {
"https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/transactions/recv/\(id).txt"
}

static let txUrls = [
663174: buildTxUrl(for: "8f064d23c66dc36e32445e5f3b50e0f32ac3ddb78cff21fb521eb6c19c07c99a"),
663188: buildTxUrl(for: "15a677b6770c5505fb47439361d3d3a7c21238ee1a6874fdedad18ae96850590"),
Expand Down Expand Up @@ -271,4 +273,34 @@ enum FakeChainBuilder {
822410: buildTxUrl(for: "f3f8684be8d77367d099a38f30e3652410cdebe35c006d0599d86d8ec640867f"),
828933: buildTxUrl(for: "1fd394257d1c10c8a70fb760cf73f6d0e96e61edcf1ffca6da12d733a59221a4")
]

static func setSubTreeRoots(service: DarksideWalletService) throws {
let subtreeRoots = try DarksideSubtreeRoots.with { subtreeRoots in
subtreeRoots.shieldedProtocol = .sapling
subtreeRoots.startIndex = 0
subtreeRoots.subtreeRoots = [
try .init(
jsonString:
"""
{
"rootHash": "dUu1k+pC0jGn3fNnZA8Ju/WdwA8sHSADzDQODAFrWxM=",
"completingBlockHash": "AAAAAACPmsBjbYHceVyw9Ulab9B06BWhnhmfDaSRUf4=",
"completingBlockHeight": "558822"
}
"""
),
try .init(
jsonString:
"""
{
"rootHash": "A2VMPqy7m5PhIs9td7YG6uKWEPTzikd5hTaBl/1o4C0=",
"completingBlockHash": "AAAAAAIFzQaAI1LPzYkhgVvQqdc+ta/D7AnzXHGARqk=",
"completingBlockHeight": "670209"
}
"""
)
]
}
service.setSubtreeRoots(subtreeRoots)
}
}
Loading

0 comments on commit eb6daba

Please sign in to comment.