Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Improve deploy.sh (#171)
Browse files Browse the repository at this point in the history
* Improve `deploy.sh`

* add case where address is address(0)

* xdigit

* unify `deploy.sh` and `get-deploy-info.sh`

* echo deploy info

* include commit add-on feat

* fix etherscan goerli api url + jq option to get raw string

* add back key spell

* add `0x0` as version of `address(0)`

Co-authored-by: Christopher Mooney <[email protected]>

* add tests check at deployed block + color err msgs

* switch to `--edit` to allow dev to set commit msg

* add more commit checks and err msgs

* add stash/reload feat

* improve stash by static commit msg and rm `make test`

* adopt trap to reload staging area on exit + more granular commit + make test

* move stash on top

* fix git commit path

* switch to stash push path + more colored echos

* echo ordering

* switch to pop to cleanup stash list

* rm git add as not required following git commit path

---------

Co-authored-by: Christopher Mooney <[email protected]>
  • Loading branch information
naszam and godsflaw authored Mar 16, 2023
1 parent 16b079c commit 642de7d
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
#!/usr/bin/env bash
set -e
trap 'git stash pop' EXIT

[[ "$(cast chain --rpc-url="$ETH_RPC_URL")" == "goerli" ]] || { echo "Please set a Goerli ETH_RPC_URL"; exit 1; }
[[ "$ETHERSCAN_API_KEY" ]] || { echo "Please set ETHERSCAN_API_KEY"; exit 1; }
# Colors
YELLOW="\033[0;33m"
PURPLE="\033[0;35m"
NC="\033[0m"

make && \
dapp create DssSpell | \
xargs ./scripts/verify.py DssSpell
# stash any changes in the staging area
echo -e "${YELLOW}Stashing any changes to${NC} ${PURPLE}src/test/config.sol${NC}"
(set -x; git stash push src/test/config.sol)

[[ "$(cast chain --rpc-url="$ETH_RPC_URL")" == "goerli" ]] || { echo -e "${YELLOW}Please set a ${NC}${PURPLE}Goerli ETH_RPC_URL${NC}"; exit 1; }
[[ "$ETHERSCAN_API_KEY" ]] || { echo -e "${YELLOW}Please set ${NC}${PURPLE}ETHERSCAN_API_KEY${NC}"; exit 1; }

SOURCE="src/test/config.sol"
KEY_SPELL="deployed_spell"
KEY_TIMESTAMP="deployed_spell_created"
KEY_BLOCK="deployed_spell_block"

make && spell_address=$(dapp create DssSpell)

./scripts/verify.py DssSpell "$spell_address"

# edit config.sol to add the deployed spell address
sed -Ei "s/($KEY_SPELL: *address\()(0x[[:xdigit:]]{40}|0x0|0)\)/\1$spell_address)/" "$SOURCE"

# get tx hash from contract address, created using an internal transaction
TXHASH=$(curl "https://api-goerli.etherscan.io/api?module=account&action=txlistinternal&address=$spell_address&startblock=0&endblock=99999999&sort=asc&apikey=$ETHERSCAN_API_KEY" | jq -r ".result[0].hash")

# get deployed contract timestamp and block number info
timestamp=$(cast block "$(cast tx "${TXHASH}"|grep blockNumber|awk '{print $2}')"|grep timestamp|awk '{print $2}')
block=$(cast tx "${TXHASH}"|grep blockNumber|awk '{print $2}')

# edit config.sol to add the deployed spell timestamp and block number
sed -i "s/\($KEY_TIMESTAMP *: *\)[0-9]\+/\1$timestamp/" "$SOURCE"
sed -i "s/\($KEY_BLOCK *: *\)[0-9]\+/\1$block/" "$SOURCE"

echo -e "${YELLOW}Network: $(cast chain)${NC}"
echo -e "${YELLOW}config.sol updated with ${PURPLE}deployed spell:${NC} $spell_address, ${PURPLE}timestamp:${NC} $timestamp and ${PURPLE}block:${NC} $block ${NC}"

make test block="$block" || { echo -e "${PURPLE}Ensure Tests PASS before commiting the config.sol changes${NC}"; exit 1; }

# commit edit change to config.sol
if [[ $(git status --porcelain src/test/config.sol) ]]; then
(set -x; git commit -m "add deployed spell info" -- src/test/config.sol)
else
echo -e "${PURPLE}Ensure config.sol was edited correctly${NC}"
exit 1
fi

0 comments on commit 642de7d

Please sign in to comment.