From b60b596741614263f80d71a5bfe069360cc97764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Mon, 10 Jan 2022 17:25:20 +0100 Subject: [PATCH] externalTests: Add support for cloning repos at a specific commit --- test/externalTests/colony.sh | 5 +++-- test/externalTests/common.sh | 22 +++++++++++++++++----- test/externalTests/ens.sh | 5 +++-- test/externalTests/gnosis-v2.sh | 5 +++-- test/externalTests/gnosis.sh | 5 +++-- test/externalTests/trident.sh | 5 +++-- test/externalTests/zeppelin.sh | 5 +++-- 7 files changed, 35 insertions(+), 17 deletions(-) diff --git a/test/externalTests/colony.sh b/test/externalTests/colony.sh index 9bebc2722..a63648e85 100755 --- a/test/externalTests/colony.sh +++ b/test/externalTests/colony.sh @@ -34,7 +34,8 @@ function test_fn { yarn run test:contracts; } function colony_test { local repo="https://github.com/solidity-external-tests/colonyNetwork.git" - local branch=develop_080 + local ref_type=branch + local ref="develop_080" local config_file="truffle.js" local compile_only_presets=( @@ -54,7 +55,7 @@ function colony_test print_optimizer_presets_or_exit "$selected_optimizer_presets" setup_solc "$DIR" "$BINARY_TYPE" "$BINARY_PATH" - download_project "$repo" "$branch" "$DIR" + download_project "$repo" "$ref_type" "$ref" "$DIR" [[ $BINARY_TYPE == native ]] && replace_global_solc "$BINARY_PATH" neutralize_package_json_hooks diff --git a/test/externalTests/common.sh b/test/externalTests/common.sh index a0bf17bda..728f85fbb 100644 --- a/test/externalTests/common.sh +++ b/test/externalTests/common.sh @@ -77,12 +77,24 @@ function setup_solc function download_project { local repo="$1" - local solcjs_branch="$2" - local test_dir="$3" + local ref_type="$2" + local solcjs_ref="$3" + local test_dir="$4" - printLog "Cloning $solcjs_branch of $repo..." - git clone --depth 1 "$repo" -b "$solcjs_branch" "$test_dir/ext" - cd ext + [[ $ref_type == commit || $ref_type == branch || $ref_type == tag ]] || assertFail + + printLog "Cloning ${ref_type} ${solcjs_ref} of ${repo}..." + if [[ $ref_type == commit ]]; then + mkdir ext + cd ext + git init + git remote add origin "$repo" + git fetch --depth 1 origin "$solcjs_ref" + git reset --hard FETCH_HEAD + else + git clone --depth 1 "$repo" -b "$solcjs_ref" "$test_dir/ext" + cd ext + fi echo "Current commit hash: $(git rev-parse HEAD)" } diff --git a/test/externalTests/ens.sh b/test/externalTests/ens.sh index 2b663cf84..b19fbabe2 100755 --- a/test/externalTests/ens.sh +++ b/test/externalTests/ens.sh @@ -34,7 +34,8 @@ function test_fn { yarn test; } function ens_test { local repo="https://github.com/ensdomains/ens-contracts.git" - local branch="v0.0.8" # The project is in flux right now and master might be too unstable for us + local ref_type=tag + local ref="v0.0.8" # The project is in flux right now and master might be too unstable for us local config_file="hardhat.config.js" local compile_only_presets=( @@ -54,7 +55,7 @@ function ens_test print_optimizer_presets_or_exit "$selected_optimizer_presets" setup_solc "$DIR" "$BINARY_TYPE" "$BINARY_PATH" - download_project "$repo" "$branch" "$DIR" + download_project "$repo" "$ref_type" "$ref" "$DIR" [[ $BINARY_TYPE == native ]] && replace_global_solc "$BINARY_PATH" neutralize_package_lock diff --git a/test/externalTests/gnosis-v2.sh b/test/externalTests/gnosis-v2.sh index f963c74a0..e21940095 100755 --- a/test/externalTests/gnosis-v2.sh +++ b/test/externalTests/gnosis-v2.sh @@ -34,7 +34,8 @@ function test_fn { npm test; } function gnosis_safe_test { local repo="https://github.com/solidity-external-tests/safe-contracts.git" - local branch=v2_080 + local ref_type=branch + local ref="v2_080" local config_file="truffle-config.js" local compile_only_presets=( @@ -54,7 +55,7 @@ function gnosis_safe_test print_optimizer_presets_or_exit "$selected_optimizer_presets" setup_solc "$DIR" "$BINARY_TYPE" "$BINARY_PATH" - download_project "$repo" "$branch" "$DIR" + download_project "$repo" "$ref_type" "$ref" "$DIR" [[ $BINARY_TYPE == native ]] && replace_global_solc "$BINARY_PATH" sed -i 's|github:gnosis/mock-contract#sol_0_5_0|github:solidity-external-tests/mock-contract#master_080|g' package.json diff --git a/test/externalTests/gnosis.sh b/test/externalTests/gnosis.sh index 7d8bc2442..ade36a9ce 100755 --- a/test/externalTests/gnosis.sh +++ b/test/externalTests/gnosis.sh @@ -34,7 +34,8 @@ function test_fn { npm test; } function gnosis_safe_test { local repo="https://github.com/solidity-external-tests/safe-contracts.git" - local branch=development_080 + local ref_type=branch + local ref="development_080" local config_file="truffle-config.js" local compile_only_presets=() @@ -53,7 +54,7 @@ function gnosis_safe_test print_optimizer_presets_or_exit "$selected_optimizer_presets" setup_solc "$DIR" "$BINARY_TYPE" "$BINARY_PATH" - download_project "$repo" "$branch" "$DIR" + download_project "$repo" "$ref_type" "$ref" "$DIR" [[ $BINARY_TYPE == native ]] && replace_global_solc "$BINARY_PATH" sed -i 's|github:gnosis/mock-contract#sol_0_5_0|github:solidity-external-tests/mock-contract#master_080|g' package.json diff --git a/test/externalTests/trident.sh b/test/externalTests/trident.sh index 312930293..3c15c5ea1 100755 --- a/test/externalTests/trident.sh +++ b/test/externalTests/trident.sh @@ -42,7 +42,8 @@ function test_fn { function trident_test { local repo="https://github.com/sushiswap/trident" - local branch=master + local ref_type=branch + local ref="master" local config_file="hardhat.config.ts" local config_var=config @@ -62,7 +63,7 @@ function trident_test print_optimizer_presets_or_exit "$selected_optimizer_presets" setup_solc "$DIR" "$BINARY_TYPE" "$BINARY_PATH" - download_project "$repo" "$branch" "$DIR" + download_project "$repo" "$ref_type" "$ref" "$DIR" # TODO: Currently tests work only with the exact versions from yarn.lock. # Re-enable this when https://github.com/sushiswap/trident/issues/284 is fixed. diff --git a/test/externalTests/zeppelin.sh b/test/externalTests/zeppelin.sh index 9865c7e40..7873ec953 100755 --- a/test/externalTests/zeppelin.sh +++ b/test/externalTests/zeppelin.sh @@ -34,7 +34,8 @@ function test_fn { npm test; } function zeppelin_test { local repo="https://github.com/OpenZeppelin/openzeppelin-contracts.git" - local branch=master + local ref_type=branch + local ref="master" local config_file="hardhat.config.js" local compile_only_presets=( @@ -54,7 +55,7 @@ function zeppelin_test print_optimizer_presets_or_exit "$selected_optimizer_presets" setup_solc "$DIR" "$BINARY_TYPE" "$BINARY_PATH" - download_project "$repo" "$branch" "$DIR" + download_project "$repo" "$ref_type" "$ref" "$DIR" neutralize_package_json_hooks force_hardhat_compiler_binary "$config_file" "$BINARY_TYPE" "$BINARY_PATH"