Skip to content

Commit

Permalink
Change importexport tests to use test datadir (#3738)
Browse files Browse the repository at this point in the history
I noticed this was failing to run because my datadir was a later
version. I see it's using my actual datadir which I have my real data
in. Changing this so it does not use a users real database to perform
tests, and instead uses a test datadir.
  • Loading branch information
NullSoldier authored and jowparks committed Apr 5, 2023
1 parent 5ea7e57 commit 18bb2a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ironfish-cli/scripts/import-export-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set -e # exit immediately if anything returns with non-zero exit code
# Change working directory to the script's directory
cd "$(dirname "$0")"

DATA_DIR="../testdbs/importexport"

if ! command -v expect &> /dev/null; then
echo "expect is not installed but is required"
exit 1
Expand All @@ -13,7 +15,7 @@ fi
# check if import was successful
function check_import_success() {
local account_name=$1
ACCOUNTS_OUTPUT=$(../bin/ironfish wallet:accounts)
ACCOUNTS_OUTPUT=$(../bin/ironfish wallet:accounts -d $DATA_DIR)

if echo "$ACCOUNTS_OUTPUT" | grep -q "$account_name"; then
echo "Import successful for $account_name"
Expand All @@ -26,7 +28,7 @@ function check_import_success() {
# check if deletion was successful
function check_delete_success() {
local account_name=$1
ACCOUNTS_OUTPUT=$(../bin/ironfish wallet:accounts)
ACCOUNTS_OUTPUT=$(../bin/ironfish wallet:accounts -d $DATA_DIR)

if ! echo "$ACCOUNTS_OUTPUT" | grep -q "$account_name"; then
echo "Deletion successful for $account_name"
Expand All @@ -50,8 +52,9 @@ function import_account_interactively() {
local account_name="$1"
local file_contents="$2"
echo "Testing interactive import."

expect -c "
spawn ../bin/ironfish wallet:import
spawn ../bin/ironfish wallet:import -d $DATA_DIR
expect \"Paste the output of wallet:export, or your spending key:\"
send {${file_contents}}
send \"\r\"
Expand All @@ -71,7 +74,7 @@ function import_account_interactively() {
"
check_error "Import failed for $account_name"
check_import_success "$ACCOUNT_NAME"
../bin/ironfish wallet:delete $ACCOUNT_NAME
../bin/ironfish wallet:delete $ACCOUNT_NAME -d $DATA_DIR
check_error "Deletion failed for $account_name"
check_delete_success "$ACCOUNT_NAME"
}
Expand All @@ -82,7 +85,7 @@ function import_account_by_pipe() {
local account_name="$1"
local test_file="$2"
expect -c "
spawn sh -c \"cat $test_file | ../bin/ironfish wallet:import\"
spawn sh -c \"cat $test_file | ../bin/ironfish wallet:import -d $DATA_DIR\"
expect {
\"Enter a new account name:\" {
send \"$account_name\\r\"
Expand All @@ -100,7 +103,7 @@ function import_account_by_pipe() {
"
check_error "Import failed for $account_name"
check_import_success "$account_name"
../bin/ironfish wallet:delete $account_name
../bin/ironfish wallet:delete $account_name -d $DATA_DIR
check_error "Deletion failed for $account_name"
check_delete_success "$account_name"
}
Expand All @@ -113,7 +116,7 @@ function import_account_by_path() {
local account_name="$1"
local test_file="$2"
expect -c "
spawn ../bin/ironfish wallet:import --path $test_file
spawn ../bin/ironfish wallet:import --path $test_file -d $DATA_DIR
expect {
\"Enter a new account name:\" {
send \"$account_name\\r\"
Expand All @@ -130,7 +133,7 @@ function import_account_by_path() {
"
check_error "Import failed for $account_name"
check_import_success "$account_name"
../bin/ironfish wallet:delete $account_name
../bin/ironfish wallet:delete $account_name -d $DATA_DIR
check_error "Deletion failed for $account_name"
check_delete_success "$account_name"
}
Expand Down
1 change: 1 addition & 0 deletions ironfish-cli/scripts/import-export-test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When ever the exported wallet format changes, the new wallet format should be included here and it will get automatically tested.

0 comments on commit 18bb2a4

Please sign in to comment.