Skip to content

Commit 1ceca5e

Browse files
Merge pull request #604 from shutter-network/shutter-service-test-setup
Shutter API Keyper basic test setup
2 parents a805cf4 + b83bb57 commit 1ceca5e

File tree

20 files changed

+689
-0
lines changed

20 files changed

+689
-0
lines changed

docker-test-setup-api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/data

docker-test-setup-api/00-build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
source ./common.sh
4+
5+
$DC --profile dev build
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
source ./common.sh
4+
5+
mkdb() {
6+
$DC exec -T db createdb -U postgres $1
7+
$DC run -T --rm --no-deps $1 initdb --config /config/${1}.toml
8+
}
9+
10+
$DC stop db
11+
$DC rm -f db
12+
13+
${BB} rm -rf data/db
14+
15+
$DC up -d db
16+
$DC run --rm --no-deps wait-for-db
17+
18+
for cmd in keyper-0 keyper-1 keyper-2; do
19+
mkdb $cmd &
20+
done
21+
22+
wait
23+
24+
$DC stop db
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
source ./common.sh
4+
5+
$DC stop blockchain
6+
$DC rm -f blockchain
7+
$DC stop chain-{0..2}-validator chain-seed
8+
$DC rm -f chain-{0..2}-validator chain-seed
9+
10+
${BB} rm -rf data/chain-{0..2}-validator data/chain-seed
11+
${BB} mkdir -p data/chain-{0..2}-validator/config data/chain-seed/config
12+
${BB} chmod -R a+rwX data/chain-{0..2}-validator/config data/chain-seed/config
13+
${BB} rm -rf data/deployments
14+
15+
# has blockchain as dependency
16+
$DC up -d blockchain
17+
sleep 5
18+
$DC up deploy-contracts
19+
20+
bash get-contracts.sh
21+
# setup chain-seed
22+
$DC run --rm --no-deps chain-seed init \
23+
--root /chain \
24+
--blocktime 1 \
25+
--listen-address tcp://0.0.0.0:${TM_RPC_PORT} \
26+
--role seed
27+
28+
seed_node=$(cat data/chain-seed/config/node_key.json.id)@chain-seed:${TM_P2P_PORT}
29+
30+
${BB} sed -i "/^moniker/c\moniker = \"chain-seed\"" data/chain-seed/config/config.toml
31+
32+
# configure validators and keypers 0-2
33+
for num in {0..2}; do
34+
validator_cmd=chain-$num-validator
35+
36+
$DC run --rm --no-deps ${validator_cmd} init \
37+
--root /chain \
38+
--genesis-keyper 0x440Dc6F164e9241F04d282215ceF2780cd0B755e \
39+
--blocktime 1 \
40+
--listen-address tcp://0.0.0.0:${TM_RPC_PORT} \
41+
--role validator
42+
43+
validator_id=$(cat data/${validator_cmd}/config/node_key.json.id)
44+
validator_node=${validator_id}@${validator_cmd}:${TM_P2P_PORT}
45+
validator_config_path=data/${validator_cmd}/config/config.toml
46+
47+
# share genesis
48+
if [ $num -eq 0 ]; then
49+
for destination in data/chain-seed/config/ data/chain-{1..2}-validator/config/; do
50+
${BB} cp -v data/chain-0-validator/config/genesis.json "${destination}"
51+
done
52+
fi
53+
54+
# set validator publickey for keyper
55+
${BB} sed -i "/ValidatorPublicKey/c\ValidatorPublicKey = \"$(cat data/${validator_cmd}/config/priv_validator_pubkey.hex)\"" /config/keyper-${num}.toml
56+
57+
# set seed node for chain bootstrap
58+
${BB} sed -i "/^seeds =/c\seeds = \"${seed_node}\"" "${validator_config_path}"
59+
# fix external address for docker internal communication
60+
${BB} sed -i "/^external_address =/c\external_address = \"${validator_cmd}:${TM_P2P_PORT}\"" "${validator_config_path}"
61+
# give a nice name
62+
${BB} sed -i "/^moniker/c\moniker = \"${validator_cmd}\"" "${validator_config_path}"
63+
64+
done
65+
66+
$DC stop -t 30

