-
Notifications
You must be signed in to change notification settings - Fork 95
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
base: dev
Are you sure you want to change the base?
Changes from 8 commits
73491ad
47861f8
4277284
5b52c69
763f32b
c79ae3c
efa9285
313283d
364a98f
2fb5cf4
8aa12b5
a81d5fd
7f8fba1
be15afa
220651d
824463e
96d4855
f4f644a
30e8cbe
525625f
19bbd93
6d5bc8e
00ecbb6
958de15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"] |
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] |
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 | ||
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" |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
} |
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"} |
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"} |
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be move solana_tests and solana_common_tests files to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's similar to this comment #2187 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, can you check it now, please @shamardy ? |
There was a problem hiding this comment.
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
komodo-defi-framework/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs
Line 129 in 9b01339
komodo-defi-framework/mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs
Line 149 in 9b01339
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)
There was a problem hiding this comment.
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.