diff --git a/packages/rs-sdk/README.md b/packages/rs-sdk/README.md index c14b9bbd592..4c993d9e18a 100644 --- a/packages/rs-sdk/README.md +++ b/packages/rs-sdk/README.md @@ -74,7 +74,14 @@ cargo test -p dash-sdk --no-default-features --features network-testing ## Offline Testing Offline testing uses the vectors generated using `packages/rs-sdk/scripts/generate_test_vectors.sh` script. -These vectors must be saved in `packages/rs-sdk/tests/vectors`. +This script will connect to node defined in `packages/rs-sdk/tests/.env`, execute all tests against it and +update test vectors in `packages/rs-sdk/tests/vectors`. + +To generate test vectors against a testnet node (or other remote node), you can use helper script +`packages/rs-sdk/scripts/connect_to_remote.sh` which will generate `.env` file for you and tunnel connection to Dash +Core RPC on the remote host. + +Refer to rich comments / help in the forementioned scripts for more details. ### Generating test vectors diff --git a/packages/rs-sdk/scripts/connect_to_remote.sh b/packages/rs-sdk/scripts/connect_to_remote.sh new file mode 100755 index 00000000000..87455b6f0b4 --- /dev/null +++ b/packages/rs-sdk/scripts/connect_to_remote.sh @@ -0,0 +1,91 @@ +#! /bin/bash + +set -e -o pipefail + +CORE_USER=dashmate + +function usage() { + + echo This script connects to a remote node and runs the SDK tests on it. + echo It establishes SSH tunnel to the remote node and uses DAPI and Core RPC + echo services running on the remote node to run the tests. + echo + echo Note: you can use + echo + echo "Usage: $0 [ssh arguments]" + echo " remote-user: The username to use for SSH connection." + echo " remote-node: The IP address or hostname of the remote node." + echo " ssh arguments: Additional arguments to pass to the SSH command." + echo + echo "Example: $0 ubuntu@1.2.3.4 sudo -u dashmate" + exit 1 +} + +if [ "$#" -lt 1 ]; then + usage +fi + +REMOTE="$1" + +# Validate remote format +if ! echo "$REMOTE" | grep -q "@"; then + echo "Error: Remote must be in format user@host" + usage +fi + +# REMOTE_USER=$(echo "$1" | cut -d@ -f1) +REMOTE_NODE=$(echo "$1" | cut -d@ -f2) + +SSH_ARGS=${*:2} + +echo -n Reading configuration from remote "$REMOTE" using \`dashmate config get\` command... +# read core username and password from the remote node +CORE_PORT=$(ssh "$REMOTE" ${SSH_ARGS} dashmate config get core.rpc.port) +CORE_PASSWORD=$(ssh "$REMOTE" ${SSH_ARGS} dashmate config get "core.rpc.users.${CORE_USER}.password") + +DAPI_PORT=$(ssh "$REMOTE" ${SSH_ARGS} dashmate config get platform.gateway.listeners.dapiAndDrive.port) +DAPI_SSL_ENABLED=$(ssh "$REMOTE" ${SSH_ARGS} dashmate config get platform.gateway.ssl.enabled) + +echo " done." + +# Double check that the variables are set +if [ -z "$CORE_PORT" ] || [ -z "$CORE_PASSWORD" ] || [ -z "$DAPI_PORT" ] || [ -z "$DAPI_SSL_ENABLED" ]; then + echo "Failed to read configuration from the remote node." + exit 1 +fi + +ENV_FILE="$(realpath "$0" | xargs dirname)/../tests/.env" +echo -n Generating "${ENV_FILE}" file for the SDK tests... + +cat >"${ENV_FILE}" < ${REMOTE_NODE}:${CORE_PORT}" +echo +echo "To stop the tunnel, press Ctrl+C." + +ssh -L "12367:127.0.0.1:${CORE_PORT}" "$REMOTE" \ + -o ServerAliveInterval=60 \ + -o ServerAliveCountMax=3 \ + -o ExitOnForwardFailure=yes \ + -N ${SSH_ARGS} diff --git a/packages/rs-sdk/scripts/generate_test_vectors.sh b/packages/rs-sdk/scripts/generate_test_vectors.sh index a5530e7d93e..aad6afdb183 100755 --- a/packages/rs-sdk/scripts/generate_test_vectors.sh +++ b/packages/rs-sdk/scripts/generate_test_vectors.sh @@ -15,7 +15,8 @@ # its test vector is generated. # # Otherwise, all existing test vectors are removed and regenerated. - +# +# HINT: You can use `connect_to_remote.sh` script to use some remote node (like testnet) to generate test vectors. CARGO_DIR="$(realpath "$(dirname "$0")/..")" pushd "$CARGO_DIR" diff --git a/packages/rs-sdk/tests/.env.example b/packages/rs-sdk/tests/.env.example index 1a9222032eb..f0e4089da66 100644 --- a/packages/rs-sdk/tests/.env.example +++ b/packages/rs-sdk/tests/.env.example @@ -7,6 +7,8 @@ DASH_SDK_PLATFORM_SSL=false # ProTxHash of masternode that has at least 1 vote casted for DPNS name `testname` DASH_SDK_MASTERNODE_OWNER_PRO_REG_TX_HASH="6ac88f64622d9bc0cb79ad0f69657aa9488b213157d20ae0ca371fa5f04fb222" +# Dash Core host to use for RPC. Defaults to DASH_SDK_PLATFORM_HOST. +DASH_SDK_CORE_HOST=127.0.0.1 DASH_SDK_CORE_PORT=20002 DASH_SDK_CORE_USER="someuser" DASH_SDK_CORE_PASSWORD="verysecretpassword" diff --git a/packages/rs-sdk/tests/fetch/config.rs b/packages/rs-sdk/tests/fetch/config.rs index f55484f5ce3..41d3601cbdf 100644 --- a/packages/rs-sdk/tests/fetch/config.rs +++ b/packages/rs-sdk/tests/fetch/config.rs @@ -10,7 +10,7 @@ use dpp::{ }; use rs_dapi_client::{Address, AddressList}; use serde::Deserialize; -use std::{path::PathBuf, str::FromStr}; +use std::path::PathBuf; use zeroize::Zeroizing; /// Existing document ID @@ -36,6 +36,11 @@ pub struct Config { /// Port of the Dash Platform node grpc interface #[serde(default)] pub platform_port: u16, + /// Host of the Dash Core RPC interface running on the Dash Platform node. + /// Defaults to the same as [platform_host](Config::platform_host). + #[serde(default)] + #[cfg_attr(not(feature = "network-testing"), allow(unused))] + pub core_host: Option, /// Port of the Dash Core RPC interface running on the Dash Platform node #[serde(default)] pub core_port: u16, @@ -180,9 +185,10 @@ impl Config { // offline testing takes precedence over network testing #[cfg(all(feature = "network-testing", not(feature = "offline-testing")))] let sdk = { + let core_host = self.core_host.as_ref().unwrap_or(&self.platform_host); // Dump all traffic to disk let builder = dash_sdk::SdkBuilder::new(self.address_list()).with_core( - &self.platform_host, + core_host, self.core_port, &self.core_user, &self.core_password, diff --git a/packages/rs-sdk/tests/fetch/evonode.rs b/packages/rs-sdk/tests/fetch/evonode.rs index b2521ba8648..9a01eabb9d3 100644 --- a/packages/rs-sdk/tests/fetch/evonode.rs +++ b/packages/rs-sdk/tests/fetch/evonode.rs @@ -4,7 +4,6 @@ use super::{common::setup_logs, config::Config}; use dash_sdk::platform::{types::evonode::EvoNode, FetchUnproved}; use dpp::dashcore::{hashes::Hash, ProTxHash}; use drive_proof_verifier::types::EvoNodeStatus; -use http::Uri; use rs_dapi_client::Address; use std::time::Duration; /// Given some existing evonode URIs, WHEN we connect to them, THEN we get status.