From bcde75bc0b01c922be686439b0af24b954cfc42b Mon Sep 17 00:00:00 2001 From: mrlutik Date: Sun, 2 Apr 2023 20:30:36 +0200 Subject: [PATCH 01/38] Add more files Added ipfs-api/README.md, validator-key-gen/README.md --- build-tools/update_version.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build-tools/update_version.py b/build-tools/update_version.py index db014ba1..9b23c121 100644 --- a/build-tools/update_version.py +++ b/build-tools/update_version.py @@ -55,6 +55,8 @@ def updateVersion(path,ver): "../bip39gen/cmd/version.go":updateVersion, "../ipfs-api/types/constants.go":updateVersion, "../validator-key-gen/main.go":updateVersion, + "../validator-key-gen/README.md":updateVersion, + "../ipfs-api/README.md":updateVersion, } new_release = sys.argv[1] From 7f255d2b809849b1cfbd0a5a82c1c830e7e8f57f Mon Sep 17 00:00:00 2001 From: mrlutik Date: Sun, 2 Apr 2023 23:33:18 +0200 Subject: [PATCH 02/38] Add integration test Integration test for dag, pin, pin with meta, delete, --ovewrite, --force. Doesn't include keyvalues --- ipfs-api/scripts/test.sh | 160 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index e29e6efc..3e1eb5df 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -1,7 +1,167 @@ set -e set +x . /etc/profile +#. ../../bash-utils/bash-utils.sh +. ../bash-utils/bash-utils.sh set -x +echoInfo "Starting unit tests..." go test ./... -vet=off -v || echo "IPFS-API test finished successfully" +echoInfo "Starting integration tests..." + +ROOT_DIR=$(pwd) +MAIN_DIR=$ROOT_DIR/cmd/ipfs-api/main.go +ENTRY_DIR=$ROOT_DIR/test_dir +SECOND_DIR=$ENTRY_DIR/test_dir1 + +echoInfo "Creating directory tree..." +mkdir -p $ENTRY_DIR || echoError "Failed to create directory $ENTRY_DIR" +mkdir -p $SECOND_DIR || echoError "Failed to create directory $SECOND_DIR" + + +echoInfo "Populating directory tree with files..." +# Populate dir with files L1 +set +x +for i in {1..5}; +do + echo "file$i">"$ENTRY_DIR/file$i.txt" || echoError "Failed to create file$i.txt" +done + +# Populate dir with files L2 +for i in {6..10}; +do + echo "file$i">"$SECOND_DIR/file$i.txt" || echoError "Failed to create file$i.txt" +done + + +function dagExportTest(){ + echoNInfo "[ ] dagExportTest" + + local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" + local GOT=$(go run $MAIN_DIR dag $ENTRY_DIR --export) + + if [[ $WANT -eq $GOT ]]; + then + echo -en "\e[0m\e[36;1m\033[1G[PASS] dagExportTest\e[0m"; echo + else + echo -en "\e[0m\e[31;1m\033[1G[PASS] dagExportTest\e[0m"; echo + exit 1 + fi +} + +function pinTest(){ + echoNInfo "[ ] pinTest" + local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" + local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR --key="${{secrets.PINATA_API_JWT_TEST}}" | jq -r .hash) + + if [[ $WANT -eq $GOT ]]; + then + echo -en "\e[0m\e[36;1m\033[1G[PASS] pinTest\e[0m" + echo + else + echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinTest\e[0m" + echo + exit 1 + fi + +} + +function deleteByHashTest(){ + echoNInfo "[ ] deleteByHashTest" + + local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" + local GOT=$(go run $MAIN_DIR delete $WANT --key="${{secrets.PINATA_API_JWT_TEST}}" | jq .success) + + if [[ $GOT -eq $WANT ]]; + then + echo -en "\e[0m\e[36;1m\033[1G[PASS] deleteByHashTest\e[0m"; echo + else + echo -en "\e[0m\e[31;1m\033[1G[FAILED] deleteByHashTest\e[0m"; echo + exit 1 + fi +} + +function pinWithMetaTest(){ + echoNInfo "[ ] pinWithMetaTest" + + local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" + local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR meta --key="${{secrets.PINATA_API_JWT_TEST}}" | jq -r .hash) + + if [[ $WANT -eq $GOT ]]; + then + echo -en "\e[0m\e[36;1m\033[1G[PASS] pinWithMetaTest\e[0m"; echo + else + echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinWithMetaTest\e[0m"; echo + exit 1 + fi + +} + +function pinWithMetaForceTest(){ + echoNInfo "[ ] pinWithMetaForceTest" + + local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" + local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --key="${{secrets.PINATA_API_JWT_TEST}}" | jq -r .hash) + + if [[ $WANT -eq $GOT ]]; + then + echo -en "\e[0m\e[36;1m\033[1G[PASS] pinWithMetaForceTest\e[0m"; echo + else + echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinWithMetaForceTest\e[0m"; echo + exit 1 + fi + +} +function pinWithMetaOverwriteTest(){ + echoNInfo "[ ] pinWithMetaOverwriteTest" + + local WANT="OK" + local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --overwrite --key="${{secrets.PINATA_API_JWT_TEST}}") + if [[ $WANT -eq $GOT ]]; + then + echo -en "\e[0m\e[36;1m\033[1G[PASS] pinWithMetaOverwriteTest\e[0m"; echo + else + echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinWithMetaOverwriteTest\e[0m"; echo + exit 1 + fi + +} + +function deleteByMetaTest(){ + echoNInfo "[PASS] deleteByMetaTest" + + local WANT=true + local GOT=$(go run $MAIN_DIR delete meta --key="${{secrets.PINATA_API_JWT_TEST}}" | jq .success) + if [[ $GOT -eq $WANT ]]; + then + echo -en "\e[0m\e[36;1m\033[1G[PASS] deleteByMetaTest\e[0m"; echo + else + echo -en "\e[0m\e[31;1m\033[1G[FAILED] deleteByMetaTest\e[0m"; echo + exit 1 + fi +} + +function deleteByMetaOverwriteTest(){ + echoNInfo "[PASS] deleteByMetaOverwriteTest" + + local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" + local GOT=$(go run $MAIN_DIR delete foobar --key="${{secrets.PINATA_API_JWT_TEST}}" | jq .success) + + if [[ $GOT -eq true ]]; + then + echo -en "\e[0m\e[36;1m\033[1G[PASS] deleteByMetaOverwriteTest\e[0m"; echo + else + echo -en "\e[0m\e[31;1m\033[1G[FAILED] deleteByMetaOverwriteTest\e[0m"; echo + exit 1 + fi +} +echoInfo "Starting tests..." +TESTS=(dagExportTest pinTest deleteByHashTest pinWithMetaTest deleteByMetaTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaOverwriteTest) +for TEST in "${TESTS[@]}"; do + $TEST +done +echoInfo "All tests finished. Cleaning up the environment..." +set -x +rm -rf $ENTRY_DIR || echoError "Failed to clean up an the environment" +echoInfo "All done..." \ No newline at end of file From c92ad1922580690cac9cbc337e8c1a300128ccee Mon Sep 17 00:00:00 2001 From: mrlutik Date: Sun, 2 Apr 2023 23:36:06 +0200 Subject: [PATCH 03/38] Change ver v0.3.42 -> v0.3.43 --- bash-utils/bash-utils.sh | 3 ++- bip39gen/cmd/version.go | 2 +- build-tools/update_version.py | 2 +- ipfs-api/README.md | 2 +- ipfs-api/types/constants.go | 2 +- scripts/version.sh | 2 +- validator-key-gen/README.md | 2 +- validator-key-gen/main.go | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bash-utils/bash-utils.sh b/bash-utils/bash-utils.sh index ae8846eb..84d564b5 100644 --- a/bash-utils/bash-utils.sh +++ b/bash-utils/bash-utils.sh @@ -26,7 +26,7 @@ function bashUtilsVersion() { # this is default installation script for utils # ./bash-utils.sh bashUtilsSetup "/var/kiraglob" function bashUtilsSetup() { - local BASH_UTILS_VERSION="v0.3.42" + local BASH_UTILS_VERSION="v0.3.43" local COSIGN_VERSION="v2.0.0" if [ "$1" == "version" ] ; then echo "$BASH_UTILS_VERSION" @@ -2312,3 +2312,4 @@ fi + diff --git a/bip39gen/cmd/version.go b/bip39gen/cmd/version.go index 9269eb91..9e7c1b57 100644 --- a/bip39gen/cmd/version.go +++ b/bip39gen/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const Bip39GenVersion = "v0.3.39" +const Bip39GenVersion = "v0.3.43" func cmdVersion(cmd *cobra.Command, args []string) error { fmt.Println(Bip39GenVersion) diff --git a/build-tools/update_version.py b/build-tools/update_version.py index 9b23c121..3cf93ce8 100644 --- a/build-tools/update_version.py +++ b/build-tools/update_version.py @@ -1,7 +1,7 @@ import re import sys -version = "v0.3.39" +version = "v0.3.43" if len(sys.argv) != 2: print("Usage: python3 update_version.py ") diff --git a/ipfs-api/README.md b/ipfs-api/README.md index 11de5682..4f6a253f 100644 --- a/ipfs-api/README.md +++ b/ipfs-api/README.md @@ -5,7 +5,7 @@ A command-line interface (CLI) for interacting with the IPFS API, providing func To install the CLI, clone the repository and build the project using Go.= or dowload from existing release ``` -TOOLS_VERSION="v0.3.39" && rm -rfv /tmp/ipfs-api && \ +TOOLS_VERSION="v0.3.43" && rm -rfv /tmp/ipfs-api && \ safeWget /tmp/ipfs-api.deb "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/ipfs-api-$(getPlatform)-$(getArch).deb" "QmeqFDLGfwoWgCy2ZEFXerVC5XW8c5xgRyhK5bLArBr2ue" && \ dpkg-deb -x /tmp/ipfs-api.deb /tmp/ipfs-api && cp -fv "/tmp/ipfs-api/bin/ipfs-api" /usr/local/bin/ipfs-api && chmod -v 755 /usr/local/bin/ipfs-api && \ ipfs-api version diff --git a/ipfs-api/types/constants.go b/ipfs-api/types/constants.go index 11b47318..0f0dfdaf 100644 --- a/ipfs-api/types/constants.go +++ b/ipfs-api/types/constants.go @@ -1,7 +1,7 @@ package types const ( - IpfsApiVersion = "v0.3.39" + IpfsApiVersion = "v0.3.43" // Pinata v1 constants BASE_URL = "https://api.pinata.cloud" diff --git a/scripts/version.sh b/scripts/version.sh index db041c7b..11a736c0 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.42" +echo "v0.3.43" diff --git a/validator-key-gen/README.md b/validator-key-gen/README.md index 83f03fb4..d9b12832 100644 --- a/validator-key-gen/README.md +++ b/validator-key-gen/README.md @@ -5,7 +5,7 @@ Validator Key Generator is a CLI tool that generates validator keys, node keys, ### Setup from binary file ```bash -TOOLS_VERSION="v0.3.28" +TOOLS_VERSION="v0.3.43" # Quick-Install bash-utils or see root repository README file for secure download FILE_NAME="bash-utils.sh" && \ diff --git a/validator-key-gen/main.go b/validator-key-gen/main.go index 8a0dbd6f..4aca6a48 100644 --- a/validator-key-gen/main.go +++ b/validator-key-gen/main.go @@ -18,7 +18,7 @@ import ( "github.com/tendermint/tendermint/privval" ) -const PrivValidatorKeyGenVersion = "v0.3.39" +const PrivValidatorKeyGenVersion = "v0.3.43" type Prefix struct { fullPath *hd.BIP44Params From 08dd7eaca7500f1f7e5fe103821dd09da2e4c7c7 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Sun, 2 Apr 2023 23:42:05 +0200 Subject: [PATCH 04/38] Fix source for bash-utils --- ipfs-api/scripts/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 3e1eb5df..da55f536 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -1,8 +1,8 @@ set -e set +x . /etc/profile -#. ../../bash-utils/bash-utils.sh -. ../bash-utils/bash-utils.sh +. ../../bash-utils/bash-utils.sh + set -x echoInfo "Starting unit tests..." From 3d2289b5d55a77aea12976e3bd194c2d0ed2ac4b Mon Sep 17 00:00:00 2001 From: mrlutik Date: Sun, 2 Apr 2023 23:44:48 +0200 Subject: [PATCH 05/38] Update RELEASE.md --- RELEASE.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index fc3586c2..d98ae65e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,3 +1,2 @@ Features: - -* added timeout and retry to safeWget +* ipfs-api: add integration tests From 929712ac0cf91d24467534ae786acae39a5272dd Mon Sep 17 00:00:00 2001 From: mrlutik Date: Sun, 2 Apr 2023 23:49:38 +0200 Subject: [PATCH 06/38] Clean source from profile --- ipfs-api/scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index da55f536..a9af37fa 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -1,6 +1,6 @@ set -e set +x -. /etc/profile + . ../../bash-utils/bash-utils.sh set -x From ef7cf5f63822b86fc1dc0479d6ef1ec95bf3afe1 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 14:30:19 +0200 Subject: [PATCH 07/38] Revert commits, refactor revert commits connected to bash-utils, refactor output and secret --- ipfs-api/scripts/test.sh | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index a9af37fa..fdedf01c 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -1,12 +1,8 @@ set -e -set +x - -. ../../bash-utils/bash-utils.sh - set -x echoInfo "Starting unit tests..." -go test ./... -vet=off -v || echo "IPFS-API test finished successfully" +go test ./... -vet=off -v || echoInfo "IPFS-API test finished successfully" echoInfo "Starting integration tests..." @@ -53,15 +49,13 @@ function dagExportTest(){ function pinTest(){ echoNInfo "[ ] pinTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR --key="${{secrets.PINATA_API_JWT_TEST}}" | jq -r .hash) + local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR --key="$PINATA_API_JWT_TEST" | jq -r .hash) if [[ $WANT -eq $GOT ]]; then - echo -en "\e[0m\e[36;1m\033[1G[PASS] pinTest\e[0m" - echo + echo -en "\e[0m\e[36;1m\033[1G[PASS] pinTest\e[0m"; echo else - echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinTest\e[0m" - echo + echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinTest\e[0m"; echo exit 1 fi @@ -71,7 +65,7 @@ function deleteByHashTest(){ echoNInfo "[ ] deleteByHashTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - local GOT=$(go run $MAIN_DIR delete $WANT --key="${{secrets.PINATA_API_JWT_TEST}}" | jq .success) + local GOT=$(go run $MAIN_DIR delete $WANT --key="$PINATA_API_JWT_TEST" | jq .success) if [[ $GOT -eq $WANT ]]; then @@ -86,7 +80,7 @@ function pinWithMetaTest(){ echoNInfo "[ ] pinWithMetaTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR meta --key="${{secrets.PINATA_API_JWT_TEST}}" | jq -r .hash) + local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR meta --key="$PINATA_API_JWT_TEST" | jq -r .hash) if [[ $WANT -eq $GOT ]]; then @@ -102,7 +96,7 @@ function pinWithMetaForceTest(){ echoNInfo "[ ] pinWithMetaForceTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --key="${{secrets.PINATA_API_JWT_TEST}}" | jq -r .hash) + local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --key="$PINATA_API_JWT_TEST" | jq -r .hash) if [[ $WANT -eq $GOT ]]; then @@ -117,7 +111,7 @@ function pinWithMetaOverwriteTest(){ echoNInfo "[ ] pinWithMetaOverwriteTest" local WANT="OK" - local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --overwrite --key="${{secrets.PINATA_API_JWT_TEST}}") + local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --overwrite --key="$PINATA_API_JWT_TEST") if [[ $WANT -eq $GOT ]]; then echo -en "\e[0m\e[36;1m\033[1G[PASS] pinWithMetaOverwriteTest\e[0m"; echo @@ -132,7 +126,7 @@ function deleteByMetaTest(){ echoNInfo "[PASS] deleteByMetaTest" local WANT=true - local GOT=$(go run $MAIN_DIR delete meta --key="${{secrets.PINATA_API_JWT_TEST}}" | jq .success) + local GOT=$(go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" | jq .success) if [[ $GOT -eq $WANT ]]; then echo -en "\e[0m\e[36;1m\033[1G[PASS] deleteByMetaTest\e[0m"; echo @@ -145,8 +139,8 @@ function deleteByMetaTest(){ function deleteByMetaOverwriteTest(){ echoNInfo "[PASS] deleteByMetaOverwriteTest" - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - local GOT=$(go run $MAIN_DIR delete foobar --key="${{secrets.PINATA_API_JWT_TEST}}" | jq .success) + local WANT=true + local GOT=$(go run $MAIN_DIR delete foobar --key="$PINATA_API_JWT_TEST" | jq .success) if [[ $GOT -eq true ]]; then @@ -156,7 +150,9 @@ function deleteByMetaOverwriteTest(){ exit 1 fi } + echoInfo "Starting tests..." + TESTS=(dagExportTest pinTest deleteByHashTest pinWithMetaTest deleteByMetaTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaOverwriteTest) for TEST in "${TESTS[@]}"; do $TEST From 02712aa1f1f0163a8e4136f0f1a305f9c0632213 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 14:33:16 +0200 Subject: [PATCH 08/38] Update main.yml change base-image v0.11.2 -> v0.13.7 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a2f738bc..6ec12631 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: id-token: write pull-requests: write container: - image: ghcr.io/kiracore/docker/base-image:v0.11.2 + image: ghcr.io/kiracore/docker/base-image:v0.13.7 steps: # Work around https://github.com/actions/checkout/issues/760 - name: Add safe.directory From 1c0ff9d000624772df5b1548cc4f7e1c21051777 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 14:52:20 +0200 Subject: [PATCH 09/38] Add bu before func call --- ipfs-api/scripts/test.sh | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index fdedf01c..65dc09ba 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -1,38 +1,38 @@ set -e set -x -echoInfo "Starting unit tests..." -go test ./... -vet=off -v || echoInfo "IPFS-API test finished successfully" +bu echoInfo "Starting unit tests..." +go test ./... -vet=off -v || bu echoInfo "IPFS-API test finished successfully" -echoInfo "Starting integration tests..." +bu echoInfo "Starting integration tests..." ROOT_DIR=$(pwd) MAIN_DIR=$ROOT_DIR/cmd/ipfs-api/main.go ENTRY_DIR=$ROOT_DIR/test_dir SECOND_DIR=$ENTRY_DIR/test_dir1 -echoInfo "Creating directory tree..." -mkdir -p $ENTRY_DIR || echoError "Failed to create directory $ENTRY_DIR" -mkdir -p $SECOND_DIR || echoError "Failed to create directory $SECOND_DIR" +bu echoInfo "Creating directory tree..." +mkdir -p $ENTRY_DIR || bu echoError "Failed to create directory $ENTRY_DIR" +mkdir -p $SECOND_DIR || bu echoError "Failed to create directory $SECOND_DIR" -echoInfo "Populating directory tree with files..." +bu echoInfo "Populating directory tree with files..." # Populate dir with files L1 set +x for i in {1..5}; do - echo "file$i">"$ENTRY_DIR/file$i.txt" || echoError "Failed to create file$i.txt" + echo "file$i">"$ENTRY_DIR/file$i.txt" || bu echoError "Failed to create file$i.txt" done # Populate dir with files L2 for i in {6..10}; do - echo "file$i">"$SECOND_DIR/file$i.txt" || echoError "Failed to create file$i.txt" + echo "file$i">"$SECOND_DIR/file$i.txt" || bu echoError "Failed to create file$i.txt" done function dagExportTest(){ - echoNInfo "[ ] dagExportTest" + bu echoNInfo "[ ] dagExportTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR dag $ENTRY_DIR --export) @@ -47,7 +47,7 @@ function dagExportTest(){ } function pinTest(){ - echoNInfo "[ ] pinTest" + bu echoNInfo "[ ] pinTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR --key="$PINATA_API_JWT_TEST" | jq -r .hash) @@ -62,7 +62,7 @@ function pinTest(){ } function deleteByHashTest(){ - echoNInfo "[ ] deleteByHashTest" + bu echoNInfo "[ ] deleteByHashTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR delete $WANT --key="$PINATA_API_JWT_TEST" | jq .success) @@ -77,7 +77,7 @@ function deleteByHashTest(){ } function pinWithMetaTest(){ - echoNInfo "[ ] pinWithMetaTest" + bu echoNInfo "[ ] pinWithMetaTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR meta --key="$PINATA_API_JWT_TEST" | jq -r .hash) @@ -93,7 +93,7 @@ function pinWithMetaTest(){ } function pinWithMetaForceTest(){ - echoNInfo "[ ] pinWithMetaForceTest" + bu echoNInfo "[ ] pinWithMetaForceTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --key="$PINATA_API_JWT_TEST" | jq -r .hash) @@ -108,7 +108,7 @@ function pinWithMetaForceTest(){ } function pinWithMetaOverwriteTest(){ - echoNInfo "[ ] pinWithMetaOverwriteTest" + bu echoNInfo "[ ] pinWithMetaOverwriteTest" local WANT="OK" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --overwrite --key="$PINATA_API_JWT_TEST") @@ -123,7 +123,7 @@ function pinWithMetaOverwriteTest(){ } function deleteByMetaTest(){ - echoNInfo "[PASS] deleteByMetaTest" + bu echoNInfo "[PASS] deleteByMetaTest" local WANT=true local GOT=$(go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" | jq .success) @@ -137,7 +137,7 @@ function deleteByMetaTest(){ } function deleteByMetaOverwriteTest(){ - echoNInfo "[PASS] deleteByMetaOverwriteTest" + bu echoNInfo "[PASS] deleteByMetaOverwriteTest" local WANT=true local GOT=$(go run $MAIN_DIR delete foobar --key="$PINATA_API_JWT_TEST" | jq .success) @@ -151,13 +151,13 @@ function deleteByMetaOverwriteTest(){ fi } -echoInfo "Starting tests..." +bu echoInfo "Starting tests..." TESTS=(dagExportTest pinTest deleteByHashTest pinWithMetaTest deleteByMetaTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaOverwriteTest) for TEST in "${TESTS[@]}"; do $TEST done -echoInfo "All tests finished. Cleaning up the environment..." +bu echoInfo "All tests finished. Cleaning up the environment..." set -x -rm -rf $ENTRY_DIR || echoError "Failed to clean up an the environment" -echoInfo "All done..." \ No newline at end of file +rm -rf $ENTRY_DIR || bu echoError "Failed to clean up an the environment" +bu echoInfo "All done..." \ No newline at end of file From 0ee149febc8b768ca68f34fa8a89930cb5ea6077 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 15:21:46 +0200 Subject: [PATCH 10/38] Delete 'function' keyword --- ipfs-api/scripts/test.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 65dc09ba..99d00ddf 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -1,3 +1,5 @@ +#!/usr/bin/bash + set -e set -x @@ -31,7 +33,7 @@ do done -function dagExportTest(){ +dagExportTest(){ bu echoNInfo "[ ] dagExportTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" @@ -46,7 +48,7 @@ function dagExportTest(){ fi } -function pinTest(){ +pinTest(){ bu echoNInfo "[ ] pinTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR --key="$PINATA_API_JWT_TEST" | jq -r .hash) @@ -61,7 +63,7 @@ function pinTest(){ } -function deleteByHashTest(){ +deleteByHashTest(){ bu echoNInfo "[ ] deleteByHashTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" @@ -76,7 +78,7 @@ function deleteByHashTest(){ fi } -function pinWithMetaTest(){ +pinWithMetaTest(){ bu echoNInfo "[ ] pinWithMetaTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" @@ -92,7 +94,7 @@ function pinWithMetaTest(){ } -function pinWithMetaForceTest(){ +pinWithMetaForceTest(){ bu echoNInfo "[ ] pinWithMetaForceTest" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" @@ -107,7 +109,7 @@ function pinWithMetaForceTest(){ fi } -function pinWithMetaOverwriteTest(){ +pinWithMetaOverwriteTest(){ bu echoNInfo "[ ] pinWithMetaOverwriteTest" local WANT="OK" @@ -122,7 +124,7 @@ function pinWithMetaOverwriteTest(){ } -function deleteByMetaTest(){ +deleteByMetaTest(){ bu echoNInfo "[PASS] deleteByMetaTest" local WANT=true @@ -136,7 +138,7 @@ function deleteByMetaTest(){ fi } -function deleteByMetaOverwriteTest(){ +deleteByMetaOverwriteTest(){ bu echoNInfo "[PASS] deleteByMetaOverwriteTest" local WANT=true From 6ca81f3b4e98012dccd91683478eac8a04679a5a Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 15:39:02 +0200 Subject: [PATCH 11/38] Add env with pinata secrete to job 'Testing & Building TOOLS' --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ec12631..e6fe68ba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -71,6 +71,8 @@ jobs: echo " Release exists: ${{ env.RELEASE_EXISTS }}" go version - name: Testing & Building TOOLS + env: + PINATA_API_JWT_TEST="${{secrets.PINATA_API_JWT_TEST}}" run: | set -x echo "(current dir): $PWD" && ls -l ./ From 57118bb47be6020c1db1e2811520b5aff018408f Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 15:45:25 +0200 Subject: [PATCH 12/38] Syntax fix --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6fe68ba..de57d7a3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,7 +72,7 @@ jobs: go version - name: Testing & Building TOOLS env: - PINATA_API_JWT_TEST="${{secrets.PINATA_API_JWT_TEST}}" + PINATA_API_JWT_TEST: ${{ secrets.PINATA_API_JWT_TEST }} run: | set -x echo "(current dir): $PWD" && ls -l ./ From 0fbe41b9f02c5d9d284943b432fde0ecff18245f Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 17:07:03 +0200 Subject: [PATCH 13/38] Format output --- .github/workflows/main.yml | 2 +- ipfs-api/scripts/test.sh | 74 ++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index de57d7a3..e6fe68ba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,7 +72,7 @@ jobs: go version - name: Testing & Building TOOLS env: - PINATA_API_JWT_TEST: ${{ secrets.PINATA_API_JWT_TEST }} + PINATA_API_JWT_TEST="${{secrets.PINATA_API_JWT_TEST}}" run: | set -x echo "(current dir): $PWD" && ls -l ./ diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 99d00ddf..35c6bb15 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -34,121 +34,122 @@ done dagExportTest(){ - bu echoNInfo "[ ] dagExportTest" + echo -en "\033[1G\e[0m\e[36;1m[ ] dagExportTest\e[0m" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR dag $ENTRY_DIR --export) - if [[ $WANT -eq $GOT ]]; + if [[ $WANT == $GOT ]]; then - echo -en "\e[0m\e[36;1m\033[1G[PASS] dagExportTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[36;1m[PASS] dagExportTest\e[0m"; echo else - echo -en "\e[0m\e[31;1m\033[1G[PASS] dagExportTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[31;1m[FAIL] dagExportTest\e[0m"; echo exit 1 fi } pinTest(){ - bu echoNInfo "[ ] pinTest" + echo -en "\033[1G\e[0m\e[36;1m[ ] pinTest\e[0m" + local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR --key="$PINATA_API_JWT_TEST" | jq -r .hash) - if [[ $WANT -eq $GOT ]]; + if [[ $WANT == $GOT ]]; then - echo -en "\e[0m\e[36;1m\033[1G[PASS] pinTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[36;1m[PASS] pinTest\e[0m"; echo else - echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[31;1m[FAIL] pinTest\e[0m"; echo exit 1 fi } deleteByHashTest(){ - bu echoNInfo "[ ] deleteByHashTest" + echo -en "\033[1G\e[0m\e[36;1m[ ] deleteByHashTest\e[0m" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR delete $WANT --key="$PINATA_API_JWT_TEST" | jq .success) - if [[ $GOT -eq $WANT ]]; + if [[ $GOT == $WANT ]]; then - echo -en "\e[0m\e[36;1m\033[1G[PASS] deleteByHashTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByHashTest\e[0m"; echo else - echo -en "\e[0m\e[31;1m\033[1G[FAILED] deleteByHashTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByHashTest\e[0m"; echo exit 1 fi } pinWithMetaTest(){ - bu echoNInfo "[ ] pinWithMetaTest" + echo -en "\033[1G\e[0m\e[36;1m[ ] pinWithMetaTest\e[0m" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR meta --key="$PINATA_API_JWT_TEST" | jq -r .hash) - if [[ $WANT -eq $GOT ]]; + if [[ $WANT == $GOT ]]; then - echo -en "\e[0m\e[36;1m\033[1G[PASS] pinWithMetaTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[36;1m[PASS] pinWithMetaTest\e[0m"; echo else - echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinWithMetaTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[31;1m[FAIL] pinWithMetaTest\e[0m"; echo exit 1 fi } pinWithMetaForceTest(){ - bu echoNInfo "[ ] pinWithMetaForceTest" + echo -en "\033[1G\e[0m\e[36;1m[ ] pinWithMetaForceTest\e[0m" local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --key="$PINATA_API_JWT_TEST" | jq -r .hash) - if [[ $WANT -eq $GOT ]]; + if [[ $WANT == $GOT ]]; then - echo -en "\e[0m\e[36;1m\033[1G[PASS] pinWithMetaForceTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[36;1m[PASS] pinWithMetaForceTest\e[0m"; echo else - echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinWithMetaForceTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[31;1m[FAIL] pinWithMetaForceTest\e[0m"; echo exit 1 fi } pinWithMetaOverwriteTest(){ - bu echoNInfo "[ ] pinWithMetaOverwriteTest" + echo -en "\033[1G\e[0m\e[36;1m[ ] pinWithMetaOverwriteTest\e[0m" local WANT="OK" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --overwrite --key="$PINATA_API_JWT_TEST") - if [[ $WANT -eq $GOT ]]; + if [[ $WANT == $GOT ]]; then - echo -en "\e[0m\e[36;1m\033[1G[PASS] pinWithMetaOverwriteTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[36;1m[PASS] pinWithMetaOverwriteTest\e[0m"; echo else - echo -en "\e[0m\e[31;1m\033[1G[FAILED] pinWithMetaOverwriteTest\e[0m"; echo - exit 1 + echo -en "\033[1G\e[0m\e[31;1m[FAIL] pinWithMetaOverwriteTest\e[0m"; echo + exit 1 fi } deleteByMetaTest(){ - bu echoNInfo "[PASS] deleteByMetaTest" + echo -en "\033[1G\e[0m\e[36;1m[ ] deleteByMetaTest\e[0m" local WANT=true local GOT=$(go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" | jq .success) - if [[ $GOT -eq $WANT ]]; - then - echo -en "\e[0m\e[36;1m\033[1G[PASS] deleteByMetaTest\e[0m"; echo + if [[ $GOT == $WANT ]]; + then + echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByMetaTest\e[0m"; echo else - echo -en "\e[0m\e[31;1m\033[1G[FAILED] deleteByMetaTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByMetaTest\e[0m"; echo exit 1 fi } deleteByMetaOverwriteTest(){ - bu echoNInfo "[PASS] deleteByMetaOverwriteTest" + echo -en "\033[1G\e[0m\e[36;1m[ ] deleteByMetaOverwriteTest\e[0m" local WANT=true local GOT=$(go run $MAIN_DIR delete foobar --key="$PINATA_API_JWT_TEST" | jq .success) - if [[ $GOT -eq true ]]; - then - echo -en "\e[0m\e[36;1m\033[1G[PASS] deleteByMetaOverwriteTest\e[0m"; echo + if [[ $GOT == $WANT ]]; + then + echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByMetaOverwriteTest\e[0m"; echo else - echo -en "\e[0m\e[31;1m\033[1G[FAILED] deleteByMetaOverwriteTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByMetaOverwriteTest\e[0m"; echo exit 1 fi } @@ -159,7 +160,10 @@ TESTS=(dagExportTest pinTest deleteByHashTest pinWithMetaTest deleteByMetaTest p for TEST in "${TESTS[@]}"; do $TEST done + bu echoInfo "All tests finished. Cleaning up the environment..." + set -x + rm -rf $ENTRY_DIR || bu echoError "Failed to clean up an the environment" bu echoInfo "All done..." \ No newline at end of file From 873b373ceb38477c450f1155ddcfc4f06c6c3f0c Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 17:12:51 +0200 Subject: [PATCH 14/38] Add secret --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6fe68ba..d4cca7bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,7 +72,7 @@ jobs: go version - name: Testing & Building TOOLS env: - PINATA_API_JWT_TEST="${{secrets.PINATA_API_JWT_TEST}}" + PINATA_API_JWT_TEST: "${{ secrets.PINATA_API_JWT_TEST }}" run: | set -x echo "(current dir): $PWD" && ls -l ./ From 8c05ee93aa3e265889802bef8eb9540325a7408f Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 17:25:37 +0200 Subject: [PATCH 15/38] Fix comparison --- ipfs-api/scripts/test.sh | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 35c6bb15..5206a206 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -34,8 +34,6 @@ done dagExportTest(){ - echo -en "\033[1G\e[0m\e[36;1m[ ] dagExportTest\e[0m" - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR dag $ENTRY_DIR --export) @@ -49,8 +47,6 @@ dagExportTest(){ } pinTest(){ - echo -en "\033[1G\e[0m\e[36;1m[ ] pinTest\e[0m" - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR --key="$PINATA_API_JWT_TEST" | jq -r .hash) @@ -65,9 +61,7 @@ pinTest(){ } deleteByHashTest(){ - echo -en "\033[1G\e[0m\e[36;1m[ ] deleteByHashTest\e[0m" - - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" + local WANT=true local GOT=$(go run $MAIN_DIR delete $WANT --key="$PINATA_API_JWT_TEST" | jq .success) if [[ $GOT == $WANT ]]; @@ -80,8 +74,6 @@ deleteByHashTest(){ } pinWithMetaTest(){ - echo -en "\033[1G\e[0m\e[36;1m[ ] pinWithMetaTest\e[0m" - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR meta --key="$PINATA_API_JWT_TEST" | jq -r .hash) @@ -96,8 +88,6 @@ pinWithMetaTest(){ } pinWithMetaForceTest(){ - echo -en "\033[1G\e[0m\e[36;1m[ ] pinWithMetaForceTest\e[0m" - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --key="$PINATA_API_JWT_TEST" | jq -r .hash) @@ -111,8 +101,6 @@ pinWithMetaForceTest(){ } pinWithMetaOverwriteTest(){ - echo -en "\033[1G\e[0m\e[36;1m[ ] pinWithMetaOverwriteTest\e[0m" - local WANT="OK" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --overwrite --key="$PINATA_API_JWT_TEST") if [[ $WANT == $GOT ]]; @@ -126,8 +114,6 @@ pinWithMetaOverwriteTest(){ } deleteByMetaTest(){ - echo -en "\033[1G\e[0m\e[36;1m[ ] deleteByMetaTest\e[0m" - local WANT=true local GOT=$(go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" | jq .success) if [[ $GOT == $WANT ]]; @@ -140,8 +126,6 @@ deleteByMetaTest(){ } deleteByMetaOverwriteTest(){ - echo -en "\033[1G\e[0m\e[36;1m[ ] deleteByMetaOverwriteTest\e[0m" - local WANT=true local GOT=$(go run $MAIN_DIR delete foobar --key="$PINATA_API_JWT_TEST" | jq .success) From 02084a9157bc2377dcc47bad1fc661060493b524 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 17:30:58 +0200 Subject: [PATCH 16/38] Hardcoded hash --- ipfs-api/scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 5206a206..f362d009 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -62,7 +62,7 @@ pinTest(){ deleteByHashTest(){ local WANT=true - local GOT=$(go run $MAIN_DIR delete $WANT --key="$PINATA_API_JWT_TEST" | jq .success) + local GOT=$(go run $MAIN_DIR delete bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4 --key="$PINATA_API_JWT_TEST" | jq .success) if [[ $GOT == $WANT ]]; then From 4dbf7ba5c12bf1dcfec8cc038f78897786f3bb1c Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 18:27:30 +0200 Subject: [PATCH 17/38] Add test deleteByMetaForceTest --- ipfs-api/scripts/test.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index f362d009..440b25a7 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -87,6 +87,19 @@ pinWithMetaTest(){ } +deleteByMetaTest(){ + local WANT=true + local GOT=$(go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" | jq .success) + if [[ $GOT == $WANT ]]; + then + echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByMetaTest\e[0m"; echo + else + echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByMetaTest\e[0m"; echo + echo "SUCCESS: $GOT" + exit 1 + fi +} + pinWithMetaForceTest(){ local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --key="$PINATA_API_JWT_TEST" | jq -r .hash) @@ -113,19 +126,21 @@ pinWithMetaOverwriteTest(){ } -deleteByMetaTest(){ + +deleteByMetaOverwriteTest(){ local WANT=true - local GOT=$(go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" | jq .success) + local GOT=$(go run $MAIN_DIR delete foobar --key="$PINATA_API_JWT_TEST" | jq .success) + if [[ $GOT == $WANT ]]; then - echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByMetaTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByMetaOverwriteTest\e[0m"; echo else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByMetaTest\e[0m"; echo + echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByMetaOverwriteTest\e[0m"; echo exit 1 fi } -deleteByMetaOverwriteTest(){ +deleteByMetaForceTest(){ local WANT=true local GOT=$(go run $MAIN_DIR delete foobar --key="$PINATA_API_JWT_TEST" | jq .success) @@ -140,7 +155,7 @@ deleteByMetaOverwriteTest(){ bu echoInfo "Starting tests..." -TESTS=(dagExportTest pinTest deleteByHashTest pinWithMetaTest deleteByMetaTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaOverwriteTest) +TESTS=(dagExportTest pinTest deleteByHashTest pinWithMetaTest deleteByMetaTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaForceTest) for TEST in "${TESTS[@]}"; do $TEST done @@ -150,4 +165,5 @@ bu echoInfo "All tests finished. Cleaning up the environment..." set -x rm -rf $ENTRY_DIR || bu echoError "Failed to clean up an the environment" + bu echoInfo "All done..." \ No newline at end of file From 507a60fc50120f64675489c6755fd7a00d5a14ea Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 18:34:40 +0200 Subject: [PATCH 18/38] Checnge test order --- ipfs-api/scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 440b25a7..af4da7eb 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -155,7 +155,7 @@ deleteByMetaForceTest(){ bu echoInfo "Starting tests..." -TESTS=(dagExportTest pinTest deleteByHashTest pinWithMetaTest deleteByMetaTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaForceTest) +TESTS=(dagExportTest pinTest deleteByHashTest pinWithMetaTest deleteByHashTest pinWithMetaTest deleteByMetaTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaForceTest) for TEST in "${TESTS[@]}"; do $TEST done From a7dbd33b409e07cfec8bb2182e598884f09d62f9 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 19:17:33 +0200 Subject: [PATCH 19/38] Debug url.Url --- ipfs-api/pkg/pinatav2/pinata2_pinata_api.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ipfs-api/pkg/pinatav2/pinata2_pinata_api.go b/ipfs-api/pkg/pinatav2/pinata2_pinata_api.go index 18590d04..01f0b8af 100644 --- a/ipfs-api/pkg/pinatav2/pinata2_pinata_api.go +++ b/ipfs-api/pkg/pinatav2/pinata2_pinata_api.go @@ -167,6 +167,7 @@ func (p *PinataApi) Pinned(hash string) error { } else { // Set the URL to search by metadata name. url.Set(tp.BASE_URL + tp.PINNEDDATA + "/?status=pinned&metadata[name]=" + hash) + log.Debug("Url formed to get meta: ", url.url) } // Create a new request using the PinataApi request object. From b1bda93a2d57ced89de8ba49663f005c40a469b2 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Mon, 3 Apr 2023 19:19:51 +0200 Subject: [PATCH 20/38] Debug url.Url --- ipfs-api/scripts/test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index af4da7eb..65e488fb 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -75,7 +75,8 @@ deleteByHashTest(){ pinWithMetaTest(){ local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR meta --key="$PINATA_API_JWT_TEST" | jq -r .hash) + + local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR meta --key="$PINATA_API_JWT_TEST" | jq -r .hash) if [[ $WANT == $GOT ]]; then From 0df17bde988e262f7f9db118699814948467bd67 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 14:56:44 +0200 Subject: [PATCH 21/38] Change tests order --- ipfs-api/scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 65e488fb..4a52fa85 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -156,7 +156,7 @@ deleteByMetaForceTest(){ bu echoInfo "Starting tests..." -TESTS=(dagExportTest pinTest deleteByHashTest pinWithMetaTest deleteByHashTest pinWithMetaTest deleteByMetaTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaForceTest) +TESTS=(dagExportTest pinWithMetaTest deleteByMetaTest pinTest deleteByHashTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaForceTest) for TEST in "${TESTS[@]}"; do $TEST done From d67c62a5040cd22d1c72fcca2602ff8b3cd4e059 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 15:07:13 +0200 Subject: [PATCH 22/38] Add cleaning results If previous test failed we should clean the results by hash and meta --- ipfs-api/scripts/test.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 4a52fa85..7226633f 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -154,7 +154,12 @@ deleteByMetaForceTest(){ fi } -bu echoInfo "Starting tests..." +bu echoInfo "Clearing failed results if any..." + +go run $MAIN_DIR delete bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4 --key="$PINATA_API_JWT_TEST" --verbose ||: +go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" --verbose ||: + +bu echoInfo "Running tests" TESTS=(dagExportTest pinWithMetaTest deleteByMetaTest pinTest deleteByHashTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaForceTest) for TEST in "${TESTS[@]}"; do From 9f0f05d7a6b98fe9bf85c229da9627ef52f2dd0b Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 15:14:57 +0200 Subject: [PATCH 23/38] Add sleep --- ipfs-api/scripts/test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 7226633f..99294a79 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -164,6 +164,7 @@ bu echoInfo "Running tests" TESTS=(dagExportTest pinWithMetaTest deleteByMetaTest pinTest deleteByHashTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaForceTest) for TEST in "${TESTS[@]}"; do $TEST + sleep 3 done bu echoInfo "All tests finished. Cleaning up the environment..." From b4eeef3e0e770a005b86773b72761326e6753536 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 18:53:30 +0200 Subject: [PATCH 24/38] Refactor Changed method Unpin, unpin. Added OutputPinnedJsonObj --- ipfs-api/pkg/cli/unpin.go | 43 +- ipfs-api/pkg/pinatav2/pinatav2_dirwalker.go | 55 ++ ipfs-api/pkg/pinatav2/pinatav2_efi.go | 14 + ipfs-api/pkg/pinatav2/pinatav2_header.go | 12 + ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go | 485 ++++++++++++++++++ .../pkg/pinatav2/pinatav2_pinata_api_test.go | 103 ++++ 6 files changed, 701 insertions(+), 11 deletions(-) create mode 100644 ipfs-api/pkg/pinatav2/pinatav2_dirwalker.go create mode 100644 ipfs-api/pkg/pinatav2/pinatav2_efi.go create mode 100644 ipfs-api/pkg/pinatav2/pinatav2_header.go create mode 100644 ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go create mode 100644 ipfs-api/pkg/pinatav2/pinatav2_pinata_api_test.go diff --git a/ipfs-api/pkg/cli/unpin.go b/ipfs-api/pkg/cli/unpin.go index fb7b2396..47c3a71a 100644 --- a/ipfs-api/pkg/cli/unpin.go +++ b/ipfs-api/pkg/cli/unpin.go @@ -2,6 +2,7 @@ package cli import ( "errors" + "fmt" log "github.com/kiracore/tools/ipfs-api/pkg/ipfslog" pnt "github.com/kiracore/tools/ipfs-api/pkg/pinatav2" @@ -24,6 +25,7 @@ var unpinCommand = &cobra.Command{ // // Returns an error if the unpin operation fails or the arguments are empty. func unpin(cmd *cobra.Command, args []string) error { + hash := args[0] // Check if the arguments are empty. if len(args) == 0 { log.Error("unpin: empty arg") @@ -38,22 +40,41 @@ func unpin(cmd *cobra.Command, args []string) error { } // Set up the PinataApi instance with the obtained keys and the provided argument. - p := pnt.PinataApi{} - p.SetKeys(keys) - p.SetData(args[0]) + pin := pnt.PinataApi{} - // Unpin the content using the Pinata API. - if err := p.Unpin(args[0]); err != nil { - log.Error("unable to unpin: %v", err) - return err - } + pin.SetKeys(keys) + pin.SetData(hash) - // Output the result of the unpin operation. - err = p.OutputUnpinJson() + pin.Pinned(hash) + + // Unmarshal the response into a PinnedResponse struct. + pinned, err := pin.OutputPinnedJsonObj() if err != nil { - log.Error("failed to print results") return err } + // Check the count of pinned content with the given metadata name. + switch pinned.Count { + case 0: + return fmt.Errorf(`not found. data with name %s doesn't exist`, hash) + case 1: + // Set the URL for unpinning by IPFS hash. + unpin := pnt.PinataApi{} + unpin.SetKeys(keys) + + if err := unpin.Unpin(pinned.Rows[0].CID); err != nil { + log.Error("unable to unpin: %v", err) + return err + } + err = unpin.OutputUnpinJson() + if err != nil { + log.Error("failed to print results") + return err + } + + default: + return errors.New("more than one result returned") + } + return nil } diff --git a/ipfs-api/pkg/pinatav2/pinatav2_dirwalker.go b/ipfs-api/pkg/pinatav2/pinatav2_dirwalker.go new file mode 100644 index 00000000..e9d93182 --- /dev/null +++ b/ipfs-api/pkg/pinatav2/pinatav2_dirwalker.go @@ -0,0 +1,55 @@ +package pinatav2 + +import ( + "io/fs" + "os" + "path/filepath" + "sync" + + log "github.com/kiracore/tools/ipfs-api/pkg/ipfslog" +) + +func (w *Walker) Walk(rootDir string) error { + ap, err := filepath.Abs(rootDir) + base := filepath.Base(ap) + if err != nil { + return err + } + + var wg sync.WaitGroup + var efi = []ExtendedFileInfo{} + + wg.Add(1) + go func() { + + err := filepath.Walk(ap, func(path string, info fs.FileInfo, err error) error { + if err != nil { + os.Exit(1) + return err + } + if !info.IsDir() { + rel, err := filepath.Rel(ap, path) + + if err != nil { + log.Error("walker: can't get relative path for %v. err: %v", path, err) + os.Exit(1) + } + fn := filepath.Clean(base + "/" + rel) + e := ExtendedFileInfo{} + efi = append(efi, e.Set(info, fn, path)) + } + + return nil + + }) + if err != nil { + os.Exit(1) + return + } + wg.Done() + }() + wg.Wait() + w.bulk = efi + return nil + +} diff --git a/ipfs-api/pkg/pinatav2/pinatav2_efi.go b/ipfs-api/pkg/pinatav2/pinatav2_efi.go new file mode 100644 index 00000000..9843fe6e --- /dev/null +++ b/ipfs-api/pkg/pinatav2/pinatav2_efi.go @@ -0,0 +1,14 @@ +package pinatav2 + +import "io/fs" + +func (e ExtendedFileInfo) Set(fs fs.FileInfo, p string, ap string) ExtendedFileInfo { + return ExtendedFileInfo{info: fs, path: p, absoultePath: ap} +} +func (e ExtendedFileInfo) Abs() string { + return e.absoultePath +} + +func (e ExtendedFileInfo) Path() string { + return e.path +} diff --git a/ipfs-api/pkg/pinatav2/pinatav2_header.go b/ipfs-api/pkg/pinatav2/pinatav2_header.go new file mode 100644 index 00000000..340f9538 --- /dev/null +++ b/ipfs-api/pkg/pinatav2/pinatav2_header.go @@ -0,0 +1,12 @@ +package pinatav2 + +func (h *Header) Init() { + if h.keys.jwt != "" { + + h.header.Add("Authorization", "Bearer "+h.keys.jwt) + + } else { + h.header.Add("pinata_api_key", h.keys.api_key) + h.header.Add("pinata_secret_api_key", h.keys.api_secret) + } +} diff --git a/ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go b/ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go new file mode 100644 index 00000000..f1d16dfa --- /dev/null +++ b/ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go @@ -0,0 +1,485 @@ +package pinatav2 + +import ( + "bytes" + "crypto/tls" + "encoding/json" + "errors" + "fmt" + "io" + "mime/multipart" + "os" + + "net/http" + "net/http/httputil" + "net/textproto" + "time" + + cid "github.com/ipfs/go-cid" + log "github.com/kiracore/tools/ipfs-api/pkg/ipfslog" + tp "github.com/kiracore/tools/ipfs-api/types" + "golang.org/x/net/http2" +) + +// Setting new client for an Api +func ValidateCid(hash string) bool { + _, err := cid.Decode(hash) + if err != nil { + return false + } + return true +} + +func (p *PinataApi) newClient() { + + // Client params to be adjusted ... + tr := &http.Transport{ + MaxIdleConnsPerHost: 100, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + ExpectContinueTimeout: 5 * time.Second, + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + } + http2.ConfigureTransport(tr) + p.client = http.Client{ + Timeout: 100 * time.Second, + Transport: tr, + } + +} + +// Adding keys to request header +func (p *PinataApi) SetKeys(keys Keys) { + p.request.header.keys = keys + p.newClient() + p.SetOptsDefault() +} + +// Sending GET request to check authorization +func (p *PinataApi) Test() error { + req, err := p.request.Get(tp.BASE_URL + tp.TESTAUTH) + if err != nil { + log.Debug("Ipfs-api: test: invalid request: %v", err) + return err + } + + resp, err := p.client.Do(req) + if err != nil { + log.Debug("Ipfs-api: test: invalid response: %v", err) + return err + } + defer resp.Body.Close() + + b, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + p.SaveResp(b) + p.SetRespCode(resp.StatusCode) + + return nil +} + +// Unpin removes the content from the Pinata API by its IPFS hash or metadata name. +// This function returns an error if the unpinning operation fails. +// +// hash: A string containing either the IPFS hash or the metadata name of the content. +// +// Returns an error if any operation fails. +func (p *PinataApi) Unpin(hash string) error { + // Initialize a Url instance. + url := Url{} + + // Set the URL for unpinning by IPFS hash. + url.Set(tp.BASE_URL + tp.UNPIN + "/" + hash) + + // Create a new DELETE request using the PinataApi request object. + req, err := p.request.Del(url.Get()) + if err != nil { + return err + } + + // Send the request and get the response. + resp, err := p.client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + // Read the response body. + b, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + + // Save the response body and status code to the PinataApi instance. + p.SaveResp(b) + p.SetRespCode(resp.StatusCode) + + return nil +} + +// Pinned retrieves the pinned content by hash or metadata name from the Pinata API. +// This function returns an error if the request to the Pinata API fails. +// +// hash: A string containing either the IPFS hash or the metadata name of the content. +// +// Returns an error if any operation fails. +func (p *PinataApi) Pinned(hash string) error { + // Initialize a Url instance. + url := Url{} + + // Check if the provided hash is a valid CID. + if ValidateCid(hash) { + // Set the URL to search by IPFS hash. + url.Set(tp.BASE_URL + tp.PINNEDDATA + "/?status=pinned&hashContains=" + hash) + } else { + // Set the URL to search by metadata name. + url.Set(tp.BASE_URL + tp.PINNEDDATA + "/?status=pinned&metadata[name]=" + hash) + log.Debug("Url formed to get meta: ", url.url) + } + + // Create a new request using the PinataApi request object. + req, err := p.request.Get(url.Get()) + if err != nil { + return err + } + + // Send the request and get the response. + resp, err := p.client.Do(req) + if err != nil { + log.Debug("Ipfs-api: test: invalid response: %v", err) + return err + } + defer resp.Body.Close() + + // Read the response body. + b, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + + // Save the response body and status code to the PinataApi instance. + p.SaveResp(b) + p.SetRespCode(resp.StatusCode) + + return nil +} + +func (p *PinataApi) Pin(path string) error { + // Return response as a struct. Clone output logic to + // response struct + if _, err := os.Stat(path); os.IsNotExist(err) { + log.Error("pin: provided path doesn't exist") + return err + } + err := p.walker.Walk(path) + if err != nil { + return err + } + c, r, err := p.createBody() + if err != nil { + return err + } + req, err := p.request.Post(tp.BASE_URL+tp.PINFILE, &r) + if err != nil { + return err + } + + req.Header.Add("Content-Type", c) + if p.dump { + rd, err := httputil.DumpRequest(req, true) + if err != nil { + return err + } + f, err := os.Create("./dump.log") + if err != nil { + return err + } + f.Write(rd) + f.Close() + } + + resp, err := p.client.Do(req) + if err != nil { + log.Debug("Ipfs-api: pin: invalid response: %v", err) + return err + } + defer resp.Body.Close() + + b, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + p.SaveResp(b) + p.SetRespCode(resp.StatusCode) + return nil +} + +func (p *PinataApi) createBody() (string, io.Reader, error) { + + pr, pw := io.Pipe() + bw := multipart.NewWriter(pw) + + go func() { + + bw.WriteField(tp.PINATAOPTS, p.GetOpts()) + + if p.CheckMeta() { + log.Debug("meta available: will set %v", p.GetMeta()) + bw.WriteField(tp.PINATAMETA, p.GetMeta()) + } + + for _, p := range p.walker.bulk { + f, err := os.Open(p.Abs()) + if err != nil { + log.Error("failed to open %v", p.Abs()) + os.Exit(1) // return error + } + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", + fmt.Sprintf(`form-data; name="file"; filename="%s"`, p.Path())) + h.Set("Content-Type", "application/octet-stream") + + c, err := bw.CreatePart(h) + if err != nil { + log.Error("failed to create part") + os.Exit(1) + } + d, err := io.Copy(c, f) + if err != nil { + log.Error("failed to copy content") + os.Exit(1) + } else { + log.Debug("uploaded file %v: bytes : %v", p.Path(), d) + } + f.Close() + + } + + bw.Close() + pw.Close() + + }() + return bw.FormDataContentType(), pr, nil + +} + +func (p *PinataApi) SetOpts(c int8, b bool) error { + if c >= 0 && c < 2 { + p.opts.cidVersion = c + } else { + return errors.New("CID version should be 0 or 1") + } + + p.opts.wrapWithDirectory = b + + return nil +} + +func (p *PinataApi) SetOptsDefault() { + p.SetOpts(1, false) +} + +func (p *PinataApi) GetOpts() string { + o := PinataOptionsJSON{WrapWithDirectory: p.opts.wrapWithDirectory, CidVersion: p.opts.cidVersion} + j, err := json.Marshal(o) + if err != nil { + log.Error("failed to get options") + } + return string(j) +} + +func (p *PinataApi) GetMeta() string { + m := PinataMetadataJSON{Name: p.meta.name, KeyValues: p.meta.keyValues} + j, err := json.Marshal(m) + if err != nil { + log.Error("failed to get options") + } + return string(j) +} + +// SetMeta updates the metadata associated with an IPFS hash in Pinata. +// +// h: The IPFS hash of the content to update the metadata for. +// n: The new name to be associated with the IPFS hash. +// +// Returns an error if the update operation fails. +func (p *PinataApi) SetMeta(h string, n string) error { + r := PinataPutMetadataJSON{ + IpfsHash: h, + Name: n, + KeyValues: p.meta.keyValues, + } + var buf bytes.Buffer + + err := json.NewEncoder(&buf).Encode(r) + if err != nil { + log.Error("SetMeta: %s", err) + return err + } + + req, err := p.request.Put(tp.BASE_URL+tp.METADATA_URL, &buf) + if err != nil { + return err + } + req.Header.Add("Content-Type", "application/json") + + rd, err := httputil.DumpRequest(req, true) + if err != nil { + return err + } + f, err := os.Create("./dump.log") + if err != nil { + return err + } + f.Write(rd) + f.Close() + + if resp, err := p.client.Do(req); err != nil { + return err + } else { + r, _ := io.ReadAll(resp.Body) + fmt.Println(string(r)) + } + + return nil + +} +func (p *PinataApi) SetMetaData(m map[string]string) { + p.meta.keyValues = m +} +func (p *PinataApi) SetMetaName(n string) error { + if len(n) != 0 && len(n) <= 245 { + err := p.Pinned(n) + if err != nil { + return err + } + s := PinnedResponse{} + if err := json.Unmarshal(p.resp, &s); err != nil { + return err + } + if s.Count != 0 { + log.Error("SetMetaName: name exist") + return errors.New("name already exist") + } + log.Debug("setting meta name to %s", n) + p.meta.name = n + return nil + } else { + return errors.New("provided name should be from 1 to 250 chars long") + } + +} +func (p *PinataApi) CheckMeta() bool { + if len(p.meta.name) > 1 || len(p.meta.keyValues) > 1 { + return true + } else { + return false + } +} + +func (p *PinataApi) Dump() { + p.dump = true +} + +func (p *PinataApi) SetRespCode(code int) { + p.respCode = code +} +func (p *PinataApi) SaveResp(resp []byte) { + p.resp = resp +} +func (p *PinataApi) OutputPinJsonObj() (PinResponseJSON, error) { + s := PinResponseJSON{} + if err := json.Unmarshal(p.resp, &s); err != nil { + log.Error("failed to unmarshal in json") + return PinResponseJSON{}, err + } + return s, nil + +} + +func (p *PinataApi) OutputPinnedJsonObj() (PinnedResponse, error) { + s := PinnedResponse{} + if err := json.Unmarshal(p.resp, &s); err != nil { + log.Error("failed to unmarshal in json") + return PinnedResponse{}, err + } + return s, nil +} + +func (p *PinataApi) OutputPinJson() error { + s := PinResponseJSON{} + if err := json.Unmarshal(p.resp, &s); err != nil { + log.Error("failed to unmarshal in json") + return err + } + s2 := PinResponseJSONProd(s) + j, err := json.Marshal(s2) + if err != nil { + log.Error("failed to marshal") + return err + } + fmt.Println(string(j)) + return nil +} +func (p *PinataApi) OutputPinnedJson() error { + if p.respCode != http.StatusOK { + return errors.New("something failed") + } + s := PinnedResponse{} + if err := json.Unmarshal(p.resp, &s); err != nil { + return err + } + j, err := json.Marshal(s) + if err != nil { + return err + } + fmt.Println(string(j)) + return nil +} + +func (p *PinataApi) OutputTestJson() error { + if p.respCode != http.StatusOK { + return errors.New("something failed") + } + s := TestResponse{} + if err := json.Unmarshal(p.resp, &s); err != nil { + return err + } + j, err := json.Marshal(s) + if err != nil { + return err + } + fmt.Println(string(j)) + return nil +} +func (p *PinataApi) OutputUnpinJson() error { + if p.respCode != http.StatusOK { + return fmt.Errorf("server returned: %v", p.respCode) + } else { + s := UnpinResponse{Success: true, Hash: p.data, Time: time.Now()} + j, err := json.Marshal(s) + if err != nil { + log.Error("failed to marshal") + return err + } + fmt.Println(string(j)) + } + + return nil +} + +func (u *Url) Set(url string) { + u.url = url +} + +func (u *Url) Get() string { + return u.url +} + +func (p *PinataApi) SetData(data string) { + p.data = data +} diff --git a/ipfs-api/pkg/pinatav2/pinatav2_pinata_api_test.go b/ipfs-api/pkg/pinatav2/pinatav2_pinata_api_test.go new file mode 100644 index 00000000..cb493154 --- /dev/null +++ b/ipfs-api/pkg/pinatav2/pinatav2_pinata_api_test.go @@ -0,0 +1,103 @@ +package pinatav2 + +import ( + "testing" +) + +func TestPinataApiSetOptsMax(t *testing.T) { + p := PinataApi{} + err := p.SetOpts(127, false) + if err == nil { + t.Errorf("want error") + } + +} +func TestPinataApiSetOptsMin(t *testing.T) { + p := PinataApi{} + err := p.SetOpts(-127, false) + if err == nil { + t.Errorf("want error") + } + +} +func TestPinataApiSetOptsOne(t *testing.T) { + p := PinataApi{} + err := p.SetOpts(1, false) + if err != nil { + t.Errorf("want error %v", err) + } + +} +func TestPinataApiSetOptZero(t *testing.T) { + p := PinataApi{} + err := p.SetOpts(0, false) + if err != nil { + t.Errorf("want error") + } + +} + +func TestPinataApiSetMetaNameMax(t *testing.T) { + p := PinataApi{} + err := p.SetMetaName("gcwcorzcwupzndmvvawifxtmpvjuaiwbmnuiaqoesqajfucqwpcnrdgkyflcgdrmlquzwcszigxdqpzrttppxwyoxqrtdabllqsfwoionofffkmdtljeyiilrfrvnidmqbwitjklbcfjuutawvcabzdfsqkjmanzaxyvmribarjibidqudyawqpeharlpoaoaxrknvrvhtihsbsymabunbnbseqwnbyklygixxbuwdjzytsjubrkgrgwda") + if err == nil { + t.Errorf("want not nil got nil") + } +} + +func TestPinataApiSetMetaNameMin(t *testing.T) { + p := PinataApi{} + err := p.SetMetaName("") + if err == nil { + t.Errorf("want error: %v", err) + } +} + +func TestPinataApiCheckMetaEmpty(t *testing.T) { + p := PinataApi{} + b := p.CheckMeta() + if b { + t.Errorf("Should be false") + } +} + +func TestPinataApiCheckMetaFull(t *testing.T) { + p := PinataApi{} + p.SetMetaName("Full") + b := p.CheckMeta() + if !b { + t.Errorf("Should be true") + } +} + +func TestPinataApiValidateCidNotValid(t *testing.T) { + str := "./root/test/somefile.txt" + b := ValidateCid(str) + if b { + t.Errorf("String is not valid, want false") + } +} + +func TestPinataApiValidateCidEmpty(t *testing.T) { + str := "" + b := ValidateCid(str) + if b { + t.Errorf("String is not valid, want false") + } +} + +func TestPinataApiValidateCidValidv1(t *testing.T) { + str := "bafybeibkjmxftowv4lki46nad4arescoqc7kdzfnjkqux257i4jonk44w4" + b := ValidateCid(str) + if !b { + t.Errorf("String is not valid, want false") + } +} + +func TestPinataApiValidateCidValidv0(t *testing.T) { + str := "QmRBkKi1PnthqaBaiZnXML6fH6PNqCFdpcBxGYXoUQfp6z" + b := ValidateCid(str) + if !b { + t.Errorf("String is not valid, want false") + } +} From 6f24ed6eb1ac417f227af730225cc971a8c8da1d Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 18:55:26 +0200 Subject: [PATCH 25/38] Rename pinata2 -> pinatav2 --- ipfs-api/pkg/pinatav2/pinata2_dirwalker.go | 55 -- ipfs-api/pkg/pinatav2/pinata2_efi.go | 14 - ipfs-api/pkg/pinatav2/pinata2_header.go | 12 - ipfs-api/pkg/pinatav2/pinata2_pinata_api.go | 505 ------------------ .../pkg/pinatav2/pinata2_pinata_api_test.go | 103 ---- 5 files changed, 689 deletions(-) delete mode 100644 ipfs-api/pkg/pinatav2/pinata2_dirwalker.go delete mode 100644 ipfs-api/pkg/pinatav2/pinata2_efi.go delete mode 100644 ipfs-api/pkg/pinatav2/pinata2_header.go delete mode 100644 ipfs-api/pkg/pinatav2/pinata2_pinata_api.go delete mode 100644 ipfs-api/pkg/pinatav2/pinata2_pinata_api_test.go diff --git a/ipfs-api/pkg/pinatav2/pinata2_dirwalker.go b/ipfs-api/pkg/pinatav2/pinata2_dirwalker.go deleted file mode 100644 index e9d93182..00000000 --- a/ipfs-api/pkg/pinatav2/pinata2_dirwalker.go +++ /dev/null @@ -1,55 +0,0 @@ -package pinatav2 - -import ( - "io/fs" - "os" - "path/filepath" - "sync" - - log "github.com/kiracore/tools/ipfs-api/pkg/ipfslog" -) - -func (w *Walker) Walk(rootDir string) error { - ap, err := filepath.Abs(rootDir) - base := filepath.Base(ap) - if err != nil { - return err - } - - var wg sync.WaitGroup - var efi = []ExtendedFileInfo{} - - wg.Add(1) - go func() { - - err := filepath.Walk(ap, func(path string, info fs.FileInfo, err error) error { - if err != nil { - os.Exit(1) - return err - } - if !info.IsDir() { - rel, err := filepath.Rel(ap, path) - - if err != nil { - log.Error("walker: can't get relative path for %v. err: %v", path, err) - os.Exit(1) - } - fn := filepath.Clean(base + "/" + rel) - e := ExtendedFileInfo{} - efi = append(efi, e.Set(info, fn, path)) - } - - return nil - - }) - if err != nil { - os.Exit(1) - return - } - wg.Done() - }() - wg.Wait() - w.bulk = efi - return nil - -} diff --git a/ipfs-api/pkg/pinatav2/pinata2_efi.go b/ipfs-api/pkg/pinatav2/pinata2_efi.go deleted file mode 100644 index 9843fe6e..00000000 --- a/ipfs-api/pkg/pinatav2/pinata2_efi.go +++ /dev/null @@ -1,14 +0,0 @@ -package pinatav2 - -import "io/fs" - -func (e ExtendedFileInfo) Set(fs fs.FileInfo, p string, ap string) ExtendedFileInfo { - return ExtendedFileInfo{info: fs, path: p, absoultePath: ap} -} -func (e ExtendedFileInfo) Abs() string { - return e.absoultePath -} - -func (e ExtendedFileInfo) Path() string { - return e.path -} diff --git a/ipfs-api/pkg/pinatav2/pinata2_header.go b/ipfs-api/pkg/pinatav2/pinata2_header.go deleted file mode 100644 index 340f9538..00000000 --- a/ipfs-api/pkg/pinatav2/pinata2_header.go +++ /dev/null @@ -1,12 +0,0 @@ -package pinatav2 - -func (h *Header) Init() { - if h.keys.jwt != "" { - - h.header.Add("Authorization", "Bearer "+h.keys.jwt) - - } else { - h.header.Add("pinata_api_key", h.keys.api_key) - h.header.Add("pinata_secret_api_key", h.keys.api_secret) - } -} diff --git a/ipfs-api/pkg/pinatav2/pinata2_pinata_api.go b/ipfs-api/pkg/pinatav2/pinata2_pinata_api.go deleted file mode 100644 index 01f0b8af..00000000 --- a/ipfs-api/pkg/pinatav2/pinata2_pinata_api.go +++ /dev/null @@ -1,505 +0,0 @@ -package pinatav2 - -import ( - "bytes" - "crypto/tls" - "encoding/json" - "errors" - "fmt" - "io" - "mime/multipart" - "os" - - "net/http" - "net/http/httputil" - "net/textproto" - "time" - - cid "github.com/ipfs/go-cid" - log "github.com/kiracore/tools/ipfs-api/pkg/ipfslog" - tp "github.com/kiracore/tools/ipfs-api/types" - "golang.org/x/net/http2" -) - -// Setting new client for an Api -func ValidateCid(hash string) bool { - _, err := cid.Decode(hash) - if err != nil { - return false - } - return true -} - -func (p *PinataApi) newClient() { - - // Client params to be adjusted ... - tr := &http.Transport{ - MaxIdleConnsPerHost: 100, - MaxIdleConns: 100, - IdleConnTimeout: 90 * time.Second, - ExpectContinueTimeout: 5 * time.Second, - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, - }, - } - http2.ConfigureTransport(tr) - p.client = http.Client{ - Timeout: 100 * time.Second, - Transport: tr, - } - -} - -// Adding keys to request header -func (p *PinataApi) SetKeys(keys Keys) { - p.request.header.keys = keys - p.newClient() - p.SetOptsDefault() -} - -// Sending GET request to check authorization -func (p *PinataApi) Test() error { - req, err := p.request.Get(tp.BASE_URL + tp.TESTAUTH) - if err != nil { - log.Debug("Ipfs-api: test: invalid request: %v", err) - return err - } - - resp, err := p.client.Do(req) - if err != nil { - log.Debug("Ipfs-api: test: invalid response: %v", err) - return err - } - defer resp.Body.Close() - - b, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - p.SaveResp(b) - p.SetRespCode(resp.StatusCode) - - return nil -} - -// Unpin removes the content from the Pinata API by its IPFS hash or metadata name. -// This function returns an error if the unpinning operation fails. -// -// hash: A string containing either the IPFS hash or the metadata name of the content. -// -// Returns an error if any operation fails. -func (p *PinataApi) Unpin(hash string) error { - // Initialize a Url instance. - url := Url{} - - // Check if the provided hash is a valid CID. - if ValidateCid(hash) { - // Set the URL for unpinning by IPFS hash. - url.Set(tp.BASE_URL + tp.UNPIN + "/" + hash) - log.Debug("unpin: url: %v", url.Get()) - } else { - // Retrieve the pinned content by metadata name. - err := p.Pinned(hash) - if err != nil { - return err - } - - // Unmarshal the response into a PinnedResponse struct. - s := PinnedResponse{} - if err := json.Unmarshal(p.resp, &s); err != nil { - log.Error("unpin: failed to unmarshal") - return err - } - - // Check the count of pinned content with the given metadata name. - switch s.Count { - case 0: - return fmt.Errorf(`not found. data with name %s doesn't exist`, hash) - case 1: - // Set the URL for unpinning by IPFS hash. - url.Set(tp.BASE_URL + tp.UNPIN + "/" + s.Rows[0].CID) - p.SetData(s.Rows[0].CID) - default: - return errors.New("more than one result returned") - } - } - - // Create a new DELETE request using the PinataApi request object. - req, err := p.request.Del(url.Get()) - if err != nil { - return err - } - - // Send the request and get the response. - resp, err := p.client.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - // Read the response body. - b, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - // Save the response body and status code to the PinataApi instance. - p.SaveResp(b) - p.SetRespCode(resp.StatusCode) - - return nil -} - -// Pinned retrieves the pinned content by hash or metadata name from the Pinata API. -// This function returns an error if the request to the Pinata API fails. -// -// hash: A string containing either the IPFS hash or the metadata name of the content. -// -// Returns an error if any operation fails. -func (p *PinataApi) Pinned(hash string) error { - // Initialize a Url instance. - url := Url{} - - // Check if the provided hash is a valid CID. - if ValidateCid(hash) { - // Set the URL to search by IPFS hash. - url.Set(tp.BASE_URL + tp.PINNEDDATA + "/?status=pinned&hashContains=" + hash) - } else { - // Set the URL to search by metadata name. - url.Set(tp.BASE_URL + tp.PINNEDDATA + "/?status=pinned&metadata[name]=" + hash) - log.Debug("Url formed to get meta: ", url.url) - } - - // Create a new request using the PinataApi request object. - req, err := p.request.Get(url.Get()) - if err != nil { - return err - } - - // Send the request and get the response. - resp, err := p.client.Do(req) - if err != nil { - log.Debug("Ipfs-api: test: invalid response: %v", err) - return err - } - defer resp.Body.Close() - - // Read the response body. - b, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - // Save the response body and status code to the PinataApi instance. - p.SaveResp(b) - p.SetRespCode(resp.StatusCode) - - return nil -} - -func (p *PinataApi) Pin(path string) error { - // Return response as a struct. Clone output logic to - // response struct - if _, err := os.Stat(path); os.IsNotExist(err) { - log.Error("pin: provided path doesn't exist") - return err - } - err := p.walker.Walk(path) - if err != nil { - return err - } - c, r, err := p.createBody() - if err != nil { - return err - } - req, err := p.request.Post(tp.BASE_URL+tp.PINFILE, &r) - if err != nil { - return err - } - - req.Header.Add("Content-Type", c) - if p.dump { - rd, err := httputil.DumpRequest(req, true) - if err != nil { - return err - } - f, err := os.Create("./dump.log") - if err != nil { - return err - } - f.Write(rd) - f.Close() - } - - resp, err := p.client.Do(req) - if err != nil { - log.Debug("Ipfs-api: pin: invalid response: %v", err) - return err - } - defer resp.Body.Close() - - b, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - p.SaveResp(b) - p.SetRespCode(resp.StatusCode) - return nil -} - -func (p *PinataApi) createBody() (string, io.Reader, error) { - - pr, pw := io.Pipe() - bw := multipart.NewWriter(pw) - - go func() { - - bw.WriteField(tp.PINATAOPTS, p.GetOpts()) - - if p.CheckMeta() { - log.Debug("meta available: will set %v", p.GetMeta()) - bw.WriteField(tp.PINATAMETA, p.GetMeta()) - } - - for _, p := range p.walker.bulk { - f, err := os.Open(p.Abs()) - if err != nil { - log.Error("failed to open %v", p.Abs()) - os.Exit(1) // return error - } - h := make(textproto.MIMEHeader) - h.Set("Content-Disposition", - fmt.Sprintf(`form-data; name="file"; filename="%s"`, p.Path())) - h.Set("Content-Type", "application/octet-stream") - - c, err := bw.CreatePart(h) - if err != nil { - log.Error("failed to create part") - os.Exit(1) - } - d, err := io.Copy(c, f) - if err != nil { - log.Error("failed to copy content") - os.Exit(1) - } else { - log.Debug("uploaded file %v: bytes : %v", p.Path(), d) - } - f.Close() - - } - - bw.Close() - pw.Close() - - }() - return bw.FormDataContentType(), pr, nil - -} - -func (p *PinataApi) SetOpts(c int8, b bool) error { - if c >= 0 && c < 2 { - p.opts.cidVersion = c - } else { - return errors.New("CID version should be 0 or 1") - } - - p.opts.wrapWithDirectory = b - - return nil -} - -func (p *PinataApi) SetOptsDefault() { - p.SetOpts(1, false) -} - -func (p *PinataApi) GetOpts() string { - o := PinataOptionsJSON{WrapWithDirectory: p.opts.wrapWithDirectory, CidVersion: p.opts.cidVersion} - j, err := json.Marshal(o) - if err != nil { - log.Error("failed to get options") - } - return string(j) -} - -func (p *PinataApi) GetMeta() string { - m := PinataMetadataJSON{Name: p.meta.name, KeyValues: p.meta.keyValues} - j, err := json.Marshal(m) - if err != nil { - log.Error("failed to get options") - } - return string(j) -} - -// SetMeta updates the metadata associated with an IPFS hash in Pinata. -// -// h: The IPFS hash of the content to update the metadata for. -// n: The new name to be associated with the IPFS hash. -// -// Returns an error if the update operation fails. -func (p *PinataApi) SetMeta(h string, n string) error { - r := PinataPutMetadataJSON{ - IpfsHash: h, - Name: n, - KeyValues: p.meta.keyValues, - } - var buf bytes.Buffer - - err := json.NewEncoder(&buf).Encode(r) - if err != nil { - log.Error("SetMeta: %s", err) - return err - } - - req, err := p.request.Put(tp.BASE_URL+tp.METADATA_URL, &buf) - if err != nil { - return err - } - req.Header.Add("Content-Type", "application/json") - - rd, err := httputil.DumpRequest(req, true) - if err != nil { - return err - } - f, err := os.Create("./dump.log") - if err != nil { - return err - } - f.Write(rd) - f.Close() - - if resp, err := p.client.Do(req); err != nil { - return err - } else { - r, _ := io.ReadAll(resp.Body) - fmt.Println(string(r)) - } - - return nil - -} -func (p *PinataApi) SetMetaData(m map[string]string) { - p.meta.keyValues = m -} -func (p *PinataApi) SetMetaName(n string) error { - if len(n) != 0 && len(n) <= 245 { - err := p.Pinned(n) - if err != nil { - return err - } - s := PinnedResponse{} - if err := json.Unmarshal(p.resp, &s); err != nil { - return err - } - if s.Count != 0 { - log.Error("SetMetaName: name exist") - return errors.New("name already exist") - } - log.Debug("setting meta name to %s", n) - p.meta.name = n - return nil - } else { - return errors.New("provided name should be from 1 to 250 chars long") - } - -} -func (p *PinataApi) CheckMeta() bool { - if len(p.meta.name) > 1 || len(p.meta.keyValues) > 1 { - return true - } else { - return false - } -} - -func (p *PinataApi) Dump() { - p.dump = true -} - -func (p *PinataApi) SetRespCode(code int) { - p.respCode = code -} -func (p *PinataApi) SaveResp(resp []byte) { - p.resp = resp -} -func (p *PinataApi) OutputPinJsonObj() (PinResponseJSON, error) { - s := PinResponseJSON{} - if err := json.Unmarshal(p.resp, &s); err != nil { - log.Error("failed to unmarshal in json") - return PinResponseJSON{}, err - } - return s, nil - -} - -func (p *PinataApi) OutputPinJson() error { - s := PinResponseJSON{} - if err := json.Unmarshal(p.resp, &s); err != nil { - log.Error("failed to unmarshal in json") - return err - } - s2 := PinResponseJSONProd(s) - j, err := json.Marshal(s2) - if err != nil { - log.Error("failed to marshal") - return err - } - fmt.Println(string(j)) - return nil -} -func (p *PinataApi) OutputPinnedJson() error { - if p.respCode != http.StatusOK { - return errors.New("something failed") - } - s := PinnedResponse{} - if err := json.Unmarshal(p.resp, &s); err != nil { - return err - } - j, err := json.Marshal(s) - if err != nil { - return err - } - fmt.Println(string(j)) - return nil -} - -func (p *PinataApi) OutputTestJson() error { - if p.respCode != http.StatusOK { - return errors.New("something failed") - } - s := TestResponse{} - if err := json.Unmarshal(p.resp, &s); err != nil { - return err - } - j, err := json.Marshal(s) - if err != nil { - return err - } - fmt.Println(string(j)) - return nil -} -func (p *PinataApi) OutputUnpinJson() error { - if p.respCode != http.StatusOK { - return fmt.Errorf("server returned: %v", p.respCode) - } else { - s := UnpinResponse{Success: true, Hash: p.data, Time: time.Now()} - j, err := json.Marshal(s) - if err != nil { - log.Error("failed to marshal") - return err - } - fmt.Println(string(j)) - } - - return nil -} - -func (u *Url) Set(url string) { - u.url = url -} - -func (u *Url) Get() string { - return u.url -} - -func (p *PinataApi) SetData(data string) { - p.data = data -} diff --git a/ipfs-api/pkg/pinatav2/pinata2_pinata_api_test.go b/ipfs-api/pkg/pinatav2/pinata2_pinata_api_test.go deleted file mode 100644 index cb493154..00000000 --- a/ipfs-api/pkg/pinatav2/pinata2_pinata_api_test.go +++ /dev/null @@ -1,103 +0,0 @@ -package pinatav2 - -import ( - "testing" -) - -func TestPinataApiSetOptsMax(t *testing.T) { - p := PinataApi{} - err := p.SetOpts(127, false) - if err == nil { - t.Errorf("want error") - } - -} -func TestPinataApiSetOptsMin(t *testing.T) { - p := PinataApi{} - err := p.SetOpts(-127, false) - if err == nil { - t.Errorf("want error") - } - -} -func TestPinataApiSetOptsOne(t *testing.T) { - p := PinataApi{} - err := p.SetOpts(1, false) - if err != nil { - t.Errorf("want error %v", err) - } - -} -func TestPinataApiSetOptZero(t *testing.T) { - p := PinataApi{} - err := p.SetOpts(0, false) - if err != nil { - t.Errorf("want error") - } - -} - -func TestPinataApiSetMetaNameMax(t *testing.T) { - p := PinataApi{} - err := p.SetMetaName("gcwcorzcwupzndmvvawifxtmpvjuaiwbmnuiaqoesqajfucqwpcnrdgkyflcgdrmlquzwcszigxdqpzrttppxwyoxqrtdabllqsfwoionofffkmdtljeyiilrfrvnidmqbwitjklbcfjuutawvcabzdfsqkjmanzaxyvmribarjibidqudyawqpeharlpoaoaxrknvrvhtihsbsymabunbnbseqwnbyklygixxbuwdjzytsjubrkgrgwda") - if err == nil { - t.Errorf("want not nil got nil") - } -} - -func TestPinataApiSetMetaNameMin(t *testing.T) { - p := PinataApi{} - err := p.SetMetaName("") - if err == nil { - t.Errorf("want error: %v", err) - } -} - -func TestPinataApiCheckMetaEmpty(t *testing.T) { - p := PinataApi{} - b := p.CheckMeta() - if b { - t.Errorf("Should be false") - } -} - -func TestPinataApiCheckMetaFull(t *testing.T) { - p := PinataApi{} - p.SetMetaName("Full") - b := p.CheckMeta() - if !b { - t.Errorf("Should be true") - } -} - -func TestPinataApiValidateCidNotValid(t *testing.T) { - str := "./root/test/somefile.txt" - b := ValidateCid(str) - if b { - t.Errorf("String is not valid, want false") - } -} - -func TestPinataApiValidateCidEmpty(t *testing.T) { - str := "" - b := ValidateCid(str) - if b { - t.Errorf("String is not valid, want false") - } -} - -func TestPinataApiValidateCidValidv1(t *testing.T) { - str := "bafybeibkjmxftowv4lki46nad4arescoqc7kdzfnjkqux257i4jonk44w4" - b := ValidateCid(str) - if !b { - t.Errorf("String is not valid, want false") - } -} - -func TestPinataApiValidateCidValidv0(t *testing.T) { - str := "QmRBkKi1PnthqaBaiZnXML6fH6PNqCFdpcBxGYXoUQfp6z" - b := ValidateCid(str) - if !b { - t.Errorf("String is not valid, want false") - } -} From ca8e9df99db8a4f0f7206ee5ebb1e6586d70a911 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 19:14:26 +0200 Subject: [PATCH 26/38] Change os.Exit(1) -> return err --- ipfs-api/pkg/cli/pin.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ipfs-api/pkg/cli/pin.go b/ipfs-api/pkg/cli/pin.go index 7b01e5cb..04c38ad9 100644 --- a/ipfs-api/pkg/cli/pin.go +++ b/ipfs-api/pkg/cli/pin.go @@ -2,7 +2,6 @@ package cli import ( "errors" - "os" "github.com/ipld/go-ipld-prime/datamodel" log "github.com/kiracore/tools/ipfs-api/pkg/ipfslog" @@ -113,7 +112,7 @@ func pinAndOutputResult(p *pnt.PinataApi, content string) error { } if err := p.OutputPinJson(); err != nil { log.Error("failed to print results: %v", err) - os.Exit(1) + return err } return nil } From ab0c8e08442697cc9f3ff784ef3c29a653c900b6 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 19:24:43 +0200 Subject: [PATCH 27/38] Add tests Add pinnedMeta and pinnedHash test. Change output for clearing to /dev/null --- ipfs-api/scripts/test.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 99294a79..82df0ea0 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -72,6 +72,12 @@ deleteByHashTest(){ exit 1 fi } +pinnedMeta(){ + go run $MAIN_DIR pinned meta --key="$PINATA_API_JWT_TEST" | jq +} +pinnedHash(){ + go run $MAIN_DIR pinned bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4 --key="$PINATA_API_JWT_TEST" | jq +} pinWithMetaTest(){ local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" @@ -153,24 +159,21 @@ deleteByMetaForceTest(){ exit 1 fi } - +set -x bu echoInfo "Clearing failed results if any..." -go run $MAIN_DIR delete bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4 --key="$PINATA_API_JWT_TEST" --verbose ||: -go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" --verbose ||: +go run $MAIN_DIR delete bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4 --key="$PINATA_API_JWT_TEST" --verbose &> /dev/null ||: +go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" --verbose &> /dev/null ||: bu echoInfo "Running tests" -TESTS=(dagExportTest pinWithMetaTest deleteByMetaTest pinTest deleteByHashTest pinWithMetaTest pinWithMetaOverwriteTest deleteByMetaOverwriteTest pinWithMetaTest pinWithMetaForceTest deleteByMetaForceTest) +TESTS=(dagExportTest pinWithMetaTest pinnedMeta deleteByMetaTest pinTest pinnedHash deleteByHashTest pinWithMetaTest pinnedMeta pinWithMetaOverwriteTest pinnedMeta deleteByMetaOverwriteTest pinWithMetaTest pinnedMeta pinWithMetaForceTest pinnedMeta deleteByMetaForceTest) for TEST in "${TESTS[@]}"; do $TEST - sleep 3 done bu echoInfo "All tests finished. Cleaning up the environment..." -set -x - rm -rf $ENTRY_DIR || bu echoError "Failed to clean up an the environment" bu echoInfo "All done..." \ No newline at end of file From b3ba90b7d2657ae73d8eb114a598e411ffd71b85 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 20:31:14 +0200 Subject: [PATCH 28/38] Add set -x inside loop --- ipfs-api/scripts/test.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 82df0ea0..2868469e 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -166,12 +166,15 @@ go run $MAIN_DIR delete bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexku go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" --verbose &> /dev/null ||: bu echoInfo "Running tests" - +set +x TESTS=(dagExportTest pinWithMetaTest pinnedMeta deleteByMetaTest pinTest pinnedHash deleteByHashTest pinWithMetaTest pinnedMeta pinWithMetaOverwriteTest pinnedMeta deleteByMetaOverwriteTest pinWithMetaTest pinnedMeta pinWithMetaForceTest pinnedMeta deleteByMetaForceTest) for TEST in "${TESTS[@]}"; do + set -x $TEST + set +x done +set -x bu echoInfo "All tests finished. Cleaning up the environment..." rm -rf $ENTRY_DIR || bu echoError "Failed to clean up an the environment" From d26fd7a94c86900c1b9aca4e4985781d5c504680 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 20:33:18 +0200 Subject: [PATCH 29/38] Add explicit debug messages --- ipfs-api/pkg/cli/unpin.go | 12 +++++++++--- ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go | 11 ++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ipfs-api/pkg/cli/unpin.go b/ipfs-api/pkg/cli/unpin.go index 47c3a71a..7c289fbd 100644 --- a/ipfs-api/pkg/cli/unpin.go +++ b/ipfs-api/pkg/cli/unpin.go @@ -25,7 +25,12 @@ var unpinCommand = &cobra.Command{ // // Returns an error if the unpin operation fails or the arguments are empty. func unpin(cmd *cobra.Command, args []string) error { + log.Debug("Call unpin ...") + hash := args[0] + log.Debug("Args: ", args) + log.Debug("Hash: ", hash) + // Check if the arguments are empty. if len(args) == 0 { log.Error("unpin: empty arg") @@ -40,19 +45,20 @@ func unpin(cmd *cobra.Command, args []string) error { } // Set up the PinataApi instance with the obtained keys and the provided argument. + pin := pnt.PinataApi{} + log.Debug("Created PinataApi") pin.SetKeys(keys) - pin.SetData(hash) - pin.Pinned(hash) + log.Debug("Struct after pinned call %#v", pin) // Unmarshal the response into a PinnedResponse struct. pinned, err := pin.OutputPinnedJsonObj() if err != nil { return err } - + log.Debug("Struct of obj pinned %#v", pinned) // Check the count of pinned content with the given metadata name. switch pinned.Count { case 0: diff --git a/ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go b/ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go index f1d16dfa..ff08619e 100644 --- a/ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go +++ b/ipfs-api/pkg/pinatav2/pinatav2_pinata_api.go @@ -89,11 +89,14 @@ func (p *PinataApi) Test() error { // // Returns an error if any operation fails. func (p *PinataApi) Unpin(hash string) error { + log.Debug("Call Unpin ...") + log.Debug("Received arg:", hash) // Initialize a Url instance. url := Url{} // Set the URL for unpinning by IPFS hash. url.Set(tp.BASE_URL + tp.UNPIN + "/" + hash) + log.Debug("Formed URL: ", url.Get()) // Create a new DELETE request using the PinataApi request object. req, err := p.request.Del(url.Get()) @@ -115,7 +118,9 @@ func (p *PinataApi) Unpin(hash string) error { } // Save the response body and status code to the PinataApi instance. + log.Debug("Response string([]byte): ", b) p.SaveResp(b) + log.Debug("Response stat code: ", resp.StatusCode) p.SetRespCode(resp.StatusCode) return nil @@ -128,6 +133,7 @@ func (p *PinataApi) Unpin(hash string) error { // // Returns an error if any operation fails. func (p *PinataApi) Pinned(hash string) error { + log.Debug("Call pinned ...") // Initialize a Url instance. url := Url{} @@ -135,10 +141,11 @@ func (p *PinataApi) Pinned(hash string) error { if ValidateCid(hash) { // Set the URL to search by IPFS hash. url.Set(tp.BASE_URL + tp.PINNEDDATA + "/?status=pinned&hashContains=" + hash) + log.Debug("ValidateCId return true. Url: ", url.Get()) } else { // Set the URL to search by metadata name. url.Set(tp.BASE_URL + tp.PINNEDDATA + "/?status=pinned&metadata[name]=" + hash) - log.Debug("Url formed to get meta: ", url.url) + log.Debug("Url formed to get meta: ", url.Get()) } // Create a new request using the PinataApi request object. @@ -162,7 +169,9 @@ func (p *PinataApi) Pinned(hash string) error { } // Save the response body and status code to the PinataApi instance. + log.Debug("Response string([]byte): ", string(b)) p.SaveResp(b) + log.Debug("Response stat code: ", resp.StatusCode) p.SetRespCode(resp.StatusCode) return nil From 03f3374c23c4cdc1a2dc2df1b48a3a64a84e79f2 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 22:15:27 +0200 Subject: [PATCH 30/38] Update header for get requests Add random pick of users agents, add some fields to imitate user requests --- ipfs-api/pkg/pinatav2/pinatav2_header.go | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ipfs-api/pkg/pinatav2/pinatav2_header.go b/ipfs-api/pkg/pinatav2/pinatav2_header.go index 340f9538..5e087055 100644 --- a/ipfs-api/pkg/pinatav2/pinatav2_header.go +++ b/ipfs-api/pkg/pinatav2/pinatav2_header.go @@ -1,6 +1,35 @@ package pinatav2 +import ( + "math/rand" + "time" +) + +// List of common browser user agents +var userAgentList = []string{ + // Windows Browsers + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0", + "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134", + + // Linux Browsers + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1", + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36", + + // macOS Browsers + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0", +} + +func getRandomUserAgent() string { + rand.Seed(time.Now().UnixNano()) + return userAgentList[rand.Intn(len(userAgentList))] +} + func (h *Header) Init() { + if h.keys.jwt != "" { h.header.Add("Authorization", "Bearer "+h.keys.jwt) @@ -9,4 +38,10 @@ func (h *Header) Init() { h.header.Add("pinata_api_key", h.keys.api_key) h.header.Add("pinata_secret_api_key", h.keys.api_secret) } + h.header.Set("User-Agent", getRandomUserAgent()) + + // Set other common headers + h.header.Set("Accept", "application/json") + h.header.Set("Accept-Language", "en-US,en;q=0.5") + h.header.Set("Connection", "keep-alive") } From d96fc535a99950b2df24e7b0468408d453b90295 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 22:26:09 +0200 Subject: [PATCH 31/38] Add loop for pinned req Add 5 cycles with random sleep time to improve results on obtaining data from pinata --- ipfs-api/pkg/cli/unpin.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ipfs-api/pkg/cli/unpin.go b/ipfs-api/pkg/cli/unpin.go index 7c289fbd..8f23cb0f 100644 --- a/ipfs-api/pkg/cli/unpin.go +++ b/ipfs-api/pkg/cli/unpin.go @@ -3,6 +3,8 @@ package cli import ( "errors" "fmt" + "math/rand" + "time" log "github.com/kiracore/tools/ipfs-api/pkg/ipfslog" pnt "github.com/kiracore/tools/ipfs-api/pkg/pinatav2" @@ -24,6 +26,12 @@ var unpinCommand = &cobra.Command{ // args: The arguments passed to the unpin command. // // Returns an error if the unpin operation fails or the arguments are empty. +func randomSleep(maxDuration time.Duration) { + rand.Seed(time.Now().UnixNano()) + sleepDuration := time.Duration(rand.Int63n(int64(maxDuration))) + time.Sleep(sleepDuration) +} + func unpin(cmd *cobra.Command, args []string) error { log.Debug("Call unpin ...") @@ -50,7 +58,14 @@ func unpin(cmd *cobra.Command, args []string) error { log.Debug("Created PinataApi") pin.SetKeys(keys) - pin.Pinned(hash) + for i := 0; i == 4; i++ { + pin.Pinned(hash) + if out, err := pin.OutputPinnedJsonObj(); out.Count == 1 && err == nil { + break + } + randomSleep(10 * time.Second) + } + log.Debug("Struct after pinned call %#v", pin) // Unmarshal the response into a PinnedResponse struct. From 35a5ab65ccffd123c286e78d3ad45e9068b61be9 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 23:03:52 +0200 Subject: [PATCH 32/38] Refactor tests --- ipfs-api/scripts/test.sh | 169 +++++++++------------------------------ 1 file changed, 38 insertions(+), 131 deletions(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 2868469e..01b441c6 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -13,6 +13,10 @@ MAIN_DIR=$ROOT_DIR/cmd/ipfs-api/main.go ENTRY_DIR=$ROOT_DIR/test_dir SECOND_DIR=$ENTRY_DIR/test_dir1 +CID="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" +META="meta" +META_FORCE="foobar" + bu echoInfo "Creating directory tree..." mkdir -p $ENTRY_DIR || bu echoError "Failed to create directory $ENTRY_DIR" mkdir -p $SECOND_DIR || bu echoError "Failed to create directory $SECOND_DIR" @@ -31,152 +35,55 @@ for i in {6..10}; do echo "file$i">"$SECOND_DIR/file$i.txt" || bu echoError "Failed to create file$i.txt" done +set -x +runTest() { + local test_cmd="$1" + local test_name="$2" -dagExportTest(){ - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - local GOT=$(go run $MAIN_DIR dag $ENTRY_DIR --export) - - if [[ $WANT == $GOT ]]; - then - echo -en "\033[1G\e[0m\e[36;1m[PASS] dagExportTest\e[0m"; echo - else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] dagExportTest\e[0m"; echo - exit 1 - fi -} - -pinTest(){ - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR --key="$PINATA_API_JWT_TEST" | jq -r .hash) - - if [[ $WANT == $GOT ]]; - then - echo -en "\033[1G\e[0m\e[36;1m[PASS] pinTest\e[0m"; echo - else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] pinTest\e[0m"; echo - exit 1 - fi - -} - -deleteByHashTest(){ - local WANT=true - local GOT=$(go run $MAIN_DIR delete bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4 --key="$PINATA_API_JWT_TEST" | jq .success) - - if [[ $GOT == $WANT ]]; - then - echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByHashTest\e[0m"; echo - else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByHashTest\e[0m"; echo - exit 1 - fi -} -pinnedMeta(){ - go run $MAIN_DIR pinned meta --key="$PINATA_API_JWT_TEST" | jq -} -pinnedHash(){ - go run $MAIN_DIR pinned bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4 --key="$PINATA_API_JWT_TEST" | jq -} - -pinWithMetaTest(){ - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - - local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR meta --key="$PINATA_API_JWT_TEST" | jq -r .hash) - - if [[ $WANT == $GOT ]]; - then - echo -en "\033[1G\e[0m\e[36;1m[PASS] pinWithMetaTest\e[0m"; echo - else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] pinWithMetaTest\e[0m"; echo - exit 1 - fi -} + # Execute the test command and get the exit code + eval "$test_cmd" + exit_code=$? -deleteByMetaTest(){ - local WANT=true - local GOT=$(go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" | jq .success) - if [[ $GOT == $WANT ]]; - then - echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByMetaTest\e[0m"; echo - else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByMetaTest\e[0m"; echo - echo "SUCCESS: $GOT" - exit 1 - fi + # Get the command name + # Check the exit code and print the result + if [ $exit_code -eq 0 ]; then + echo "[PASS] Test $test_name" + else + echo "[FAIL] Test $test_name" + fi } -pinWithMetaForceTest(){ - local WANT="bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4" - local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --key="$PINATA_API_JWT_TEST" | jq -r .hash) - if [[ $WANT == $GOT ]]; - then - echo -en "\033[1G\e[0m\e[36;1m[PASS] pinWithMetaForceTest\e[0m"; echo - else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] pinWithMetaForceTest\e[0m"; echo - exit 1 - fi - -} -pinWithMetaOverwriteTest(){ - local WANT="OK" - local GOT=$(go run $MAIN_DIR pin $ENTRY_DIR foobar --overwrite --key="$PINATA_API_JWT_TEST") - if [[ $WANT == $GOT ]]; - then - echo -en "\033[1G\e[0m\e[36;1m[PASS] pinWithMetaOverwriteTest\e[0m"; echo - else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] pinWithMetaOverwriteTest\e[0m"; echo - exit 1 - fi +# Clearing failed results +bu echoInfo "Clearing failed results if any..." +go run $MAIN_DIR delete bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4 --key="$PINATA_API_JWT_TEST" --verbose &> /dev/null ||: +go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" --verbose &> /dev/null ||: -} +bu echoInfo "Running tests" +runTest "go run $MAIN_DIR dag $ENTRY_DIR" "Dag" -deleteByMetaOverwriteTest(){ - local WANT=true - local GOT=$(go run $MAIN_DIR delete foobar --key="$PINATA_API_JWT_TEST" | jq .success) +runTest "go run $MAIN_DIR pin $ENTRY_DIR --key=$PINATA_API_JWT_TEST" "Pin without metadata" +runTest "go run $MAIN_DIR pinned $CID --key=$PINATA_API_JWT_TEST" "Pinned wiht CID" +runTest "go run $MAIN_DIR delete $CID --key=$PINATA_API_JWT_TEST" "Unpin with CID" - if [[ $GOT == $WANT ]]; - then - echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByMetaOverwriteTest\e[0m"; echo - else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByMetaOverwriteTest\e[0m"; echo - exit 1 - fi -} +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "Pin with metadata" +runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "Pinned with metadata" +runTest "go run $MAIN_DIR delete $META --key=$PINATA_API_JWT_TEST" "Delete with metadata" -deleteByMetaForceTest(){ - local WANT=true - local GOT=$(go run $MAIN_DIR delete foobar --key="$PINATA_API_JWT_TEST" | jq .success) - - if [[ $GOT == $WANT ]]; - then - echo -en "\033[1G\e[0m\e[36;1m[PASS] deleteByMetaOverwriteTest\e[0m"; echo - else - echo -en "\033[1G\e[0m\e[31;1m[FAIL] deleteByMetaOverwriteTest\e[0m"; echo - exit 1 - fi -} -set -x -bu echoInfo "Clearing failed results if any..." +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "Pin with metadata" +runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "Pinned with metadata" +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META_FORCE --key=$PINATA_API_JWT_TEST --force=true" "Forced pin" +runTest "go run $MAIN_DIR delete $META_FORCE --key=$PINATA_API_JWT_TEST" "Delete with metadata" -go run $MAIN_DIR delete bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexkuwg4 --key="$PINATA_API_JWT_TEST" --verbose &> /dev/null ||: -go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" --verbose &> /dev/null ||: +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "Pin with metadata" +runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "Pinned with metadata" +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META_FORCE --key=$PINATA_API_JWT_TEST --overwrite=true" "Overwrite pin" +runTest "go run $MAIN_DIR delete $META_FORCE --key=$PINATA_API_JWT_TEST" "Delete with metadata" -bu echoInfo "Running tests" -set +x -TESTS=(dagExportTest pinWithMetaTest pinnedMeta deleteByMetaTest pinTest pinnedHash deleteByHashTest pinWithMetaTest pinnedMeta pinWithMetaOverwriteTest pinnedMeta deleteByMetaOverwriteTest pinWithMetaTest pinnedMeta pinWithMetaForceTest pinnedMeta deleteByMetaForceTest) -for TEST in "${TESTS[@]}"; do - set -x - $TEST - set +x -done -set -x bu echoInfo "All tests finished. Cleaning up the environment..." - rm -rf $ENTRY_DIR || bu echoError "Failed to clean up an the environment" - bu echoInfo "All done..." \ No newline at end of file From 16d815150ac6ada7f9b9ac8d44f808cb3ad93b75 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 23:41:00 +0200 Subject: [PATCH 33/38] Refactor Discard loop in unpin, update tests --- ipfs-api/pkg/cli/unpin.go | 8 +----- ipfs-api/scripts/test.sh | 53 +++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/ipfs-api/pkg/cli/unpin.go b/ipfs-api/pkg/cli/unpin.go index 8f23cb0f..e60d2a27 100644 --- a/ipfs-api/pkg/cli/unpin.go +++ b/ipfs-api/pkg/cli/unpin.go @@ -58,13 +58,7 @@ func unpin(cmd *cobra.Command, args []string) error { log.Debug("Created PinataApi") pin.SetKeys(keys) - for i := 0; i == 4; i++ { - pin.Pinned(hash) - if out, err := pin.OutputPinnedJsonObj(); out.Count == 1 && err == nil { - break - } - randomSleep(10 * time.Second) - } + pin.Pinned(hash) log.Debug("Struct after pinned call %#v", pin) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index 01b441c6..d9a7a921 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -43,15 +43,15 @@ runTest() { # Execute the test command and get the exit code - eval "$test_cmd" + eval "$test_cmd &> /dev/null ||:" exit_code=$? # Get the command name # Check the exit code and print the result if [ $exit_code -eq 0 ]; then - echo "[PASS] Test $test_name" + echo "[PASS] $test_name" else - echo "[FAIL] Test $test_name" + bu echoError "[FAIL] $test_name" fi } @@ -62,27 +62,32 @@ go run $MAIN_DIR delete bafybeiajf7mv3htewce3zozleukne3vfmagrc7bmk7uzzcsy7gjexku go run $MAIN_DIR delete meta --key="$PINATA_API_JWT_TEST" --verbose &> /dev/null ||: bu echoInfo "Running tests" - -runTest "go run $MAIN_DIR dag $ENTRY_DIR" "Dag" - -runTest "go run $MAIN_DIR pin $ENTRY_DIR --key=$PINATA_API_JWT_TEST" "Pin without metadata" -runTest "go run $MAIN_DIR pinned $CID --key=$PINATA_API_JWT_TEST" "Pinned wiht CID" -runTest "go run $MAIN_DIR delete $CID --key=$PINATA_API_JWT_TEST" "Unpin with CID" - -runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "Pin with metadata" -runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "Pinned with metadata" -runTest "go run $MAIN_DIR delete $META --key=$PINATA_API_JWT_TEST" "Delete with metadata" - -runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "Pin with metadata" -runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "Pinned with metadata" -runTest "go run $MAIN_DIR pin $ENTRY_DIR $META_FORCE --key=$PINATA_API_JWT_TEST --force=true" "Forced pin" -runTest "go run $MAIN_DIR delete $META_FORCE --key=$PINATA_API_JWT_TEST" "Delete with metadata" - -runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "Pin with metadata" -runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "Pinned with metadata" -runTest "go run $MAIN_DIR pin $ENTRY_DIR $META_FORCE --key=$PINATA_API_JWT_TEST --overwrite=true" "Overwrite pin" -runTest "go run $MAIN_DIR delete $META_FORCE --key=$PINATA_API_JWT_TEST" "Delete with metadata" - +# DAG test DAG: +runTest "go run $MAIN_DIR dag $ENTRY_DIR &> /dev/null" "DAG: Dag" + +# Pin dir test PIN: +runTest "go run $MAIN_DIR pin $ENTRY_DIR --key=$PINATA_API_JWT_TEST" "PIN: Pin with CID" +runTest "go run $MAIN_DIR pinned $CID --key=$PINATA_API_JWT_TEST" "PIN: Pinned with CID" +runTest "go run $MAIN_DIR delete $CID --key=$PINATA_API_JWT_TEST" "PIN: Unpin with CID" + +#Pin with meta test META: +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "META: Pin with metadata" +runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "META: Pinned with metadata" +runTest "go run $MAIN_DIR delete $META --key=$PINATA_API_JWT_TEST" "META: Delete with metadata" + +#Pin with meta --force FORCE: +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "FORCE: Pin with metadata" +runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "FORCE: Pinned with metadata" +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META_FORCE --key=$PINATA_API_JWT_TEST --force=true" "FORCE: pin with meta --force" +runTest "go run $MAIN_DIR delete $META_FORCE --key=$PINATA_API_JWT_TEST" "FORCE: Delete with metadata" + +#Pin with meta --overwrite OVERWRITE: +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "OVERWRITE: Pin with metadata" +runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "OVERWRITE: Pinned with metadata" +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META_FORCE --key=$PINATA_API_JWT_TEST --overwrite=true" "OVERWRITE: Pin with metadata --overwrite" +runTest "go run $MAIN_DIR pinned $META_FORCE --key=$PINATA_API_JWT_TEST" "OVERWRITE: Pinned with metadata" +runTest "go run $MAIN_DIR delete $META_FORCE --key=$PINATA_API_JWT_TEST" "OVERWRITE: Delete with metadata" +#TODO: collect exit codes for later processing bu echoInfo "All tests finished. Cleaning up the environment..." rm -rf $ENTRY_DIR || bu echoError "Failed to clean up an the environment" From 04c8c6832ba7fddc3906b5418a3d63bddc47e090 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Tue, 4 Apr 2023 23:57:37 +0200 Subject: [PATCH 34/38] Fix typo, clean set --- ipfs-api/scripts/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ipfs-api/scripts/test.sh b/ipfs-api/scripts/test.sh index d9a7a921..643f70b2 100755 --- a/ipfs-api/scripts/test.sh +++ b/ipfs-api/scripts/test.sh @@ -35,7 +35,7 @@ for i in {6..10}; do echo "file$i">"$SECOND_DIR/file$i.txt" || bu echoError "Failed to create file$i.txt" done -set -x + runTest() { local test_cmd="$1" @@ -78,7 +78,7 @@ runTest "go run $MAIN_DIR delete $META --key=$PINATA_API_JWT_TEST" "META: Delete #Pin with meta --force FORCE: runTest "go run $MAIN_DIR pin $ENTRY_DIR $META --key=$PINATA_API_JWT_TEST" "FORCE: Pin with metadata" runTest "go run $MAIN_DIR pinned $META --key=$PINATA_API_JWT_TEST" "FORCE: Pinned with metadata" -runTest "go run $MAIN_DIR pin $ENTRY_DIR $META_FORCE --key=$PINATA_API_JWT_TEST --force=true" "FORCE: pin with meta --force" +runTest "go run $MAIN_DIR pin $ENTRY_DIR $META_FORCE --key=$PINATA_API_JWT_TEST --force=true" "FORCE: Pin with metadata --force" runTest "go run $MAIN_DIR delete $META_FORCE --key=$PINATA_API_JWT_TEST" "FORCE: Delete with metadata" #Pin with meta --overwrite OVERWRITE: From d318de4ed46a26b465e97e94904958367de20796 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Thu, 6 Apr 2023 11:50:49 +0200 Subject: [PATCH 35/38] Refactor mnemonic cmd Separate func for cipher, correct err handling --- bip39gen/cmd/mnemonic.go | 166 ++++++++++++++++++++++++--------------- 1 file changed, 102 insertions(+), 64 deletions(-) diff --git a/bip39gen/cmd/mnemonic.go b/bip39gen/cmd/mnemonic.go index 24709788..d68c433a 100644 --- a/bip39gen/cmd/mnemonic.go +++ b/bip39gen/cmd/mnemonic.go @@ -28,15 +28,30 @@ func validateLengthFlagInput(length int) error { } return nil } +func validateLengthEntropyInput(str string) error { + if len(str) == 0 { + return nil + } + + if (words/3)*32 != len(str) { + err := errors.New(fmt.Sprintf("human provided entropy has insufficient length, expected %v bits but supplied only %v of entropy, your mnemonic is NOT secure. You can specify a cipher flag to extrapolate your input.", (words/3)*32, len(str))) + return err + } + return nil + +} // validateEntropyFlagInput checks if the provided entropy string is valid. func validateEntropyFlagInput(str string) error { - if len(str) > 0 { - match, _ := regexp.MatchString("^[0-1]{1,}$", str) - if !match { - return errBinary - } + if len(str) == 0 { + return nil + } + + match, _ := regexp.MatchString("^[0-1]+$", str) + if !match { + return errBinary } + return nil } @@ -64,6 +79,79 @@ func checkInputPrefix(str string) string { } return str } +func processSHA256() error { + hex = true + if words != 24 { + fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3)) + words = 24 + } + sum := sha256.Sum256([]byte(userEntropy)) + + userEntropy = string(sum[:]) + userEntropy = fmt.Sprintf("%x", userEntropy) + + if err := validateHexEntropyFlagInput(userEntropy); err != nil { + return err + } + return nil +} + +func processSHA512() error { + hex = true + if words != 48 { + fmt.Println(colors.Print("Warning. With sha512 you can generate 48 words", 3)) + words = 48 + } + sum := sha512.Sum512([]byte(userEntropy)) + + // Flip bytes to string hex + userEntropy = string(sum[:]) + userEntropy = fmt.Sprintf("%x", userEntropy) + + if err := validateHexEntropyFlagInput(userEntropy); err != nil { + return err + } + return nil +} + +func processChaCha20() error { + hex = true + if words != 24 { + fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3)) + words = 24 + } + sum := sha256.Sum256([]byte(userEntropy)) + + // Flip bytes to string hex + userEntropy = string(sum[:]) + userEntropy = fmt.Sprintf("%x", userEntropy) + + aead, err := chacha20poly1305.NewX(sum[:]) + if err != nil { + return err + } + + mnemonic := NewMnemonic() + msg := mnemonic.String() + + nonce := make([]byte, chacha20poly1305.NonceSizeX) + ciphertext := aead.Seal(nil, nonce, []byte(msg), nil) + fmt.Fprintf(os.Stdout, "Cipher stream: %x\n", ciphertext) + mnemonic.Print(verbose) + return nil +} +func processPadding() error { + hex = false + if err := validateEntropyFlagInput(rawEntropy); err != nil { + return err + } + bits := (words / 3) * 32 + bitsEnt := len(rawEntropy) + for i := bitsEnt; i <= bits; i++ { + rawEntropy += "0" + } + return nil +} // cmdMnemonicPreRun validates the provided flags and sets the required variables. func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error { @@ -90,85 +178,35 @@ func cmdMnemonicPreRun(cmd *cobra.Command, args []string) error { if err := validateEntropyFlagInput(i); err != nil { return err } - if (words/3)*32 != len(userEntropy) { - err := errors.New(fmt.Sprintf("human provided entropy has insufficient length, expected %v bits but only %v, your mnemonic is NOT secure. You can specify a cipher flag to extrapolate your input.", (words/3)*32, len(userEntropy))) + err := validateLengthEntropyInput(i) + if err != nil { return err } + } } + } if (len(userEntropy) > 0 || len(rawEntropy) > 0) && len(cipher) != 0 { switch cipher { case "sha256": - hex = true - if words != 24 { - fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3)) - words = 24 - } - sum := sha256.Sum256([]byte(userEntropy)) - - userEntropy = string(sum[:]) - userEntropy = fmt.Sprintf("%x", userEntropy) - - if err := validateHexEntropyFlagInput(userEntropy); err != nil { + if err := processSHA256(); err != nil { return err } - case "sha512": - hex = true - if words != 48 { - fmt.Println(colors.Print("Warning. With sha512 you can generate 48 words", 3)) - words = 48 - } - sum := sha512.Sum512([]byte(userEntropy)) - - // Flip bytes to string hex - userEntropy = string(sum[:]) - userEntropy = fmt.Sprintf("%x", userEntropy) - - if err := validateHexEntropyFlagInput(userEntropy); err != nil { + if err := processSHA512(); err != nil { return err } - case "chacha20": - hex = true - if words != 24 { - fmt.Println(colors.Print("Warning. With sha256 you can generate 24 words", 3)) - words = 24 + if err := processChaCha20(); err != nil { + return err } - sum := sha256.Sum256([]byte(userEntropy)) - - // Flip bytes to string hex - userEntropy = string(sum[:]) - userEntropy = fmt.Sprintf("%x", userEntropy) - - aead, _ := chacha20poly1305.NewX(sum[:]) - - mnemonic := NewMnemonic() - msg := mnemonic.String() - - nonce := make([]byte, chacha20poly1305.NonceSizeX) - ciphertext := aead.Seal(nil, nonce, []byte(msg), nil) - - fmt.Printf("Cipher stream: %x\n", ciphertext) - - mnemonic.Print(verbose) - // should refactor this. Perhaps with a context. - os.Exit(0) - return nil case "padding": - hex = false - if err := validateEntropyFlagInput(rawEntropy); err != nil { + if err := processPadding(); err != nil { return err } - bits := (words / 3) * 32 - bitsEnt := len(rawEntropy) - for i := bitsEnt; i <= bits; i++ { - rawEntropy += "0" - } - return nil } } From 8dd79add53957cdd5f3d2e5b13ce4549b3907fa0 Mon Sep 17 00:00:00 2001 From: mrlutik Date: Thu, 6 Apr 2023 11:52:38 +0200 Subject: [PATCH 36/38] TODO integration tests --- bip39gen/scripts/test.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bip39gen/scripts/test.sh b/bip39gen/scripts/test.sh index 433ff064..eb54b21e 100644 --- a/bip39gen/scripts/test.sh +++ b/bip39gen/scripts/test.sh @@ -32,6 +32,24 @@ MNEMONIC_TEST_2="panther door little taxi unfold remain notable smooth trap beac [ "$MNEMONIC_TEST_1" != "$MNEMONIC_TEST_2" ] && \ echoErr "ERROR: When sha256 raw entropy is provided expected to end up with deterministic mnemonic, but results differ :(" && exit 1 || echoInfo "INFO: Test 2 passed" +runTest() { + local test_cmd="$1" + local test_name="$2" + + + # Execute the test command and get the exit code + eval "$test_cmd &> /dev/null ||:" + exit_code=$? + + # Get the command name + # Check the exit code and print the result + if [ $exit_code -eq 0 ]; then + echo "[PASS] $test_name" + else + bu echoError "[FAIL] $test_name" + fi +} + From afc6a00db0910bd4642f6b49f2b430ce8b22da1d Mon Sep 17 00:00:00 2001 From: mrlutik Date: Thu, 6 Apr 2023 11:55:53 +0200 Subject: [PATCH 37/38] Change ver v0.3.42 -> v0.3.43 --- bash-utils/bash-utils.sh | 4 +++- bip39gen/cmd/version.go | 2 +- build-tools/update_version.py | 2 +- ipfs-api/README.md | 2 +- ipfs-api/types/constants.go | 2 +- scripts/version.sh | 2 +- validator-key-gen/README.md | 2 +- validator-key-gen/main.go | 2 +- 8 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bash-utils/bash-utils.sh b/bash-utils/bash-utils.sh index 84d564b5..b0fbb75a 100644 --- a/bash-utils/bash-utils.sh +++ b/bash-utils/bash-utils.sh @@ -26,7 +26,7 @@ function bashUtilsVersion() { # this is default installation script for utils # ./bash-utils.sh bashUtilsSetup "/var/kiraglob" function bashUtilsSetup() { - local BASH_UTILS_VERSION="v0.3.43" + local BASH_UTILS_VERSION="v0.3.44" local COSIGN_VERSION="v2.0.0" if [ "$1" == "version" ] ; then echo "$BASH_UTILS_VERSION" @@ -2313,3 +2313,5 @@ fi + + diff --git a/bip39gen/cmd/version.go b/bip39gen/cmd/version.go index 9e7c1b57..146a17a2 100644 --- a/bip39gen/cmd/version.go +++ b/bip39gen/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const Bip39GenVersion = "v0.3.43" +const Bip39GenVersion = "v0.3.44" func cmdVersion(cmd *cobra.Command, args []string) error { fmt.Println(Bip39GenVersion) diff --git a/build-tools/update_version.py b/build-tools/update_version.py index 3cf93ce8..87352e86 100644 --- a/build-tools/update_version.py +++ b/build-tools/update_version.py @@ -1,7 +1,7 @@ import re import sys -version = "v0.3.43" +version = "v0.3.44" if len(sys.argv) != 2: print("Usage: python3 update_version.py ") diff --git a/ipfs-api/README.md b/ipfs-api/README.md index 4f6a253f..d11e84a1 100644 --- a/ipfs-api/README.md +++ b/ipfs-api/README.md @@ -5,7 +5,7 @@ A command-line interface (CLI) for interacting with the IPFS API, providing func To install the CLI, clone the repository and build the project using Go.= or dowload from existing release ``` -TOOLS_VERSION="v0.3.43" && rm -rfv /tmp/ipfs-api && \ +TOOLS_VERSION="v0.3.44" && rm -rfv /tmp/ipfs-api && \ safeWget /tmp/ipfs-api.deb "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/ipfs-api-$(getPlatform)-$(getArch).deb" "QmeqFDLGfwoWgCy2ZEFXerVC5XW8c5xgRyhK5bLArBr2ue" && \ dpkg-deb -x /tmp/ipfs-api.deb /tmp/ipfs-api && cp -fv "/tmp/ipfs-api/bin/ipfs-api" /usr/local/bin/ipfs-api && chmod -v 755 /usr/local/bin/ipfs-api && \ ipfs-api version diff --git a/ipfs-api/types/constants.go b/ipfs-api/types/constants.go index 0f0dfdaf..719b8922 100644 --- a/ipfs-api/types/constants.go +++ b/ipfs-api/types/constants.go @@ -1,7 +1,7 @@ package types const ( - IpfsApiVersion = "v0.3.43" + IpfsApiVersion = "v0.3.44" // Pinata v1 constants BASE_URL = "https://api.pinata.cloud" diff --git a/scripts/version.sh b/scripts/version.sh index 11a736c0..856bbc05 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "v0.3.43" +echo "v0.3.44" diff --git a/validator-key-gen/README.md b/validator-key-gen/README.md index d9b12832..e05468dd 100644 --- a/validator-key-gen/README.md +++ b/validator-key-gen/README.md @@ -5,7 +5,7 @@ Validator Key Generator is a CLI tool that generates validator keys, node keys, ### Setup from binary file ```bash -TOOLS_VERSION="v0.3.43" +TOOLS_VERSION="v0.3.44" # Quick-Install bash-utils or see root repository README file for secure download FILE_NAME="bash-utils.sh" && \ diff --git a/validator-key-gen/main.go b/validator-key-gen/main.go index 4aca6a48..c8f9fe35 100644 --- a/validator-key-gen/main.go +++ b/validator-key-gen/main.go @@ -18,7 +18,7 @@ import ( "github.com/tendermint/tendermint/privval" ) -const PrivValidatorKeyGenVersion = "v0.3.43" +const PrivValidatorKeyGenVersion = "v0.3.44" type Prefix struct { fullPath *hd.BIP44Params From f43b6a5dae5166f01799a07dcdcb2e3e72abf88a Mon Sep 17 00:00:00 2001 From: mrlutik Date: Thu, 6 Apr 2023 11:56:53 +0200 Subject: [PATCH 38/38] Update RELEASE.md --- RELEASE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE.md b/RELEASE.md index d98ae65e..3ee225cd 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,2 +1,3 @@ Features: * ipfs-api: add integration tests +* bip39gen: refactor, fix err handling