Skip to content

Commit

Permalink
add a check that smoke tested deploy script doesn't auto deploy on no…
Browse files Browse the repository at this point in the history
…de startup (#557)
  • Loading branch information
sparrowDom authored Feb 11, 2021
1 parent da5b410 commit 4a89d54
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
11 changes: 10 additions & 1 deletion contracts/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { debug } = require("./tasks/debug");
const { env } = require("./tasks/env");
const { execute, executeOnFork, proposal } = require("./tasks/governance");
const { balance } = require("./tasks/ousd");
const { smokeTest } = require("./tasks/smokeTest");
const { smokeTest, smokeTestCheck } = require("./tasks/smokeTest");
const {
storeStorageLayoutForAllContracts,
assertStorageLayoutChangeSafe,
Expand Down Expand Up @@ -145,6 +145,15 @@ task(
"Optional deployment id to run smoke tests against"
)
.setAction(smokeTest);
task(
"smokeTestCheck",
"Execute necessary smoke test environment / deploy script checks before the node is initialized"
)
.addOptionalParam(
"deployid",
"Optional deployment id to run smoke tests against"
)
.setAction(smokeTestCheck);

// Storage slots
task(
Expand Down
11 changes: 8 additions & 3 deletions contracts/scripts/test/smokeTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# any child processes created by this process are killed once the main process is terminated
trap "exit" INT TERM ERR
trap "kill 0" EXIT
nodeWaitTimeout=180
nodeWaitTimeout=60

main()
{
Expand All @@ -32,9 +32,14 @@ main()
echo "It is recommended that BLOCK_NUMBER is set to a recent block to improve performance of the fork";
fi

SMOKE_TEST=true FORK=true npx hardhat smokeTestCheck --network localhost "$@"
if [ $? -ne 0 ]
then
exit 1
fi

nodeOutput=$(mktemp "${TMPDIR:-/tmp/}$(basename 0).XXX")
SMOKE_TEST=true yarn run node:fork &> $nodeOutput &
NODE_PID=$!

echo "Node output: $nodeOutput"
echo "Waiting for node to initialize:"
Expand All @@ -53,7 +58,7 @@ main()
printf "\n"
echo "🟢 Node initialized running smoke tests"

FORK=true npx hardhat smokeTest --network localhost "$@"
SMOKE_TEST=true FORK=true npx hardhat smokeTest --network localhost "$@"
}

main "$@"
20 changes: 19 additions & 1 deletion contracts/tasks/smokeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

async function smokeTestCheck(taskArguments, hre) {
const deployId = taskArguments.deployid

if (!deployId) {
// interactive mode nothing to do here
return
}

const scripts = await getDeployScripts()
const deployScript = scripts[parseInt(deployId)]
const main = require(deployScript.fullPath)

if (!main.skip()) {
throw new Error("Deploy script that smoke tests are ran against should return skip === true in smoke test environment. See that the 'main.skip' function in deploy script ends with '|| isSmokeTest;'")
}
}

async function smokeTest(taskArguments, hre) {
const deployId = taskArguments.deployid
let interactiveMode = false
Expand Down Expand Up @@ -104,5 +121,6 @@ async function smokeTest(taskArguments, hre) {
}

module.exports = {
smokeTest
smokeTest,
smokeTestCheck
}

0 comments on commit 4a89d54

Please sign in to comment.