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

test(solana): migrate to local/offline containerized node #2168

Closed
wants to merge 3 commits into from
Closed
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
15 changes: 15 additions & 0 deletions .docker/Dockerfile.solana-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM rust:1.79

WORKDIR /root

RUN apt -y update && apt -y install curl bzip2

RUN sh -c "$(curl -sSfL https://release.solana.com/v1.17.13/install)"

ENV PATH="/root/.local/share/solana/install/active_release/bin:${PATH}"

RUN solana-keygen new --no-bip39-passphrase

COPY .docker/devnet-accounts/ /root/accounts/

ENTRYPOINT ["solana-test-validator", "--bpf-program", "3fystoi7pB1cnDEbRRpSjFJA4fG3W2vQQZ21jSrBc11B", "/root/accounts/program1_11B.so", "--account-dir", "/root/accounts", "--reset"]
69 changes: 42 additions & 27 deletions mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
pub use common::{block_on, now_ms, now_sec, wait_until_ms, wait_until_sec};
pub use mm2_number::MmNumber;
use mm2_rpc::data::legacy::BalanceResponse;
pub use mm2_test_helpers::for_tests::{check_my_swap_status, check_recent_swaps, enable_eth_coin, enable_native,
enable_native_bch, erc20_dev_conf, eth_dev_conf, eth_sepolia_conf,
jst_sepolia_conf, mm_dump, wait_check_stats_swap_status, MarketMakerIt,
MAKER_ERROR_EVENTS, MAKER_SUCCESS_EVENTS, TAKER_ERROR_EVENTS,
TAKER_SUCCESS_EVENTS};

use super::eth_docker_tests::{erc20_contract_checksum, fill_eth, fill_eth_erc20_with_private_key, geth_account,
swap_contract};
pub use std::env;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::str::FromStr;
use std::sync::Mutex;
pub use std::thread;
use std::time::Duration;

use ethabi::Token;
use ethereum_types::{H160 as H160Eth, U256};
use futures::TryFutureExt;
use futures01::Future;
use http::StatusCode;
use mm2_test_helpers::for_tests::{check_my_swap_status, check_recent_swaps, enable_eth_coin, enable_native,
enable_native_bch, erc20_dev_conf, eth_dev_conf, mm_dump,
wait_check_stats_swap_status, MarketMakerIt};
use mm2_test_helpers::get_passphrase;
use mm2_test_helpers::structs::TransactionDetails;

use bitcrypto::{dhash160, ChecksumType};
use chain::TransactionOutput;
use coins::eth::addr_from_raw_pubkey;
Expand All @@ -23,32 +31,19 @@ use coins::utxo::utxo_standard::{utxo_standard_coin_with_priv_key, UtxoStandardC
use coins::utxo::{coin_daemon_data_dir, sat_from_big_decimal, zcash_params_path, UtxoActivationParams,
UtxoAddressFormat, UtxoCoinFields, UtxoCommonOps};
use coins::{ConfirmPaymentInput, MarketCoinOps, Transaction};
pub use common::{block_on, now_ms, now_sec, wait_until_ms, wait_until_sec};
use crypto::privkey::key_pair_from_seed;
use crypto::Secp256k1Secret;
use ethabi::Token;
use ethereum_types::{H160 as H160Eth, U256};
use futures::TryFutureExt;
use futures01::Future;
use http::StatusCode;
use keys::{Address, AddressBuilder, AddressHashEnum, AddressPrefix, KeyPair, NetworkAddressPrefixes,
NetworkPrefix as CashAddrPrefix};
use mm2_core::mm_ctx::{MmArc, MmCtxBuilder};
use mm2_number::BigDecimal;
use mm2_test_helpers::get_passphrase;
use mm2_test_helpers::structs::TransactionDetails;
use mm2_rpc::data::legacy::BalanceResponse;
use primitives::hash::{H160, H256};
use script::Builder;
use secp256k1::Secp256k1;
pub use secp256k1::{PublicKey, SecretKey};
use serde_json::{self as json, Value as Json};
pub use std::env;
use std::path::PathBuf;
use std::process::Command;
use std::process::Stdio;
use std::str::FromStr;
use std::sync::Mutex;
pub use std::thread;
use std::time::Duration;
use testcontainers::clients::Cli;
use testcontainers::core::WaitFor;
use testcontainers::{Container, GenericImage, RunnableImage};
Expand All @@ -57,6 +52,9 @@ use web3::types::Address as EthAddress;
use web3::types::{BlockId, BlockNumber, TransactionRequest};
use web3::Web3;

use crate::docker_tests::eth_docker_tests::{erc20_contract_checksum, fill_eth, fill_eth_erc20_with_private_key,
geth_account, swap_contract};

lazy_static! {
static ref MY_COIN_LOCK: Mutex<()> = Mutex::new(());
static ref MY_COIN1_LOCK: Mutex<()> = Mutex::new(());
Expand Down Expand Up @@ -118,7 +116,7 @@ pub const GETH_DOCKER_IMAGE_WITH_TAG: &str = "docker.io/ethereum/client-go:stabl
pub const NUCLEUS_IMAGE: &str = "docker.io/komodoofficial/nucleusd";
pub const ATOM_IMAGE: &str = "docker.io/komodoofficial/gaiad";
pub const IBC_RELAYER_IMAGE: &str = "docker.io/komodoofficial/ibc-relayer";

pub const SOLANA_CLUSTER_DOCKER_IMAGE: &str = "docker.io/0xmmbd/solana-node-test";
pub const QTUM_ADDRESS_LABEL: &str = "MM2_ADDRESS_LABEL";

/// ERC721_TEST_TOKEN has additional mint function
Expand Down Expand Up @@ -372,6 +370,20 @@ pub fn geth_docker_node<'a>(docker: &'a Cli, ticker: &'static str, port: u16) ->
}
}

