externalTests: Allow adding extra settings to presets

This commit is contained in:
Kamil Śliwak 2022-01-19 18:17:38 +01:00
parent 9e92c7a466
commit e30d0a6199

View File

@ -198,6 +198,8 @@ function force_truffle_compiler_settings
local solc_path="$3"
local preset="$4"
local evm_version="${5:-"$CURRENT_EVM_VERSION"}"
local extra_settings="$6"
local extra_optimizer_settings="$7"
[[ $binary_type == native || $binary_type == solcjs ]] || assertFail
@ -209,14 +211,14 @@ function force_truffle_compiler_settings
echo "Binary type: $binary_type"
echo "Compiler path: $solc_path"
echo "Settings preset: ${preset}"
echo "Settings: $(settings_from_preset "$preset" "$evm_version")"
echo "Settings: $(settings_from_preset "$preset" "$evm_version" "$extra_settings" "$extra_optimizer_settings")"
echo "EVM version: $evm_version"
echo "Compiler version: ${SOLCVERSION_SHORT}"
echo "Compiler version (full): ${SOLCVERSION}"
echo "-------------------------------------"
local compiler_settings gas_reporter_settings
compiler_settings=$(truffle_compiler_settings "$solc_path" "$preset" "$evm_version")
compiler_settings=$(truffle_compiler_settings "$solc_path" "$preset" "$evm_version" "$extra_settings" "$extra_optimizer_settings")
gas_reporter_settings=$(eth_gas_reporter_settings "$preset")
{
@ -307,19 +309,21 @@ function force_hardhat_compiler_settings
local preset="$2"
local config_var_name="$3"
local evm_version="${4:-"$CURRENT_EVM_VERSION"}"
local extra_settings="$5"
local extra_optimizer_settings="$6"
printLog "Configuring Hardhat..."
echo "-------------------------------------"
echo "Config file: ${config_file}"
echo "Settings preset: ${preset}"
echo "Settings: $(settings_from_preset "$preset" "$evm_version")"
echo "Settings: $(settings_from_preset "$preset" "$evm_version" "$extra_settings" "$extra_optimizer_settings")"
echo "EVM version: ${evm_version}"
echo "Compiler version: ${SOLCVERSION_SHORT}"
echo "Compiler version (full): ${SOLCVERSION}"
echo "-------------------------------------"
local compiler_settings gas_reporter_settings
compiler_settings=$(hardhat_compiler_settings "$SOLCVERSION_SHORT" "$preset" "$evm_version")
compiler_settings=$(hardhat_compiler_settings "$SOLCVERSION_SHORT" "$preset" "$evm_version" "$extra_settings" "$extra_optimizer_settings")
gas_reporter_settings=$(eth_gas_reporter_settings "$preset")
if [[ $config_file == *\.js ]]; then
[[ $config_var_name == "" ]] || assertFail
@ -372,17 +376,22 @@ function settings_from_preset
{
local preset="$1"
local evm_version="$2"
local extra_settings="$3"
local extra_optimizer_settings="$4"
[[ " ${AVAILABLE_PRESETS[*]} " == *" $preset "* ]] || assertFail
[[ $extra_settings == "" ]] || extra_settings="${extra_settings}, "
[[ $extra_optimizer_settings == "" ]] || extra_optimizer_settings="${extra_optimizer_settings}, "
case "$preset" in
# NOTE: Remember to update `parallelism` of `t_ems_ext` job in CI config if you add/remove presets
legacy-no-optimize) echo "{evmVersion: '${evm_version}', viaIR: false, optimizer: {enabled: false}}" ;;
ir-no-optimize) echo "{evmVersion: '${evm_version}', viaIR: true, optimizer: {enabled: false}}" ;;
legacy-optimize-evm-only) echo "{evmVersion: '${evm_version}', viaIR: false, optimizer: {enabled: true, details: {yul: false}}}" ;;
ir-optimize-evm-only) echo "{evmVersion: '${evm_version}', viaIR: true, optimizer: {enabled: true, details: {yul: false}}}" ;;
legacy-optimize-evm+yul) echo "{evmVersion: '${evm_version}', viaIR: false, optimizer: {enabled: true, details: {yul: true}}}" ;;
ir-optimize-evm+yul) echo "{evmVersion: '${evm_version}', viaIR: true, optimizer: {enabled: true, details: {yul: true}}}" ;;
legacy-no-optimize) echo "{${extra_settings}evmVersion: '${evm_version}', viaIR: false, optimizer: {${extra_optimizer_settings}enabled: false}}" ;;
ir-no-optimize) echo "{${extra_settings}evmVersion: '${evm_version}', viaIR: true, optimizer: {${extra_optimizer_settings}enabled: false}}" ;;
legacy-optimize-evm-only) echo "{${extra_settings}evmVersion: '${evm_version}', viaIR: false, optimizer: {${extra_optimizer_settings}enabled: true, details: {yul: false}}}" ;;
ir-optimize-evm-only) echo "{${extra_settings}evmVersion: '${evm_version}', viaIR: true, optimizer: {${extra_optimizer_settings}enabled: true, details: {yul: false}}}" ;;
legacy-optimize-evm+yul) echo "{${extra_settings}evmVersion: '${evm_version}', viaIR: false, optimizer: {${extra_optimizer_settings}enabled: true, details: {yul: true}}}" ;;
ir-optimize-evm+yul) echo "{${extra_settings}evmVersion: '${evm_version}', viaIR: true, optimizer: {${extra_optimizer_settings}enabled: true, details: {yul: true}}}" ;;
*)
fail "Unknown settings preset: '${preset}'."
;;
@ -419,11 +428,13 @@ function truffle_compiler_settings
local solc_path="$1"
local preset="$2"
local evm_version="$3"
local extra_settings="$4"
local extra_optimizer_settings="$5"
echo "{"
echo " solc: {"
echo " version: \"${solc_path}\","
echo " settings: $(settings_from_preset "$preset" "$evm_version")"
echo " settings: $(settings_from_preset "$preset" "$evm_version" "$extra_settings" "$extra_optimizer_settings")"
echo " }"
echo "}"
}
@ -468,10 +479,12 @@ function hardhat_compiler_settings {
local solc_version="$1"
local preset="$2"
local evm_version="$3"
local extra_settings="$4"
local extra_optimizer_settings="$5"
echo "{"
echo " version: '${solc_version}',"
echo " settings: $(settings_from_preset "$preset" "$evm_version")"
echo " settings: $(settings_from_preset "$preset" "$evm_version" "$extra_settings" "$extra_optimizer_settings")"
echo "}"
}
@ -506,9 +519,11 @@ function truffle_run_test
local compile_only_presets="$5"
local compile_fn="$6"
local test_fn="$7"
local extra_settings="$8"
local extra_optimizer_settings="$9"
truffle_clean
force_truffle_compiler_settings "$config_file" "$binary_type" "$solc_path" "$preset"
force_truffle_compiler_settings "$config_file" "$binary_type" "$solc_path" "$preset" "$CURRENT_EVM_VERSION" "$extra_settings" "$extra_optimizer_settings"
compile_and_run_test compile_fn test_fn truffle_verify_compiler_version "$preset" "$compile_only_presets"
}
@ -520,9 +535,11 @@ function hardhat_run_test
local compile_fn="$4"
local test_fn="$5"
local config_var_name="$6"
local extra_settings="$7"
local extra_optimizer_settings="$8"
hardhat_clean
force_hardhat_compiler_settings "$config_file" "$preset" "$config_var_name"
force_hardhat_compiler_settings "$config_file" "$preset" "$config_var_name" "$CURRENT_EVM_VERSION" "$extra_settings" "$extra_optimizer_settings"
compile_and_run_test compile_fn test_fn hardhat_verify_compiler_version "$preset" "$compile_only_presets"
}