Skip to content

Commit

Permalink
Merge pull request #7 from zancas/spent_process_2024
Browse files Browse the repository at this point in the history
Spent process 2024
  • Loading branch information
fluidvanadium authored Jan 17, 2024
2 parents 198e7ca + 0db74ec commit 8f633ec
Show file tree
Hide file tree
Showing 19 changed files with 452 additions and 332 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Symlink lightwalletd and zcash binaries for darkside-tests
run: ln -s /usr/bin/lightwalletd ./darkside-tests/lightwalletd_bin/
- name: create binaries dir
run: mkdir -p ./zingo-testutils/test_binaries/bins

- name: Symlink lightwalletd and zcash binaries for integration-tests
run: ln -s /usr/bin/lightwalletd /usr/bin/zcashd /usr/bin/zcash-cli ./integration-tests/regtest/bin/
- name: Symlink lightwalletd and zcash binaries
run: ln -s /usr/bin/lightwalletd /usr/bin/zcashd /usr/bin/zcash-cli ./zingo-testutils/test_binaries/bins/

- name: Symlink zcash parameters
run: ln -s /root/.zcash-params /github/home
Expand Down
34 changes: 15 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
zingocli/regtest/data/zcashd/regtest/
zingocli/regtest/data/lightwalletd/
zingocli/regtest/data/zingo/
!zingolib/test-data/README
!zingolib/test-data/openssl_cfg
*.json.txt
.DS_Store
/procgov
/testdata
cobertura.xml
docker-ci/lightwalletd
target
wallets/*
zingocli/regtest/logs/
zingocli/regtest/zingo-wallet.dat
zingocli/regtest/bin
integration-tests/regtest/bin
target
zingolib/target
zingocli/target
/testdata
/procgov
.DS_Store
*.json.txt
docker-ci/lightwalletd
zingolib/test-data/*
!zingolib/test-data/README
!zingolib/test-data/openssl_cfg
zingocli/tests/data/basic_zcashd.conf
zingocli/tests/data/externalwallet_coinbaseaddress.conf
zingocli/tests/data/lightwalletd.yml
zingocli/tests/data/basic_zcashd.conf
cobertura.xml
zingocli/tests/times/*
wallets/*
zingocli/wallets/*
darkside-tests/lightwalletd_bin/
zingolib/target
zingolib/test-data/*
zingo-testutils/test_binaries

103 changes: 95 additions & 8 deletions darkside-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use zcash_primitives::{merkle_tree::read_commitment_tree, transaction::Transacti
use zingo_testutils::{
self,
incrementalmerkletree::frontier::CommitmentTree,
regtest::{get_cargo_manifest_dir, launch_lightwalletd},
paths::{get_bin_dir, get_cargo_manifest_dir},
regtest::launch_lightwalletd,
scenarios::setup::TestEnvironmentGenerator,
};
use zingolib::wallet::traits::DomainWalletExt;
Expand Down Expand Up @@ -251,7 +252,7 @@ impl DarksideHandler {
darkside_dir.join("logs"),
darkside_dir.join("conf"),
darkside_dir.join("data"),
get_cargo_manifest_dir().join("lightwalletd_bin"),
get_bin_dir(),
check_interval,
grpc_bind_addr,
);
Expand Down Expand Up @@ -430,7 +431,7 @@ pub async fn init_darksidewalletd(
pub fn create_chainbuild_file(test_name: &str) -> File {
let path = format!(
"{}/tests/data/chainbuilds/{}",
zingo_testutils::regtest::get_cargo_manifest_dir().to_string_lossy(),
get_cargo_manifest_dir().to_string_lossy(),
test_name
);
match fs::create_dir(path.clone()) {
Expand All @@ -453,7 +454,7 @@ pub fn create_chainbuild_file(test_name: &str) -> File {
pub fn load_chainbuild_file(test_name: &str) -> Vec<String> {
let path = format!(
"{}/tests/data/chainbuilds/{}",
zingo_testutils::regtest::get_cargo_manifest_dir().to_string_lossy(),
get_cargo_manifest_dir().to_string_lossy(),
test_name
);
let filename = "hex_transactions.txt";
Expand Down Expand Up @@ -516,6 +517,7 @@ pub mod scenarios {
lightclients: Vec<LightClient>,
staged_blockheight: BlockHeight,
tree_state: TreeState,
transaction_set_index: u64,
}
impl DarksideScenario {
/// Initialises and launches darksidewalletd, stages the genesis block and creates the lightclient builder
Expand All @@ -536,6 +538,7 @@ pub mod scenarios {
lightclients: vec![],
staged_blockheight: BlockHeight::from(1),
tree_state: constants::first_tree_state(),
transaction_set_index: 0,
}
}
pub async fn default() -> DarksideScenario {
Expand Down Expand Up @@ -578,8 +581,9 @@ pub mod scenarios {
self.lightclients.push(lightclient);
self
}
/// Stage and apply a range of blocks and update tree state.
pub async fn generate_blocks(
/// Stage blocks up to target height and update tree state.
/// Does not apply block.
pub async fn stage_blocks(
&mut self,
target_blockheight: u64,
nonce: u64,
Expand All @@ -600,16 +604,31 @@ pub mod scenarios {
})
.await
.unwrap();
self.staged_blockheight = BlockHeight::from(target_blockheight as u32);
self
}
/// Apply blocks up to target height.
pub async fn apply_blocks(&mut self, target_blockheight: u64) -> &mut DarksideScenario {
self.darkside_connector
.apply_staged(target_blockheight as i32)
.await
.unwrap();
self.staged_blockheight = BlockHeight::from(target_blockheight as u32);
self
}
/// Stage and apply blocks up to target height and update tree state.
pub async fn stage_and_apply_blocks(
&mut self,
target_blockheight: u64,
nonce: u64,
) -> &mut DarksideScenario {
self.stage_blocks(target_blockheight, nonce).await;
self.apply_blocks(target_blockheight).await;
self
}
/// Tool for chainbuilds.
/// Send from funded lightclient and write hex transaction to file.
/// Stage a block and a send from funded lightclient, then write hex transaction to file.
/// All sends in a chainbuild are appended to same file in order.
/// Does not apply block.
pub async fn send_and_write_transaction(
&mut self,
// We can't just take a reference to a LightClient, as that might be a reference to
Expand Down Expand Up @@ -661,7 +680,63 @@ pub mod scenarios {
.await;
self
}
/// Tool for chainbuilds.
/// Stage a block and a shield from funded lightclient, then write hex transaction to file.
/// Only one pool can be shielded at a time.
/// All sends in a chainbuild are appended to same file in order.
/// Does not apply block.
pub async fn shield_and_write_transaction(
&mut self,
// We can't just take a reference to a LightClient, as that might be a reference to
// a field of the DarksideScenario which we're taking by exclusive (i.e. mut) reference
sender: DarksideSender<'_>,
pool_to_shield: Pool,
chainbuild_file: &File,
) -> &mut DarksideScenario {
self.staged_blockheight = self.staged_blockheight.add(1);
self.darkside_connector
.stage_blocks_create(u32::from(self.staged_blockheight) as i32, 1, 0)
.await
.unwrap();
let lightclient = match sender {
DarksideSender::Faucet => self.get_faucet(),
DarksideSender::IndexedClient(n) => self.get_lightclient(n),
DarksideSender::ExternalClient(lc) => lc,
};
lightclient
.do_shield(&[pool_to_shield], None)
.await
.unwrap();
let mut streamed_raw_txns = self
.darkside_connector
.get_incoming_transactions()
.await
.unwrap();
self.darkside_connector
.clear_incoming_transactions()
.await
.unwrap();
let raw_tx = streamed_raw_txns.message().await.unwrap().unwrap();
// There should only be one transaction incoming
assert!(streamed_raw_txns.message().await.unwrap().is_none());
write_raw_transaction(&raw_tx, BranchId::Nu5, chainbuild_file);
self.darkside_connector
.stage_transactions_stream(vec![(
raw_tx.data.clone(),
u64::from(self.staged_blockheight),
)])
.await
.unwrap();
self.tree_state = update_tree_states_for_transaction(
&self.darkside_connector.0,
raw_tx,
u64::from(self.staged_blockheight),
)
.await;
self
}
/// Stage a block and transaction, then update tree state.
/// Does not apply block.
pub async fn stage_transaction(&mut self, hex_transaction: &str) -> &mut DarksideScenario {
self.staged_blockheight = self.staged_blockheight.add(1);
self.darkside_connector
Expand Down Expand Up @@ -690,6 +765,18 @@ pub mod scenarios {
.unwrap();
self
}
/// Stage a block and next transaction in transaction set, then update tree state.
/// Does not apply block.
/// Temporary until tree states are also written to file.
pub async fn stage_next_transaction(
&mut self,
transaction_set: &[String],
) -> &mut DarksideScenario {
self.stage_transaction(&transaction_set[self.transaction_set_index as usize])
.await;
self.transaction_set_index += 1;
self
}

/// Update the height of the staged blockchain
pub fn set_staged_blockheight(&mut self, height: u64) {
Expand Down
2 changes: 1 addition & 1 deletion darkside-tests/tests/advanced_reorg_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use darkside_tests::{

use tokio::time::sleep;
use zcash_primitives::consensus::BlockHeight;
use zingo_testutils::{regtest::get_cargo_manifest_dir, scenarios::setup::ClientBuilder};
use zingo_testutils::{paths::get_cargo_manifest_dir, scenarios::setup::ClientBuilder};
use zingoconfig::RegtestNetwork;
use zingolib::lightclient::PoolBalances;
use zingolib::wallet::data::summaries::ValueTransferKind;
Expand Down

This file was deleted.

Large diffs are not rendered by default.

Loading

0 comments on commit 8f633ec

Please sign in to comment.