forked from risc0/risc0-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e-test.sh
executable file
·56 lines (46 loc) · 2.42 KB
/
e2e-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Test the integration of the application contract and publisher, against a running EVM chain.
set -e -o pipefail
export TOKEN_OWNER=${ETH_WALLET_ADDRESS:?}
# Determine the chain ID
CHAIN_ID=$(cast rpc --rpc-url ${ETH_RPC_URL:?} eth_chainId | jq -re)
CHAIN_ID=$((CHAIN_ID))
# Deploy the Counter contract
echo "Deploying the Counter contract..."
forge script --rpc-url ${ETH_RPC_URL:?} --private-key ${ETH_WALLET_PRIVATE_KEY:?} --broadcast DeployCounter
# Extract the Toyken address
TOYKEN_ADDRESS=$(jq -re '.transactions[] | select(.contractName == "ERC20FixedSupply") | .contractAddress' ./broadcast/DeployCounter.s.sol/$CHAIN_ID/run-latest.json)
echo "ERC20 Toyken Address: $TOYKEN_ADDRESS"
# Extract the Counter contract address
COUNTER_ADDRESS=$(jq -re '.transactions[] | select(.contractName == "Counter") | .contractAddress' ./broadcast/DeployCounter.s.sol/$CHAIN_ID/run-latest.json)
echo "Counter Address: $COUNTER_ADDRESS"
# Extract the block in which the Toyken contract has been deployed
BLOCK_NUMBER=$(jq --arg ADDRESS "$TOYKEN_ADDRESS" -re '.receipts[] | select(.contractAddress == $ADDRESS) | .blockNumber' ./broadcast/DeployCounter.s.sol/$CHAIN_ID/run-latest.json)
export COMMITMENT_BLOCK=$BLOCK_NUMBER
# Enable the beacon feature is an Beacon API is provided
if [[ -n "${BEACON_API_URL}" ]]; then
PUBLISHER_FEATURES="beacon"
fi
# Enable the history feature and override the commitment block
if [[ ${HISTORY_BLOCKS} -gt 0 ]]; then
printf -v COMMITMENT_BLOCK '%#x' "$((BLOCK_NUMBER + HISTORY_BLOCKS))"
PUBLISHER_FEATURES="history"
fi
echo "Waiting for block ${COMMITMENT_BLOCK} to have one confirmation..."
while [[ $(cast rpc --rpc-url "${ETH_RPC_URL:?}" eth_blockNumber | jq -re) -le ${COMMITMENT_BLOCK} ]]; do sleep 3; done
# Publish a new state
echo "Publishing a new state..."
RUST_LOG=${RUST_LOG:-info,risc0_steel=debug} cargo run --bin publisher -F "$PUBLISHER_FEATURES" -- \
--eth-wallet-private-key=${ETH_WALLET_PRIVATE_KEY:?} \
--eth-rpc-url=${ETH_RPC_URL:?} \
--execution-block=${BLOCK_NUMBER:?} \
--counter-address=${COUNTER_ADDRESS:?} \
--token-contract=${TOYKEN_ADDRESS:?} \
--account=${TOKEN_OWNER:?}
# Attempt to verify counter value as part of the script logic
echo "Verifying state..."
COUNTER_VALUE=$(cast call --rpc-url ${ETH_RPC_URL:?} ${COUNTER_ADDRESS:?} 'get()(uint256)')
if [ "$COUNTER_VALUE" != "1" ]; then
echo "Counter value is not 1 as expected, but $COUNTER_VALUE."
exit 1
fi