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 #2187

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
73491ad
Add and fix Solana docker tests
0xMMBD Jul 18, 2024
47861f8
fmt changes
0xMMBD Jul 26, 2024
4277284
ignore tendermint tests for now
shamardy Jul 26, 2024
5b52c69
feat(solana-tests): moving to local node
mj-blockydevs Aug 5, 2024
763f32b
feat(solana-tests): moving solana tests to be executed against the lo…
mj-blockydevs Aug 6, 2024
c79ae3c
Revert "ignore tendermint tests for now"
shamardy Aug 6, 2024
efa9285
fixes after revert
shamardy Aug 6, 2024
313283d
Merge remote-tracking branch 'origin/dev' into solana-docker-tests-im…
shamardy Aug 6, 2024
364a98f
feat(solana-tests): moving solana tests to be executed against the lo…
mj-blockydevs Aug 6, 2024
2fb5cf4
feat(solana-tests): moving dockerized tests directly to the docker re…
mj-blockydevs Aug 7, 2024
8aa12b5
feat(solana-tests): moving dockerized tests directly to the docker re…
mj-blockydevs Aug 7, 2024
a81d5fd
feat(solana-tests): removing comments from code
mj-blockydevs Aug 7, 2024
7f8fba1
feat(solana-tests): one account instead of multiple accounts
mj-blockydevs Aug 8, 2024
be15afa
feat(solana-tests): fixing tests broken by previous commit
mj-blockydevs Aug 8, 2024
220651d
feat(solana-tests): fixing tests broken by previous commit
mj-blockydevs Aug 8, 2024
824463e
feat(solana-tests): fixing tests broken by previous commit
mj-blockydevs Aug 8, 2024
96d4855
feat(solana-tests): mint SPL to one account only
mj-blockydevs Aug 9, 2024
f4f644a
feat(solana-tests): moving repeated strings to consts
mj-blockydevs Aug 9, 2024
30e8cbe
enable solana feature for ci docker tests
shamardy Aug 9, 2024
525625f
* add enable-solana flag to some parts
shamardy Aug 9, 2024
19bbd93
fix wasm compilation
shamardy Aug 10, 2024
6d5bc8e
Merge remote-tracking branch 'origin/dev' into solana-docker-tests-im…
shamardy Aug 10, 2024
00ecbb6
make WithdrawRequest one implementation
shamardy Aug 10, 2024
958de15
feat(solana-tests): bringing back few omitted tests
mj-blockydevs Aug 11, 2024
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
24 changes: 24 additions & 0 deletions .docker/Dockerfile.solana-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM rust:1.79

WORKDIR /root

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

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

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

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


COPY ./solana-accounts/ /root/accounts/

RUN cd /root && mv ./accounts/mint.sh mint.sh && chmod +x mint.sh && ./mint.sh

RUN git clone https://github.com/KomodoPlatform/satomic-swap.git \
&& cd satomic-swap \
&& git checkout dev \
&& cargo build-bpf \
&& cp /root/satomic-swap/target/sbf-solana-solana/release/satomic_swap.so /root/accounts/program1_11B.so

ENTRYPOINT ["solana-test-validator", "--bpf-program", "GCJUXKH4VeKzEtr9YgwaNWC3dJonFgsM3yMiBa64CZ8m", "/root/accounts/program1_11B.so", "--account-dir", "/root/accounts", "--reset"]
1 change: 1 addition & 0 deletions .docker/solana-accounts/iguana
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[89,236,134,13,236,250,87,81,157,215,177,98,144,243,248,108,9,40,70,18,16,0,231,108,44,241,152,52,76,121,226,244,145,149,122,206,134,225,178,154,20,10,111,202,31,213,179,67,10,223,94,88,18,191,26,144,19,37,63,242,59,13,86,12]
69 changes: 69 additions & 0 deletions .docker/solana-accounts/mint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# Directory containing the accounts
ACCOUNTS_DIR="./accounts"
# Amount of tokens to mint for each account (in smallest unit, e.g., lamports if the token has 9 decimals)
MINT_AMOUNT_USDC=1000000000 # 1000 USDC if the token has 6 decimals
MINT_AMOUNT_ADEX=1000000000 # 1 ADEX if the token has 9 decimals
# Path to your keypair file
AUTHORITY_KEYPAIR=/root/accounts/iguana
# Path to the fee payer keypair file
FEE_PAYER_KEYPAIR=/root/accounts/iguana
# Ensure the solana-test-validator is running and solana-cli is set to use local network
solana config set --url http://127.0.0.1:8899
solana config set --keypair /root/accounts/iguana
# Create new SPL tokens with your keypair as the mint authority
USDC_TOKEN=$(spl-token create-token --decimals 6 --mint-authority "$AUTHORITY_KEYPAIR" --fee-payer "$FEE_PAYER_KEYPAIR" | grep -o -E 'Creating token [A-Za-z0-9]+' | awk '{print $3}')
ADEX_TOKEN=$(spl-token create-token --decimals 9 --mint-authority "$AUTHORITY_KEYPAIR" --fee-payer "$FEE_PAYER_KEYPAIR" | grep -o -E 'Creating token [A-Za-z0-9]+' | awk '{print $3}')

