Skip to content

Commit

Permalink
Merge pull request #2345 from maidsafe/tests_cli-vault
Browse files Browse the repository at this point in the history
tests: add vault CLI testcases
  • Loading branch information
ermineJose authored Nov 4, 2024
2 parents 1352fcb + 5fb5a0d commit 2e1e278
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ env:
GENESIS_SK: 5ec88891c1098a0fede5b98b07f8abc931d7247b7aa310d21ab430cc957f9f02

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Display Python version
run: python --version

cargo-udeps:
if: "!startsWith(github.event.head_commit.message, 'chore(release):')"
name: Unused dependency check
Expand Down Expand Up @@ -340,6 +350,115 @@ jobs:
SN_LOG: "v"
timeout-minutes: 2

- name: Estimate cost to create a vault
if: matrix.os != 'windows-latest'
run: |
echo "test-file" > upload-test.txt
./target/release/autonomi --log-output-dest=data-dir file upload ./upload-test.txt
./target/release/autonomi --log-output-dest=data-dir register create sample_new_register 1234
./target/release/autonomi --log-output-dest=data-dir vault cost
./target/release/autonomi --log-output-dest=data-dir file list 2>&1 | tee file_list.txt
./target/release/autonomi --log-output-dest=data-dir register list 2>&1 | tee register_list.txt
env:
SN_LOG: "v"
timeout-minutes: 2

- name: create a vault with existing user data as above
if: matrix.os != 'windows-latest'
run: ./target/release/autonomi --log-output-dest=data-dir vault create
env:
SN_LOG: "v"
timeout-minutes: 2

- name: add more files
if: matrix.os != 'windows-latest'
run: |
for i in {1..100}; do
dd if=/dev/urandom of=random_file_$i.bin bs=1M count=1 status=none
./target/release/autonomi --log-output-dest=data-dir file upload random_file_$i.bin --public
./target/release/autonomi --log-output-dest=data-dir file upload random_file_$i.bin
./target/release/autonomi --log-output-dest=data-dir register create $i random_file_$i.bin
done
env:
SN_LOG: "v"
timeout-minutes: 25

- name: sync the vault
if: matrix.os != 'windows-latest'
run: ./target/release/autonomi --log-output-dest=data-dir vault sync
env:
SN_LOG: "v"
timeout-minutes: 2

- name: vault sync validation
if: matrix.os != 'windows-latest'
run: |
NUM_OF_PUBLIC_FILES=""
NUM_OF_PRIVATE_FILES=""
NUM_OF_REGISTERS=""
NUM_OF_PUBLIC_FILES_IN_VAULT=""
NUM_OF_PRIVATE_FILES_IN_VAULT=""
NUM_OF_REGISTERS_IN_VAULT=""
./target/release/autonomi --log-output-dest=data-dir file list 2>&1 > file_list.txt
# ./target/release/autonomi --log-output-dest=data-dir register list | grep archives > register_list.txt
NUM_OF_PUBLIC_FILES=`cat file_list.txt | grep "public" | grep -o '[0-9]\+'`
NUM_OF_PRIVATE_FILES=`cat file_list.txt | grep "private" | grep -o '[0-9]\+'`
NUM_OF_REGISTERS=`cat register_list.txt | grep "register" | grep -o '[0-9]\+'`
./target/release/autonomi --log-output-dest=data-dir vault load 2>&1 > vault_data.txt
NUM_OF_PUBLIC_FILES_IN_VAULT=`cat vault_data.txt | grep "public" | grep -o '[0-9]\+'`
NUM_OF_PRIVATE_FILES_IN_VAULT=`cat vault_data.txt| grep "private" | grep -o '[0-9]\+'`
# NUM_OF_REGISTERS_IN_VAULT=`cat vault_data.txt | grep "register" | grep -o '[0-9]\+'`
echo "Total Num of local public files is $NUM_OF_PUBLIC_FILES and in vault is $NUM_OF_PUBLIC_FILES_IN_VAULT"
echo "Total Num of local private files is $NUM_OF_PRIVATE_FILES and in vault is $NUM_OF_PRIVATE_FILES_IN_VAULT"
# echo "Total Num of local registers is $NUM_OF_REGISTERS and in vault is $NUM_OF_REGISTERS_IN_VAULT"
rm -rf file_list.txt register_list.txt vault_data.txt
python3 -c 'import sys; assert sys.argv[1] == sys.argv[2], f"Error: Local public Files: {sys.argv[1]} and vault public files: {sys.argv[2]} are Not Equal"' $NUM_OF_PUBLIC_FILES $NUM_OF_PUBLIC_FILES_IN_VAULT
python3 -c 'import sys; assert sys.argv[1] == sys.argv[2], f"Error: Local private Files: {sys.argv[1]} and vault private files: {sys.argv[2]} are Not Equal"' $NUM_OF_PRIVATE_FILES $NUM_OF_PRIVATE_FILES_IN_VAULT
# python3 -c 'import sys; assert sys.argv[1] == sys.argv[2], f"Error: Local registers: {sys.argv[1]} and vault registers: {sys.argv[2]} are Not Equal"' $NUM_OF_REGISTERS $NUM_OF_REGISTERS_IN_VAULT
echo "vault synced successfully!"
env:
SN_LOG: "v"
timeout-minutes: 15

- name: load an existing vault from the network
if: matrix.os != 'windows-latest'
run: ./target/release/autonomi --log-output-dest=data-dir vault load
env:
SN_LOG: "v"
timeout-minutes: 2

- name: Time profiling for Different files
if: matrix.os != 'windows-latest'
run: |
# 1 MB
python3 -c "with open('random_1MB.bin', 'wb') as f: f.write(bytearray([0xff] * 1 * 1024 * 1024))"
# 10 MB
python3 -c "with open('random_10MB.bin', 'wb') as f: f.write(bytearray([0xff] * 10 * 1024 * 1024))"
# 100 MB
python3 -c "with open('random_100MB.bin', 'wb') as f: f.write(bytearray([0xff] * 100 * 1024 * 1024))"
# 1 GB
python3 -c "with open('random_1GB.bin', 'wb') as f: f.write(bytearray([0xff] * 1000 * 1024 * 1024))"
./target/release/autonomi --log-output-dest=data-dir file list
time ./target/release/autonomi --log-output-dest=data-dir file upload random_1MB.bin
time ./target/release/autonomi --log-output-dest=data-dir file upload random_10MB.bin
time ./target/release/autonomi --log-output-dest=data-dir file upload random_100MB.bin
time ./target/release/autonomi --log-output-dest=data-dir file upload random_1GB.bin
./target/release/autonomi --log-output-dest=data-dir vault sync
rm -rf random*.bin
rm -rf ${{ matrix.safe_path }}/autonomi
env:
SN_LOG: "v"
timeout-minutes: 15

- name: Stop the local network and upload logs
if: always()
uses: maidsafe/sn-local-testnet-action@main
Expand Down

0 comments on commit 2e1e278

Please sign in to comment.