pub fn sol_asset_docker_node<'a>(docker: &'a Cli, ticker: &'static str) -> DockerNode<'a> {
let port = 8899;

let image = GenericImage::new(SOLANA_CLUSTER_DOCKER_IMAGE, "latest");
let image = RunnableImage::from((image, vec![])).with_mapped_port((port, port));
let container = docker.run(image);
DockerNode {
container,
ticker: ticker.into(),
port,
}
}

#[allow(dead_code)]
pub fn nucleus_node(docker: &'_ Cli, runtime_dir: PathBuf) -> DockerNode<'_> {
let nucleus_node_runtime_dir = runtime_dir.join("nucleus-testnet-data");
assert!(nucleus_node_runtime_dir.exists());
Expand All @@ -388,6 +400,7 @@ pub fn nucleus_node(docker: &'_ Cli, runtime_dir: PathBuf) -> DockerNode<'_> {
}
}

#[allow(dead_code)]
pub fn atom_node(docker: &'_ Cli, runtime_dir: PathBuf) -> DockerNode<'_> {
let atom_node_runtime_dir = runtime_dir.join("atom-testnet-data");
assert!(atom_node_runtime_dir.exists());
Expand All @@ -404,6 +417,7 @@ pub fn atom_node(docker: &'_ Cli, runtime_dir: PathBuf) -> DockerNode<'_> {
}
}

#[allow(dead_code)]
pub fn ibc_relayer_node(docker: &'_ Cli, runtime_dir: PathBuf) -> DockerNode<'_> {
let relayer_node_runtime_dir = runtime_dir.join("ibc-relayer-data");
assert!(relayer_node_runtime_dir.exists());
Expand Down Expand Up @@ -1140,6 +1154,7 @@ async fn get_current_gas_limit(web3: &Web3<Http>) {
}
}

#[allow(dead_code)]
pub fn wait_until_relayer_container_is_ready(container_id: &str) {
const Q_RESULT: &str = "0: nucleus-atom -> chns(✔) clnts(✔) conn(✔) (nucleus-testnet<>cosmoshub-testnet)";

Expand Down
3 changes: 2 additions & 1 deletion mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use futures01::Future;
use http::StatusCode;
use mm2_core::mm_ctx::{MmArc, MmCtxBuilder};
use mm2_main::mm2::lp_swap::{dex_fee_amount, max_taker_vol_from_available};
use mm2_number::BigDecimal;
use mm2_number::{BigDecimal, MmNumber};
use mm2_rpc::data::legacy::{CoinInitResponse, OrderbookResponse};
use mm2_test_helpers::for_tests::{mm_dump, MarketMakerIt};
use mm2_test_helpers::structs::{trade_preimage_error, RpcErrorResponse, RpcSuccessResponse, TransactionDetails};
use rand6::Rng;
use serde_json::{self as json, Value as Json};
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_main/tests/docker_tests/slp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::integration_tests_common::enable_native;
use http::StatusCode;
use mm2_number::BigDecimal;
use mm2_rpc::data::legacy::CoinInitResponse;
use mm2_test_helpers::for_tests::{assert_coin_not_found_on_balance, disable_coin, enable_bch_with_tokens, enable_slp,
my_balance, UtxoRpcMode};
use mm2_test_helpers::for_tests::{assert_coin_not_found_on_balance, disable_coin, enable_bch_with_tokens,
enable_native_bch, enable_slp, my_balance, MarketMakerIt, UtxoRpcMode};
use mm2_test_helpers::structs::{EnableBchWithTokensResponse, EnableSlpResponse, RpcV2Response};
use serde_json::{self as json, json, Value as Json};
use std::collections::HashSet;
Expand Down
16 changes: 10 additions & 6 deletions mm2src/mm2_main/tests/docker_tests/solana_tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::docker_tests::docker_tests_common::*;
use serde_json as json;

use mm2_number::bigdecimal::Zero;
use mm2_test_helpers::for_tests::{disable_coin, enable_solana_with_tokens, enable_spl, sign_message, verify_message};
use mm2_test_helpers::structs::{EnableSolanaWithTokensResponse, EnableSplResponse, RpcV2Response, SignatureResponse,
VerificationResponse};
use serde_json as json;

use crate::docker_tests::docker_tests_common::*;

const SOLANA_CLIENT_URL: &str = "http://localhost:8899";

#[test]
fn test_solana_and_spl_balance_enable_spl_v2() {
Expand All @@ -13,7 +17,7 @@ fn test_solana_and_spl_balance_enable_spl_v2() {
&mm,
"SOL-DEVNET",
&["USDC-SOL-DEVNET"],
"https://api.devnet.solana.com",
SOLANA_CLIENT_URL,
tx_history,
));
let enable_solana_with_tokens: RpcV2Response<EnableSolanaWithTokensResponse> =
Expand Down Expand Up @@ -55,7 +59,7 @@ fn test_sign_verify_message_solana() {
&mm,
"SOL-DEVNET",
&["USDC-SOL-DEVNET"],
"https://api.devnet.solana.com",
SOLANA_CLIENT_URL,
tx_history,
));

Expand Down Expand Up @@ -88,7 +92,7 @@ fn test_sign_verify_message_spl() {
&mm,
"SOL-DEVNET",
&["USDC-SOL-DEVNET"],
"https://api.devnet.solana.com",
SOLANA_CLIENT_URL,
tx_history,
));

Expand Down Expand Up @@ -122,7 +126,7 @@ fn test_disable_solana_platform_coin_with_tokens() {
&mm,
"SOL-DEVNET",
&["USDC-SOL-DEVNET"],
"https://api.devnet.solana.com",
SOLANA_CLIENT_URL,
false,
));
block_on(enable_spl(&mm, "ADEX-SOL-DEVNET"));
Expand Down
21 changes: 19 additions & 2 deletions mm2src/mm2_main/tests/docker_tests/tendermint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const TENDERMINT_TEST_BIP39_SEED: &str =
"emerge canoe salmon dolphin glow priority random become gasp sell blade argue";

#[test]
#[ignore]
fn test_tendermint_balance() {
let coins = json!([atom_testnet_conf()]);
let coin = coins[0]["coin"].as_str().unwrap();
Expand All @@ -45,6 +46,7 @@ fn test_tendermint_balance() {
}

#[test]
#[ignore]
fn test_tendermint_activation_without_balance() {
let coins = json!([atom_testnet_conf()]);
let coin = coins[0]["coin"].as_str().unwrap();
Expand All @@ -67,6 +69,7 @@ fn test_tendermint_activation_without_balance() {
}

#[test]
#[ignore]
fn test_iris_ibc_nucleus_without_balance() {
let coins = json!([nucleus_testnet_conf(), iris_ibc_nucleus_testnet_conf()]);

Expand Down Expand Up @@ -94,6 +97,7 @@ fn test_iris_ibc_nucleus_without_balance() {
}

#[test]
#[ignore]
fn test_iris_ibc_nucleus_orderbook() {
let coins = json!([nucleus_testnet_conf(), iris_ibc_nucleus_testnet_conf()]);
let platform_coin = coins[0]["coin"].as_str().unwrap();
Expand Down Expand Up @@ -142,6 +146,7 @@ fn test_iris_ibc_nucleus_orderbook() {
}

#[test]
#[ignore]
fn test_tendermint_hd_address() {
let coins = json!([atom_testnet_conf()]);
let coin = coins[0]["coin"].as_str().unwrap();
Expand All @@ -158,6 +163,7 @@ fn test_tendermint_hd_address() {
}

#[test]
#[ignore]
fn test_tendermint_withdraw() {
const MY_ADDRESS: &str = "cosmos150evuj4j7k9kgu38e453jdv9m3u0ft2n53flg6";

Expand Down Expand Up @@ -215,6 +221,7 @@ fn test_tendermint_withdraw() {
}

#[test]
#[ignore]
fn test_tendermint_withdraw_hd() {
const MY_ADDRESS: &str = "cosmos134h9tv7866jcuw708w5w76lcfx7s3x2ysyalxy";

Expand Down Expand Up @@ -282,6 +289,7 @@ fn test_tendermint_withdraw_hd() {
}

#[test]
#[ignore]
fn test_custom_gas_limit_on_tendermint_withdraw() {
let coins = json!([atom_testnet_conf()]);
let coin = coins[0]["coin"].as_str().unwrap();
Expand Down Expand Up @@ -312,6 +320,7 @@ fn test_custom_gas_limit_on_tendermint_withdraw() {
}

#[test]
#[ignore]
fn test_tendermint_ibc_withdraw() {
// visit `{swagger_address}/ibc/core/channel/v1/channels?pagination.limit=10000` to see the full list of ibc channels
const IBC_SOURCE_CHANNEL: &str = "channel-1";
Expand Down Expand Up @@ -358,6 +367,7 @@ fn test_tendermint_ibc_withdraw() {
}

#[test]
#[ignore]
fn test_tendermint_ibc_withdraw_hd() {
// visit `{swagger_address}/ibc/core/channel/v1/channels?pagination.limit=10000` to see the full list of ibc channels
const IBC_SOURCE_CHANNEL: &str = "channel-1";
Expand Down Expand Up @@ -405,6 +415,7 @@ fn test_tendermint_ibc_withdraw_hd() {
}

#[test]
#[ignore]
fn test_tendermint_token_withdraw() {
const MY_ADDRESS: &str = "nuc150evuj4j7k9kgu38e453jdv9m3u0ft2n4fgzfr";

Expand Down Expand Up @@ -485,6 +496,7 @@ fn test_tendermint_token_withdraw() {
}

#[test]
#[ignore]
fn test_tendermint_tx_history() {
const TEST_SEED: &str = "Vdo8Xt8pTAetRlMq3kV0LzE393eVYbPSn5Mhtw4p";
const TX_FINISHED_LOG: &str = "Tx history fetching finished for NUCLEUS-TEST.";
Expand Down Expand Up @@ -561,6 +573,7 @@ fn test_tendermint_tx_history() {
}

#[test]
#[ignore]
fn test_disable_tendermint_platform_coin_with_token() {
let coins = json!([nucleus_testnet_conf(), iris_ibc_nucleus_testnet_conf()]);
let platform_coin = coins[0]["coin"].as_str().unwrap();
Expand Down Expand Up @@ -597,6 +610,7 @@ fn test_disable_tendermint_platform_coin_with_token() {
}

#[test]
#[ignore]
fn test_passive_coin_and_force_disable() {
let coins = json!([nucleus_testnet_conf(), iris_ibc_nucleus_testnet_conf()]);
let platform_coin = coins[0]["coin"].as_str().unwrap();
Expand Down Expand Up @@ -663,7 +677,7 @@ mod swap {
use instant::Duration;
use mm2_rpc::data::legacy::OrderbookResponse;
use mm2_test_helpers::for_tests::{check_my_swap_status, check_recent_swaps, doc_conf, enable_eth_coin,
iris_ibc_nucleus_testnet_conf, nucleus_testnet_conf,
eth_dev_conf, iris_ibc_nucleus_testnet_conf, nucleus_testnet_conf,
wait_check_stats_swap_status, DOC_ELECTRUM_ADDRS};
use std::convert::TryFrom;
use std::str::FromStr;
Expand All @@ -673,6 +687,7 @@ mod swap {
const ALICE_PASSPHRASE: &str = "iris test2 seed";

#[test]
#[ignore]
fn swap_nucleus_with_doc() {
let bob_passphrase = String::from(BOB_PASSPHRASE);
let alice_passphrase = String::from(ALICE_PASSPHRASE);
Expand Down Expand Up @@ -751,6 +766,7 @@ mod swap {
}

#[test]
#[ignore]
fn swap_nucleus_with_eth() {
let bob_passphrase = String::from(BOB_PASSPHRASE);
let alice_passphrase = String::from(ALICE_PASSPHRASE);
Expand All @@ -767,7 +783,7 @@ mod swap {
U256::from(10).pow(U256::from(20)),
);

let coins = json!([nucleus_testnet_conf(), crate::eth_dev_conf()]);
let coins = json!([nucleus_testnet_conf(), eth_dev_conf()]);

let mm_bob = MarketMakerIt::start(
json!({
Expand Down Expand Up @@ -857,6 +873,7 @@ mod swap {
}

#[test]
#[ignore]
fn swap_doc_with_iris_ibc_nucleus() {
let bob_passphrase = String::from(BOB_PASSPHRASE);
let alice_passphrase = String::from(ALICE_PASSPHRASE);
Expand Down
Loading
Loading