Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d789c36
save dev state
borngraced Feb 25, 2025
3050594
save dev state
borngraced Feb 26, 2025
c6e8100
save dev state
borngraced Feb 26, 2025
f68cd01
save dev state - docker image working!
borngraced Feb 26, 2025
bf9312b
reduce timeout, add log
borngraced Feb 26, 2025
ea42ae7
uncomment tendermint docker and cleanups
borngraced Feb 26, 2025
da82da1
fix tx_streaming_tests mod
borngraced Feb 26, 2025
0377162
use multiarch for zombie docker
borngraced Feb 26, 2025
83133de
fix post rebase
borngraced Feb 26, 2025
588ee43
Merge branch 'dev' into dockerize_pirate
borngraced Feb 26, 2025
6d423a6
nits
borngraced Feb 26, 2025
9950305
remove mm2_test_helpers lock file
borngraced Feb 26, 2025
46d59ea
rename zombie to pirate
borngraced Feb 26, 2025
2c662ce
add internal Lockfile to gitignore
borngraced Feb 26, 2025
d2e09d0
revert z_coin save change output and fix docker image init arrangement
borngraced Feb 26, 2025
ec4845c
fix zcoin cache update test, improve z docker, and nits
borngraced Feb 27, 2025
300943e
fix clippy
borngraced Feb 27, 2025
6e6d37c
move fund shield to docker start script
borngraced Mar 3, 2025
5344fa6
fix clippy
borngraced Mar 3, 2025
f36a3a1
remove z_shieldcoinbase rpc
borngraced Mar 3, 2025
5d6bc86
revert all changes not related to dockerizing zombie tests
borngraced Mar 10, 2025
8184e29
fix clippy and remove unused
borngraced Mar 10, 2025
0c8f297
update avg_blocktiime for ZOMBIE
borngraced Mar 11, 2025
6bb1f65
Merge branch 'dev' into dockerize_pirate
borngraced Mar 17, 2025
42dcd42
ignore z_coin docker tests
borngraced Mar 18, 2025
281fe81
fix nits
borngraced Mar 18, 2025
06858a9
Merge branch 'dev' into dockerize_pirate
borngraced Mar 24, 2025
427a653
Merge branch 'dev' into dockerize_pirate
borngraced Mar 25, 2025
a4736ad
fix review notes
borngraced Mar 26, 2025
642f493
add zombie_conf_for_docker with 10 avg blocktime and use in z_coin_do…
borngraced Mar 29, 2025
1d57ad4
make sapling check fn compile for test, docker-test only
borngraced Mar 31, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ scripts/mm2/seed/unparsed.txt
# Private IDE configuration
/mm2src/*/.vscode/tasks.json
/mm2src/*/.vscode/c_cpp_properties.json
/mm2src/*/Cargo.lock
/.vscode/settings.json
/.vscode/tasks.json
/.vscode/c_cpp_properties.json
Expand Down
43 changes: 23 additions & 20 deletions mm2src/coins/z_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ pub mod tx_history_events;
mod tx_streaming_tests;
pub mod z_balance_streaming;
mod z_coin_errors;
#[cfg(all(test, not(target_arch = "wasm32"), feature = "zhtlc-native-tests"))]
mod z_coin_native_tests;
mod z_htlc;
mod z_rpc;
mod z_tx_history;
Expand Down Expand Up @@ -72,7 +70,8 @@ use std::num::TryFromIntError;
use std::path::PathBuf;
use std::sync::Arc;
pub use z_coin_errors::*;
use z_htlc::{z_p2sh_spend, z_send_dex_fee, z_send_htlc};
pub use z_htlc::z_send_dex_fee;
use z_htlc::{z_p2sh_spend, z_send_htlc};
use z_rpc::init_light_client;
pub use z_rpc::{FirstSyncBlock, SyncStatus};
use z_rpc::{SaplingSyncConnector, SaplingSyncGuard};
Expand All @@ -91,8 +90,6 @@ use zcash_primitives::{constants::mainnet as z_mainnet_constants, sapling::Payme
zip32::ExtendedFullViewingKey, zip32::ExtendedSpendingKey};
use zcash_proofs::prover::LocalTxProver;

use self::storage::store_change_output;

cfg_native!(
use common::{async_blocking, sha256_digest};
use zcash_client_sqlite::error::SqliteClientError as ZcashClientError;
Expand Down Expand Up @@ -282,12 +279,19 @@ impl ZCoin {
/// Asynchronously checks the synchronization status and returns `true` if
/// the Sapling state has finished synchronizing, meaning that the block number is available.
/// Otherwise, it returns `false`.
#[cfg(any(test, feature = "run-docker-tests"))]
#[inline]
pub async fn is_sapling_state_synced(&self) -> bool {
matches!(
self.sync_status().await,
Ok(SyncStatus::Finished { block_number: _, .. })
)
use futures::StreamExt;

let mut watcher = self.z_fields.sync_state_connector.lock().await;
while let Some(sync) = watcher.sync_watcher.next().await {
Comment thread
shamardy marked this conversation as resolved.
if matches!(sync, SyncStatus::Finished { .. }) {
return true;
}
}

false
}

#[inline]
Expand Down Expand Up @@ -475,12 +479,6 @@ impl ZCoin {
.await?
.tx_result?;

// Store any change outputs we created in this transaction by decrypting them with our keys
// and saving them to the wallet database for future spends
store_change_output(self.consensus_params_ref(), &self.z_fields.light_wallet_db, &tx)
.await
.map_to_mm(GenTxError::SaveChangeNotesError)?;

let additional_data = AdditionalTxData {
received_by_me,
spent_by_me: sat_from_big_decimal(&total_input_amount, self.decimals())?,
Expand Down Expand Up @@ -1079,7 +1077,6 @@ impl<'a> ZCoinBuilder<'a> {
.await
.mm_err(|err| ZCoinBuildError::ZCashParamsError(err.to_string()))?
{
// save params
params_db
.download_and_save_params()
.await
Expand All @@ -1096,21 +1093,27 @@ impl<'a> ZCoinBuilder<'a> {
}
}

/// Initialize `ZCoin` with a forced `z_spending_key`.
/// Initialize `ZCoin` with a forced `z_spending_key` for dockerized tests.
/// db_dir_path is where ZOMBIE_wallet.db located
/// Note that ZOMBIE_cache.db (db where blocks are downloaded to create ZOMBIE_wallet.db) is created in-memory (see BlockDbImpl::new fn)
#[cfg(all(test, feature = "zhtlc-native-tests"))]
#[cfg(any(test, feature = "run-docker-tests"))]
#[allow(clippy::too_many_arguments)]
async fn z_coin_from_conf_and_params_with_z_key(
pub async fn z_coin_from_conf_and_params_with_docker(
ctx: &MmArc,
ticker: &str,
conf: &Json,
params: &ZcoinActivationParams,
priv_key_policy: PrivKeyBuildPolicy,
db_dir_path: PathBuf,
z_spending_key: ExtendedSpendingKey,
protocol_info: ZcoinProtocolInfo,
spending_key: &str,
) -> Result<ZCoin, MmError<ZCoinBuildError>> {
use zcash_client_backend::encoding::decode_extended_spending_key;
let z_spending_key =
decode_extended_spending_key(z_mainnet_constants::HRP_SAPLING_EXTENDED_SPENDING_KEY, spending_key)
.unwrap()
.unwrap();

let builder = ZCoinBuilder::new(
ctx,
ticker,
Expand Down
17 changes: 0 additions & 17 deletions mm2src/coins/z_coin/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ pub mod walletdb;
pub(crate) use z_params::ZcashParamsWasmImpl;

pub use walletdb::*;
use zcash_extras::wallet::decrypt_and_store_transaction;
use zcash_primitives::transaction::Transaction;

use mm2_err_handle::mm_error::MmResult;
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -190,18 +188,3 @@ pub async fn scan_cached_block(

Ok(txs)
}

/// Processes and stores any change outputs created in the transaction by:
/// - Decrypting outputs using wallet viewing keys
/// - Adding decrypted change notes to the wallet database
/// - Making change notes available for future spends
pub(crate) async fn store_change_output(
params: &ZcoinConsensusParams,
shared_db: &WalletDbShared,
tx: &Transaction,
) -> Result<(), String> {
let mut data = try_s!(shared_db.db.get_update_ops());
try_s!(decrypt_and_store_transaction(params, &mut data, tx).await);

Ok(())
}
12 changes: 6 additions & 6 deletions mm2src/coins/z_coin/tx_streaming_tests/native.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use common::custom_futures::timeout::FutureTimerExt;
use common::{block_on, Future01CompatExt};
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_test_helpers::for_tests::{pirate_conf, ARRR};
use std::time::Duration;

use super::light_zcoin_activation_params;
use crate::z_coin::tx_history_events::ZCoinTxHistoryEventStreamer;
use crate::z_coin::z_coin_from_conf_and_params;
use crate::z_coin::z_htlc::z_send_dex_fee;
use crate::{CoinProtocol, DexFee, MarketCoinOps, MmCoin, PrivKeyBuildPolicy};

use common::custom_futures::timeout::FutureTimerExt;
use common::{block_on, Future01CompatExt};
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_test_helpers::for_tests::{pirate_conf, ARRR};
use std::time::Duration;

#[test]
#[ignore] // Ignored because we don't have zcash params in CI. TODO: Why not download them on demand like how we do in wasm (see download_and_save_params).
fn test_zcoin_tx_streaming() {
Expand Down
4 changes: 1 addition & 3 deletions mm2src/coins/z_coin/z_coin_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ pub enum GenTxError {
FailedToCreateNote,
SpendableNotesError(String),
Internal(String),
SaveChangeNotesError(String),
}

impl From<GetUnspentWitnessErr> for GenTxError {
Expand Down Expand Up @@ -178,8 +177,7 @@ impl From<GenTxError> for WithdrawError {
| GenTxError::LightClientErr(_)
| GenTxError::SpendableNotesError(_)
| GenTxError::FailedToCreateNote
| GenTxError::Internal(_)
| GenTxError::SaveChangeNotesError(_) => WithdrawError::InternalError(gen_tx.to_string()),
| GenTxError::Internal(_) => WithdrawError::InternalError(gen_tx.to_string()),
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions mm2src/coins/z_coin/z_htlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// taker payment spend - https://zombie.explorer.lordofthechains.com/tx/af6bb0f99f9a5a070a0c1f53d69e4189b0e9b68f9d66e69f201a6b6d9f93897e
// maker payment spend - https://rick.explorer.dexstats.info/tx/6a2dcc866ad75cebecb780a02320073a88bcf5e57ddccbe2657494e7747d591e

use super::storage::store_change_output;
use super::{GenTxError, ZCoin};
use crate::utxo::rpc_clients::{UtxoRpcClientEnum, UtxoRpcError};
use crate::utxo::utxo_common::payment_script;
Expand Down Expand Up @@ -208,12 +207,6 @@ pub async fn z_p2sh_spend(
let mut tx_buffer = Vec::with_capacity(1024);
zcash_tx.write(&mut tx_buffer)?;

// Store any change outputs we created in this transaction by decrypting them with our keys
// and saving them to the wallet database for future spends
store_change_output(coin.consensus_params_ref(), &coin.z_fields.light_wallet_db, &zcash_tx)
.await
.map_to_mm(|err| ZP2SHSpendError::GenTxError(GenTxError::SaveChangeNotesError(err)))?;

coin.utxo_rpc_client()
.send_raw_transaction(tx_buffer.into())
.compat()
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/z_coin/z_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ type SyncWatcher = AsyncReceiver<SyncStatus>;
type NewTxNotifier = AsyncSender<OneshotSender<(SaplingSyncLoopHandle, Box<dyn ZRpcOps>)>>;

pub(super) struct SaplingSyncConnector {
sync_watcher: SyncWatcher,
pub(super) sync_watcher: SyncWatcher,
on_tx_gen_notifier: NewTxNotifier,
abort_handle: Arc<Mutex<AbortOnDropHandle>>,
first_sync_block: FirstSyncBlock,
Expand Down
56 changes: 56 additions & 0 deletions mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use coins::z_coin::ZCoin;
pub use common::{block_on, block_on_f01, now_ms, now_sec, wait_until_ms, wait_until_sec, DEX_FEE_ADDR_RAW_PUBKEY};
pub use mm2_number::MmNumber;
use mm2_rpc::data::legacy::BalanceResponse;
Expand All @@ -8,6 +9,7 @@ pub use mm2_test_helpers::for_tests::{check_my_swap_status, check_recent_swaps,
TAKER_SUCCESS_EVENTS};

use super::eth_docker_tests::{erc20_contract_checksum, fill_eth, fill_eth_erc20_with_private_key, swap_contract};
use super::z_coin_docker_tests::z_coin_from_spending_key;
use bitcrypto::{dhash160, ChecksumType};
use chain::TransactionOutput;
use coins::eth::addr_from_raw_pubkey;
Expand Down Expand Up @@ -57,6 +59,7 @@ lazy_static! {
static ref MY_COIN1_LOCK: Mutex<()> = Mutex::new(());
static ref QTUM_LOCK: Mutex<()> = Mutex::new(());
static ref FOR_SLP_LOCK: Mutex<()> = Mutex::new(());
static ref ZOMBIE_LOCK: Mutex<()> = Mutex::new(());
pub static ref SLP_TOKEN_ID: Mutex<H256> = Mutex::new(H256::default());
// Private keys supplied with 1000 SLP tokens on tests initialization.
// Due to the SLP protocol limitations only 19 outputs (18 + change) can be sent in one transaction, which is sufficient for now though.
Expand Down Expand Up @@ -126,6 +129,9 @@ pub const UTXO_ASSET_DOCKER_IMAGE: &str = "docker.io/artempikulin/testblockchain
pub const UTXO_ASSET_DOCKER_IMAGE_WITH_TAG: &str = "docker.io/artempikulin/testblockchain:multiarch";
pub const GETH_DOCKER_IMAGE: &str = "docker.io/ethereum/client-go";
pub const GETH_DOCKER_IMAGE_WITH_TAG: &str = "docker.io/ethereum/client-go:stable";
pub const ZOMBIE_ASSET_DOCKER_IMAGE: &str = "docker.io/borngraced/zombietestrunner";
pub const ZOMBIE_ASSET_DOCKER_IMAGE_WITH_TAG: &str = "docker.io/borngraced/zombietestrunner:multiarch";
Comment on lines +132 to +133
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should move these to komodo platform in docker.io. This is not a blocker for merge as this is for testing but we should open a PR once moved.
c.c. @smk762


#[allow(dead_code)]
pub const SIA_DOCKER_IMAGE: &str = "docker.io/alrighttt/walletd-komodo";
#[allow(dead_code)]
Expand Down Expand Up @@ -221,6 +227,24 @@ impl UtxoAssetDockerOps {
}
}

pub struct ZCoinAssetDockerOps {
#[allow(dead_code)]
ctx: MmArc,
coin: ZCoin,
}

impl CoinDockerOps for ZCoinAssetDockerOps {
fn rpc_client(&self) -> &UtxoRpcClientEnum { &self.coin.as_ref().rpc_client }
}

impl ZCoinAssetDockerOps {
pub fn new() -> ZCoinAssetDockerOps {
let (ctx, coin) = block_on(z_coin_from_spending_key("secret-extended-key-main1q0k2ga2cqqqqpq8m8j6yl0say83cagrqp53zqz54w38ezs8ly9ly5ptamqwfpq85u87w0df4k8t2lwyde3n9v0gcr69nu4ryv60t0kfcsvkr8h83skwqex2nf0vr32794fmzk89cpmjptzc22lgu5wfhhp8lgf3f5vn2l3sge0udvxnm95k6dtxj2jwlfyccnum7nz297ecyhmd5ph526pxndww0rqq0qly84l635mec0x4yedf95hzn6kcgq8yxts26k98j9g32kjc8y83fe"));

ZCoinAssetDockerOps { ctx, coin }
}
}

pub struct BchDockerOps {
#[allow(dead_code)]
ctx: MmArc,
Expand Down Expand Up @@ -463,6 +487,38 @@ pub fn ibc_relayer_node(docker: &'_ Cli, runtime_dir: PathBuf) -> DockerNode<'_>
}
}

pub fn zombie_asset_docker_node(docker: &Cli, port: u16) -> DockerNode<'_> {
let image = GenericImage::new(ZOMBIE_ASSET_DOCKER_IMAGE, "multiarch")
.with_volume(zcash_params_path().display().to_string(), "/root/.zcash-params")
.with_env_var("COIN_RPC_PORT", port.to_string())
.with_wait_for(WaitFor::message_on_stdout("config is ready"));

let image = RunnableImage::from(image).with_mapped_port((port, port));
let container = docker.run(image);
let config_ticker = "ZOMBIE";
let mut conf_path = coin_daemon_data_dir(config_ticker, true);

std::fs::create_dir_all(&conf_path).unwrap();
conf_path.push(format!("{}.conf", config_ticker));
Command::new("docker")
.arg("cp")
.arg(format!("{}:/data/node_0/{}.conf", container.id(), config_ticker))
.arg(&conf_path)
.status()
.expect("Failed to execute docker command");

let timeout = wait_until_ms(3000);
while !conf_path.exists() {
assert!(now_ms() < timeout, "Test timed out");
}

DockerNode {
container,
ticker: config_ticker.into(),
port,
}
}

pub fn rmd160_from_priv(privkey: Secp256k1Secret) -> H160 {
let secret = SecretKey::from_slice(privkey.as_slice()).unwrap();
let public = PublicKey::from_secret_key(&Secp256k1::new(), &secret);
Expand Down
1 change: 1 addition & 0 deletions mm2src/mm2_main/tests/docker_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod swap_watcher_tests;
mod swaps_confs_settings_sync_tests;
mod swaps_file_lock_tests;
mod tendermint_tests;
mod z_coin_docker_tests;

// dummy test helping IDE to recognize this as test module
#[test]
Expand Down
Loading
Loading