Tests: libwallet_api_tests fixing scripts

This commit is contained in:
mj-xmr 2022-04-17 17:35:54 +02:00 committed by mj-xmr
parent 9f814edbd7
commit 35e18c58ca
No known key found for this signature in database
GPG Key ID: C101BF94093451E0
14 changed files with 113 additions and 42 deletions

View File

@ -5,6 +5,11 @@
By default, tests expect daemon running at ```localhost:38081```,
can be overridden with environment variable ```TESTNET_DAEMON_ADDRESS=<your_daemon_address>```
[Manual](https://github.com/moneroexamples/private-testnet) explaining how to run private testnet.
It is benefitial to run the node with the `--disable-rpc-ban` option, because the test will be abusing the node.
* Running monero node, linked to mainnet.
By default, tests expect daemon running at ```localhost:18081```,
can be overridden with environment variable ```MAINNET_DAEMON_ADDRESS=<your_daemon_address>```
* Directory with pre-generated wallets
(wallet_01.bin, wallet_02.bin,...,wallet_06.bin, some of these wallets might not be used in the tests currently).
@ -12,13 +17,25 @@
Directory can be overriden with environment variable ```WALLETS_ROOT_DIR=<your_directory_with_wallets>```.
Directory and files should be writable for the user running tests.
* The above environment variables can be conviniently modified and exported via the `conf.sh` script.
## Preparation of WALLETS_ROOT_DIR
Ideally copy all the scripts and symlink the test executable into the directory pointed by `WALLETS_ROOT_DIR` variable
and adjust your choices via the `conf.sh` script. In such scenario, uncomment the `export WALLETS_ROOT_DIR=.` line.
From there, run the below scripts:
## Generating test wallets
* ```create_wallets.sh``` - this script will create wallets (wallet_01.bin, wallet_02.bin,...,wallet_06.bin) in current directory.
when running first time, please uncomment line ```#create_wallet wallet_m``` to create miner wallet as well.
This wallet should be used for mining and all test wallets supposed to be seed from this miner wallet
when running first time, the script will create a special wallet_m.bin miner wallet as well.
This wallet should be used for mining and all test wallets supposed to be seed from this miner wallet.
* ```mining_start.sh``` and ```mining_stop.sh``` - helper scripts to start and stop mining on miner wallet
* ```mining_start.sh``` and ```mining_stop.sh``` - helper scripts to start and stop mining on miner wallet.
* ```send_funds.sh``` - script for seeding test wallets. Please run this script when you have enough money on miner wallet
* ```send_funds.sh``` - script for seeding test wallets. Please run this script when you have enough money on miner wallet.
## Running the tests
* Before running the tests, you have to source the `conf.sh` script with: `source conf.sh` or just: `. conf.sh` within the same terminal.
* The particular tests can be executed using a Regex filter, for example: `./libwallet_api_tests --gtest_filter=WalletTest1.WalletShowsBalance`.
* Execute `./libwallet_api_tests --gtest_list_tests` to obtain the full list of available tests.

View File

@ -0,0 +1,25 @@
#!/bin/bash -e
# path where created wallets will reside
# By default: /var/monero/testnet_pvt
export WALLETS_ROOT_DIR="/var/monero/testnet_pvt"
# If the wallets are created in a different directory, please uncomment and adjust the following export:
#export WALLETS_ROOT_DIR=.
# path to monero-wallet-cli
WALLET_CLI_DIR=.
WALLET_CLI="$WALLET_CLI_DIR/monero-wallet-cli"
# Testnet daemon defaults:
DAEMON_PORT=38081
DAEMON_HOST=localhost
# If the daemon defaults are to be changed, please uncomment the following export:
#export TESTNET_DAEMON_ADDRESS=$DAEMON_HOST:$DAEMON_PORT
# Mainnet daemon defaults:
#DAEMON_PORT_MAINNET=18081
#DAEMON_HOST_MAINNET=$DAEMON_HOST
#export MAINNET_DAEMON_ADDRESS=$DAEMON_HOST_MAINNET:$DAEMON_PORT_MAINNET

View File

@ -1,18 +1,27 @@
#!/bin/bash
#!/bin/bash -e
. ./conf.sh
function create_wallet {
wallet_name=$1
echo 0 | monero-wallet-cli --testnet --trusted-daemon --daemon-address localhost:38081 --generate-new-wallet $wallet_name --password "" --restore-height=1
echo 0 | "$WALLET_CLI" --testnet --trusted-daemon --daemon-address $DAEMON_HOST:$DAEMON_PORT --generate-new-wallet "${WALLETS_ROOT_DIR}/${wallet_name}.bin" --restore-height=1 --password ""
}
function create_wallet_if_not_exists {
wallet_name=$1
if [ ! -f "$WALLETS_ROOT_DIR/$wallet_name" ]; then
create_wallet $wallet_name
fi
}
create_wallet wallet_01.bin
create_wallet wallet_02.bin
create_wallet wallet_03.bin
create_wallet wallet_04.bin
create_wallet wallet_05.bin
create_wallet wallet_06.bin
create_wallet wallet_01
create_wallet wallet_02
create_wallet wallet_03
create_wallet wallet_04
create_wallet wallet_05
create_wallet wallet_06
create_wallet_if_not_exists wallet_m
# In case you want to recreate it anyway, just uncomment the next line:
#create_wallet wallet_m

View File

@ -1,4 +1,6 @@
#!/bin/bash
#!/bin/bash -e
rlwrap monero-wallet-cli --wallet-file wallet_m --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_m.log start_mining
. ./conf.sh
rlwrap "$WALLET_CLI" --wallet-file "$WALLETS_ROOT_DIR/wallet_m.bin" --password "" --testnet --trusted-daemon --daemon-address $DAEMON_HOST:$DAEMON_PORT --log-file "$WALLETS_ROOT_DIR/wallet_m.log" start_mining

View File

@ -1,4 +1,6 @@
#!/bin/bash
#!/bin/bash -e
rlwrap monero-wallet-cli --wallet-file wallet_m --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_miner.log stop_mining
. ./conf.sh
rlwrap "$WALLET_CLI" --wallet-file "$WALLETS_ROOT_DIR/wallet_m.bin" --password "" --testnet --trusted-daemon --daemon-address $DAEMON_HOST:$DAEMON_PORT --log-file "$WALLETS_ROOT_DIR/wallet_m.log" stop_mining

View File

@ -1,5 +1,4 @@
#!/bin/bash
#!/bin/bash -e
rlwrap monero-wallet-cli --wallet-file wallet_01.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_01.log
./open_wallet_par.sh wallet_1

View File

@ -1,5 +1,4 @@
#!/bin/bash
#!/bin/bash -e
rlwrap monero-wallet-cli --wallet-file wallet_02.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_01.log
./open_wallet_par.sh wallet_2

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -e
rlwrap monero-wallet-cli --wallet-file wallet_03.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_03.log
./open_wallet_par.sh wallet_2

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -e
rlwrap monero-wallet-cli --wallet-file wallet_04.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_04.log
./open_wallet_par.sh wallet_4

View File

@ -1,4 +1,5 @@
#!/bin/bash
#!/bin/bash -e
./open_wallet_par.sh wallet_5
rlwrap monero-wallet-cli --wallet-file wallet_05.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_05.log

View File

@ -0,0 +1,4 @@
#!/bin/bash -e
./open_wallet_par.sh wallet_6

View File

@ -1,4 +1,3 @@
#!/bin/bash
rlwrap monero-wallet-cli --wallet-file wallet_m --password "" --testnet --trusted-daemon --daemon-address 127.0.0.1:38081 --log-file wallet_m.log
#!/bin/bash -e
./open_wallet_par.sh wallet_m

View File

@ -0,0 +1,15 @@
#!/bin/bash -e
. ./conf.sh
WALLET_NAME=$1
if [ -z $WALLET_NAME ]; then
echo "Please provide the wallet name as the 1st parameter"
exit 1
fi
echo "Opening wallet: $WALLET_NAME"
rlwrap "$WALLET_CLI" --wallet-file "$WALLETS_ROOT_DIR/$WALLET_NAME.bin" --password "" --testnet --trusted-daemon --daemon-address $DAEMON_HOST:$DAEMON_PORT --log-file "$WALLETS_ROOT_DIR/$WALLET_NAME.log"

View File

@ -1,11 +1,13 @@
#!/bin/bash
#!/bin/bash -e
. ./conf.sh
function send_funds {
local amount=$1
local dest=$(cat "$2.address.txt")
local dest=$(cat "$WALLETS_ROOT_DIR/$2.address.txt")
monero-wallet-cli --wallet-file wallet_m --password "" \
--testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_m.log \
"$WALLET_CLI" --wallet-file "$WALLETS_ROOT_DIR/wallet_m.bin" --password "" \
--testnet --trusted-daemon --daemon-address $DAEMON_HOST:$DAEMON_PORT --log-file "$WALLETS_ROOT_DIR/wallet_m.log" \
--command transfer $dest $amount
}
@ -27,6 +29,3 @@ seed_wallets 10
seed_wallets 20
seed_wallets 50
seed_wallets 100