docker-test-setup-api/03-run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
source ./common.sh
4+
5+
echo "Starting entire system"
6+
$DC up -d
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
source ./common.sh
4+
source .env
5+
set -e
6+
7+
CONTRACTS_JSON=$(jq '.transactions[]|(select(.function==null))|{(.contractName|tostring): .contractAddress}' data/deployments/Deploy.service.s.sol/31337/run-latest.json)
8+
9+
for s in $(echo ${CONTRACTS_JSON} | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")| .[] "); do
10+
export $s
11+
done
12+
13+
# Get keyper addresses from node-deploy.json
14+
export KEYPER_ADDRESSES=$(jq -r '.keypers[0] | join(",")' config/node-deploy.json)
15+
16+
echo "Submitting Add Keyper Set transaction"
17+
export THRESHOLD=2
18+
export KEYPERSETMANAGER_ADDRESS=${KeyperSetManager}
19+
export KEYBROADCAST_ADDRESS=${KeyBroadcastContract}
20+
export ACTIVATION_DELTA=10
21+
22+
$DC run --rm --no-deps add-keyper-set
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
source ./common.sh
4+
5+
echo "Submitting bootstrap transaction"
6+
7+
$DC run --rm --no-deps --entrypoint /rolling-shutter chain-0-validator op-bootstrap fetch-keyperset \
8+
--config /config/op-bootstrap.toml
9+
10+
$DC run --rm --no-deps --entrypoint /rolling-shutter chain-0-validator op-bootstrap \
11+
--config /config/op-bootstrap.toml
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
source ./common.sh
4+
set -e
5+
6+
echo "Submitting identity registration transaction"
7+
8+
CONTRACTS_JSON=$(jq '.transactions[]|(select(.function==null))|{(.contractName|tostring): .contractAddress}' data/deployments/Deploy.service.s.sol/31337/run-latest.json)
9+
10+
for s in $(echo ${CONTRACTS_JSON} | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")| .[] "); do
11+
export $s
12+
done
13+
14+
export TIMESTAMP=$(($(date +%s) + 50))
15+
export IDENTITY_PREFIX=0x$(LC_ALL=C tr -dc 'a-f0-9' </dev/urandom | head -c64)
16+
export REGISTRY_ADDRESS=${ShutterRegistry}
17+
export EON=$($DC exec db psql -U postgres -d keyper-0 -t -c 'select max(eon) from eons;' | tr -d '[:space:]')
18+
if [[ -z $EON ]]; then
19+
echo "No eonId found in keyper-0 db. Did you run bootstrap?"
20+
exit 1
21+
fi
22+
23+
${DC} run --rm --no-deps register-identity
24+
sleep 55
25+
26+
DECRYPTION_KEY_MSGS=$(${DC} logs keyper-0 | grep ${EON} | grep -c decryptionKey)
27+
echo "DECRYPTION_KEY_MSGS: ${DECRYPTION_KEY_MSGS}"
28+
if [[ $DECRYPTION_KEY_MSGS -gt 0 ]]; then
29+
echo "Decryption successful with $DECRYPTION_KEY_MSGS / 3 nodes"
30+
exit 0
31+
else
32+
echo "Decryption failed"
33+
exit 1
34+
fi

docker-test-setup-api/90-stop.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
source ./common.sh
4+
5+
echo "Stopping entire system"
6+
$DC down
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM alpine/git AS builder
2+
3+
RUN date
4+
RUN git clone --branch=shutter-api https://github.com/shutter-network/contracts /contracts
5+
RUN cd /contracts && git submodule update --init --recursive
6+
7+
FROM --platform=linux/amd64 ghcr.io/foundry-rs/foundry AS runner
8+
WORKDIR /contracts
9+
COPY --from=builder --chown=foundry:foundry /contracts /contracts
10+
11+
RUN git config --global --add safe.directory /contracts
12+
13+
USER foundry
14+
RUN forge install
15+
RUN forge build
16+
ENTRYPOINT ["forge", "script"]

0 commit comments

Comments
 (0)