echo "Created new USDC token: $USDC_TOKEN"
echo "Created new ADEX token: $ADEX_TOKEN"
spl-token create-account "$USDC_TOKEN" --owner "$ACCOUNTS_DIR"/iguana
spl-token create-account "$ADEX_TOKEN" --owner "$ACCOUNTS_DIR"/iguana
spl-token mint "$USDC_TOKEN" 100000
spl-token mint "$ADEX_TOKEN" 100000
# Iterate over each account file in the directory
for ACCOUNT_FILE in "$ACCOUNTS_DIR"/*.json; do
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am fine with having multiple accounts for users created and funded while starting the docker node, but this will cause problems for you in the future while implementing HD wallet since there are multiple addresses/accounts per HD wallet and you will need to update the docker image for those tests. A better pattern is to have one distributor account and this sends coins/tokens to addresses at the start of each test similar to how it's done for ethereum and other coins that use dockerized nodes

pub fn fill_eth(to_addr: Address, amount: U256) {

fn fill_erc20(to_addr: Address, amount: U256) {

It's up to you if you want to handle this now or later, but handling it here is the right choice so we don't change the docker image again ref. #2187 (comment)

Copy link
Author

Choose a reason for hiding this comment

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

@shamardy, all the tests are now working correctly with SPL tokens minted to a single account (I've updated the mint.sh file as you suggested). I believe we can introduce the "filling" methods later, as they are primarily needed to cover the currently implemented test case scenarios.

echo "Processing account: $ACCOUNT_FILE"

# Extract the public key from the account file
PUBKEY=$(jq -r '.pubkey' "$ACCOUNT_FILE")

# Create associated token account for USDC if it doesn't exist
USDC_ASSOCIATED_TOKEN_ADDRESS=$(spl-token accounts --owner "$PUBKEY" | grep "$USDC_TOKEN" | awk '{print $1}')
if [ -z "$USDC_ASSOCIATED_TOKEN_ADDRESS" ]; then
USDC_ASSOCIATED_TOKEN_ADDRESS=$(spl-token create-account "$USDC_TOKEN" --owner "$PUBKEY" --fee-payer "$FEE_PAYER_KEYPAIR" | grep -o -E 'Creating account [A-Za-z0-9]+' | awk '{print $3}')
echo "Created associated token account for USDC: $USDC_ASSOCIATED_TOKEN_ADDRESS"
else
echo "Associated token account for USDC already exists: $USDC_ASSOCIATED_TOKEN_ADDRESS"
fi

# Create associated token account for ADEX if it doesn't exist
ADEX_ASSOCIATED_TOKEN_ADDRESS=$(spl-token accounts --owner "$PUBKEY" | grep "$ADEX_TOKEN" | awk '{print $1}')
if [ -z "$ADEX_ASSOCIATED_TOKEN_ADDRESS" ]; then
ADEX_ASSOCIATED_TOKEN_ADDRESS=$(spl-token create-account "$ADEX_TOKEN" --owner "$PUBKEY" --fee-payer "$FEE_PAYER_KEYPAIR" | grep -o -E 'Creating account [A-Za-z0-9]+' | awk '{print $3}')
echo "Created associated token account for ADEX: $ADEX_ASSOCIATED_TOKEN_ADDRESS"
else
echo "Associated token account for ADEX already exists: $ADEX_ASSOCIATED_TOKEN_ADDRESS"
fi

# Mint USDC tokens to the associated token account
echo "Minting $MINT_AMOUNT_USDC USDC tokens"
spl-token mint "$USDC_TOKEN" "$MINT_AMOUNT_USDC" --mint-authority "$AUTHORITY_KEYPAIR" --recipient-owner "$PUBKEY" --fee-payer "$FEE_PAYER_KEYPAIR"

# Mint ADEX tokens to the associated token account
echo "Minting $MINT_AMOUNT_ADEX ADEX tokens"
spl-token mint "$ADEX_TOKEN" "$MINT_AMOUNT_ADEX" --mint-authority "$AUTHORITY_KEYPAIR" --recipient-owner "$PUBKEY" --fee-payer "$FEE_PAYER_KEYPAIR"

# Check the balance of the token accounts
USDC_BALANCE=$(spl-token balance "$USDC_TOKEN" --owner "$PUBKEY")
ADEX_BALANCE=$(spl-token balance "$ADEX_TOKEN" --owner "$PUBKEY")
echo "Account: $PUBKEY, USDC Token Balance: $USDC_BALANCE, ADEX Token Balance: $ADEX_BALANCE"
done

echo $USDC_TOKEN > /root/accounts/usdc_token_address
echo $ADEX_TOKEN > /root/accounts/adex_token_address

echo "New token addresses:"
echo "USDC Token Address: $USDC_TOKEN"
echo "ADEX Token Address: $ADEX_TOKEN"
16 changes: 16 additions & 0 deletions .docker/solana-accounts/token_m_a.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this file also

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"account":
{
"data":
[
"",
"base64"
],
"executable": false,
"lamports": 992380560,
"owner": "11111111111111111111111111111111",
"rentEpoch": 18446744073709551615,
"space": 0
},
"pubkey": "BRCLD4ANoSbhSs1L9oyaqGL3UwpdfZ5LBpQRp1EvgSgF"
}
16 changes: 16 additions & 0 deletions .docker/solana-accounts/user1.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this user is not needed anymore

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"account":
{
"data":
[
"AQAAAOuFRM+RGCd6ljLpmVBmZRu/sUCLhXPrwC5T76tavw4L/RbEetstXpkGAQEAAACoBjP/Bn2I36XUNXv0TibOzM8IZmiBA8a6YJ+kTBjSCA==",
"base64"
],
"executable": false,
"lamports": 58894504030,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709551615,
"space": 82
},
"pubkey": "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"
}
16 changes: 16 additions & 0 deletions .docker/solana-accounts/user2.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for this user

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"account":
{
"data":
[
"AQAAAJrHnvG0jCL7n9BmQRqwTAmP5AKq7ktJC5x9VJvb6LJwAAjB8egBAAAJAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"base64"
],
"executable": false,
"lamports": 1461600,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709551615,
"space": 82
},
"pubkey": "5tSm6PqMosy1rz1AqV3kD28yYT5XqZW3QYmZommuFiPJ"
}
1 change: 1 addition & 0 deletions .docker/solana-accounts/user3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"account":{"data":["","base64"],"executable":false,"lamports":1548982240,"owner":"11111111111111111111111111111111","rentEpoch":18446744073709551615,"space":0},"pubkey":"FJktmyjV9aBHEShT4hfnLpr9ELywdwVtEL1w1rSWgbVf"}
1 change: 1 addition & 0 deletions .docker/solana-accounts/user4_TijN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"account":{"data":["","base64"],"executable":false,"lamports":3522011040,"owner":"11111111111111111111111111111111","rentEpoch":18446744073709551615,"space":0},"pubkey":"FssCi3dqytoGu7rUkptWXvWRg9hcJa54MXme31PKTojN"}
1 change: 1 addition & 0 deletions .docker/solana-accounts/user5_v54e.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions mm2src/coins/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub mod solana_common;
mod solana_decode_tx_helpers;
pub mod spl;

#[cfg(test)] mod solana_common_tests;
#[cfg(test)] mod solana_tests;
#[cfg(feature = "enable-solana")] mod solana_common_tests;
#[cfg(feature = "enable-solana")] pub mod solana_tests;
#[cfg(test)] mod spl_tests;

pub const SOLANA_DEFAULT_DECIMALS: u64 = 9;
Expand Down
10 changes: 4 additions & 6 deletions mm2src/coins/solana/solana_common_tests.rs
Copy link
Member

Choose a reason for hiding this comment

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

may be move solana_tests and solana_common_tests files to /mm2_main/tests/mm2_tests?
It looks like there is too much test code in mm2src space

Copy link
Collaborator

@shamardy shamardy Aug 7, 2024

Choose a reason for hiding this comment

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

It's similar to this comment #2187 (comment)
They should be moved to mm2_main/tests/docker_tests/solana_tests.rs, spl_tests should also be moved to a new spl_tests.rs file in docker tests.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, can you check it now, please @shamardy ?

Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ use solana_sdk::commitment_config::{CommitmentConfig, CommitmentLevel};
use std::str::FromStr;

pub enum SolanaNet {
//Mainnet,
Testnet,
Devnet,
Local,
}

pub fn solana_net_to_url(net_type: SolanaNet) -> String {
match net_type {
//SolanaNet::Mainnet => "https://api.mainnet-beta.solana.com".to_string(),
SolanaNet::Testnet => "https://api.testnet.solana.com/".to_string(),
SolanaNet::Devnet => "https://api.devnet.solana.com".to_string(),
SolanaNet::Local => "http://localhost:8899".to_string(),
}
}

#[allow(dead_code)]
pub fn generate_key_pair_from_seed(seed: &str) -> SolKeypair {
let derivation_path = DerivationPath::from_str("m/44'/501'/0'").unwrap();
let seed = bip39_seed_from_passphrase(seed).unwrap();
Expand Down Expand Up @@ -49,6 +46,7 @@ pub fn generate_key_pair_from_iguana_seed(seed: String) -> SolKeypair {
solana_sdk::signature::keypair_from_seed(other_key_pair.to_bytes().as_ref()).unwrap()
}

#[allow(dead_code)]
pub fn spl_coin_for_test(
solana_coin: SolanaCoin,
ticker: String,
Expand Down
Loading
Loading