Skip to content

Commit

Permalink
Update nix flake and remaining misbehaviour tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 committed Nov 1, 2023
1 parent f9b2834 commit 190862d
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 65 deletions.
52 changes: 39 additions & 13 deletions ci/misbehaviour-ics/double_sign_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ do

# Build genesis file and node directory structure
interchain-security-pd init $MONIKER --chain-id provider --home ${PROV_NODE_DIR}
jq ".app_state.gov.voting_params.voting_period = \"10s\" | .app_state.staking.params.unbonding_time = \"86400s\"" \
jq ".app_state.gov.params.voting_period = \"5s\" | .app_state.staking.params.unbonding_time = \"86400s\"" \
${PROV_NODE_DIR}/config/genesis.json > \
${PROV_NODE_DIR}/edited_genesis.json && mv ${PROV_NODE_DIR}/edited_genesis.json ${PROV_NODE_DIR}/config/genesis.json

Expand All @@ -99,10 +99,10 @@ do

# Add stake to user
PROV_ACCOUNT_ADDR=$(jq -r '.address' ${PROV_NODE_DIR}/${PROV_KEY}.json)
interchain-security-pd add-genesis-account $PROV_ACCOUNT_ADDR $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test
interchain-security-pd genesis add-genesis-account $PROV_ACCOUNT_ADDR $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test

PROV_ACCOUNT_ADDR2=$(jq -r '.address' ${PROV_NODE_DIR}/${PROV_KEY2}.json)
interchain-security-pd add-genesis-account $PROV_ACCOUNT_ADDR2 $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test
interchain-security-pd genesis add-genesis-account $PROV_ACCOUNT_ADDR2 $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test
sleep 1

# copy genesis out, unless this validator is the lead validator
Expand Down Expand Up @@ -141,7 +141,7 @@ do
fi

# Stake 1/1000 user's coins
interchain-security-pd gentx $PROV_KEY $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER
interchain-security-pd genesis gentx $PROV_KEY $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER
sleep 1

# Copy gentxs to the lead validator for possible future collection.
Expand All @@ -152,7 +152,7 @@ do
done

# Collect genesis transactions with lead validator
interchain-security-pd collect-gentxs --home ${LEAD_VALIDATOR_PROV_DIR} --gentx-dir ${LEAD_VALIDATOR_PROV_DIR}/config/gentx/
interchain-security-pd genesis collect-gentxs --home ${LEAD_VALIDATOR_PROV_DIR} --gentx-dir ${LEAD_VALIDATOR_PROV_DIR}/config/gentx/

sleep 1

Expand Down Expand Up @@ -222,7 +222,7 @@ done
tee ${LEAD_VALIDATOR_PROV_DIR}/consumer-proposal.json<<EOF
{
"title": "Create a chain",
"description": "Gonna be a great chain",
"summary": "Gonna be a great chain",
"chain_id": "consumer",
"initial_height": {
"revision_height": 1
Expand All @@ -244,9 +244,9 @@ sleep 5
interchain-security-pd keys show $LEAD_PROV_KEY --keyring-backend test --home ${LEAD_VALIDATOR_PROV_DIR}

# Submit consumer chain proposal
interchain-security-pd tx gov submit-proposal consumer-addition ${LEAD_VALIDATOR_PROV_DIR}/consumer-proposal.json --chain-id provider --from $LEAD_PROV_KEY --home ${LEAD_VALIDATOR_PROV_DIR} --node $LEAD_PROV_LISTEN_ADDR --keyring-backend test -b block -y --gas auto
interchain-security-pd tx gov submit-legacy-proposal consumer-addition ${LEAD_VALIDATOR_PROV_DIR}/consumer-proposal.json --chain-id provider --from $LEAD_PROV_KEY --home ${LEAD_VALIDATOR_PROV_DIR} --node $LEAD_PROV_LISTEN_ADDR --keyring-backend test -y --gas auto

sleep 1
sleep 3

# Vote yes to proposal
for index in "${!MONIKERS[@]}"
Expand All @@ -257,18 +257,44 @@ do
RPC_LADDR=tcp://${NODE_IP}:${RPC_LADDR_PORT}

PROV_NODE_DIR=${PROV_NODES_ROOT_DIR}/provider-${MONIKER}
interchain-security-pd tx gov vote 1 yes --from $PROV_KEY --chain-id provider --home ${PROV_NODE_DIR} --node $RPC_LADDR -b block -y --keyring-backend test
interchain-security-pd tx gov vote 1 yes --from $PROV_KEY --chain-id provider --home ${PROV_NODE_DIR} --node $RPC_LADDR -y --keyring-backend test
done

HERMES_PROV_NODE_DIR=${PROV_NODES_ROOT_DIR}/provider-${HERMES_VALIDATOR_MONIKER}
HERMES_KEY=${HERMES_VALIDATOR_MONIKER}-key
HERMES_KEY2=${HERMES_VALIDATOR_MONIKER}-key2
HERMES_CONS_NODE_DIR=${CONS_NODES_ROOT_DIR}/consumer-${HERMES_VALIDATOR_MONIKER}

# sleep 3

# # ## CONSUMER CHAIN ##

### Assert that the proposal for the consumer chain passed
PROPOSAL_STATUS_PASSED="PROPOSAL_STATUS_PASSED"
MAX_TRIES=10
TRIES=0

cat ${PROV_NODE_DIR}/config/genesis.json | grep "period"

while [ $TRIES -lt $MAX_TRIES ]; do
output=$(interchain-security-pd query gov proposal 1 --home ${LEAD_VALIDATOR_PROV_DIR} --node $LEAD_PROV_LISTEN_ADDR --output json)

proposal_status=$(echo "$output" | grep -o '"status":"[^"]*' | awk -F ':"' '{print $2}')
if [ "$proposal_status" = "$PROPOSAL_STATUS_PASSED" ]; then
echo "Proposal status is now $proposal_status. Exiting loop."
break
else
echo "Proposal status is $proposal_status. Continuing to check..."
fi
((TRIES++))

sleep 2
done

if [ $TRIES -eq $MAX_TRIES ]; then
echo "[ERROR] Failed due to an issue with the consumer proposal"
echo "This is likely due to a misconfiguration in the test script."
exit 0
fi

# # Clean start
for index in "${!MONIKERS[@]}"
do
Expand Down Expand Up @@ -299,9 +325,9 @@ do

# Add stake to user
CONS_ACCOUNT_ADDR=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY}.json)
interchain-security-cd add-genesis-account $CONS_ACCOUNT_ADDR $USER_COINS --home ${CONS_NODE_DIR}
interchain-security-cd genesis add-genesis-account $CONS_ACCOUNT_ADDR $USER_COINS --home ${CONS_NODE_DIR}
CONS_ACCOUNT_ADDR2=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY2}.json)
interchain-security-cd add-genesis-account $CONS_ACCOUNT_ADDR2 $USER_COINS --home ${CONS_NODE_DIR}
interchain-security-cd genesis add-genesis-account $CONS_ACCOUNT_ADDR2 $USER_COINS --home ${CONS_NODE_DIR}
sleep 10

### this probably doesnt have to be done for each node
Expand Down
36 changes: 32 additions & 4 deletions ci/misbehaviour-ics/light_client_attack_freeze_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fi
HERMES_CONFIG="$HOME_DIR/hermes.toml"
HERMES_CONFIG_FORK="$HOME_DIR/hermes-fork.toml"
# Hermes binary
HERMES_BIN=cargo run -q --bin hermes -- $HERMES_DEBUG --config $HERMES_CONFIG
HERMES_BIN_FORK=cargo run -q --bin hermes -- $HERMES_DEBUG --config $HERMES_CONFIG_FORK
HERMES_BIN="cargo run -q --bin hermes -- $HERMES_DEBUG --config $HERMES_CONFIG"
HERMES_BIN_FORK="cargo run -q --bin hermes -- $HERMES_DEBUG --config $HERMES_CONFIG_FORK"

# Validator moniker
MONIKER="coordinator"
Expand Down Expand Up @@ -191,10 +191,38 @@ waiting 3 "for proposal to be submitted"
# Vote yes to proposal
interchain-security-pd tx gov vote 1 yes --from $PROV_KEY --chain-id provider --home ${PROV_NODE_DIR} -y --keyring-backend test

waiting 10 "for proposal to be voted on"

# CONSUMER CHAIN ##

### Assert that the proposal for the consumer chain passed
PROPOSAL_STATUS_PASSED="PROPOSAL_STATUS_PASSED"
MAX_TRIES=10
TRIES=0

cat ${PROV_NODE_DIR}/config/genesis.json | grep "period"

while [ $TRIES -lt $MAX_TRIES ]; do
output=$(interchain-security-pd query gov proposal 1 --home ${PROV_NODE_DIR} --node tcp://${NODE_IP}:26658 --output json)

proposal_status=$(echo "$output" | grep -o '"status":"[^"]*' | awk -F ':"' '{print $2}')
if [ "$proposal_status" = "$PROPOSAL_STATUS_PASSED" ]; then
echo "Proposal status is now $proposal_status. Exiting loop."
break
else
echo "Proposal status is $proposal_status. Continuing to check..."
fi
((TRIES++))

sleep 2
done

if [ $TRIES -eq $MAX_TRIES ]; then
echo "[ERROR] Failed due to an issue with the consumer proposal"
echo "This is likely due to a misconfiguration in the test script."
exit 0
fi

waiting 3 "for passed proposal to be executed"

# Build genesis file and node directory structure
interchain-security-cd init $MONIKER --chain-id consumer --home ${CONS_NODE_DIR}

Expand Down
65 changes: 44 additions & 21 deletions ci/misbehaviour-ics/light_client_attack_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ rm -rf "${CONS_FORK_NODE_DIR}"

# Build genesis file and node directory structure
interchain-security-pd init $MONIKER --chain-id provider --home ${PROV_NODE_DIR}
jq ".app_state.gov.voting_params.voting_period = \"3s\" | .app_state.staking.params.unbonding_time = \"86400s\"" \
jq ".app_state.gov.params.voting_period = \"5s\" | .app_state.staking.params.unbonding_time = \"86400s\"" \
${PROV_NODE_DIR}/config/genesis.json > \
${PROV_NODE_DIR}/edited_genesis.json && mv ${PROV_NODE_DIR}/edited_genesis.json ${PROV_NODE_DIR}/config/genesis.json

Expand All @@ -94,10 +94,10 @@ interchain-security-pd keys add $PROV_KEY --home ${PROV_NODE_DIR} --keyring-back

# Add stake to user
PROV_ACCOUNT_ADDR=$(jq -r '.address' ${PROV_NODE_DIR}/${PROV_KEY}.json)
interchain-security-pd add-genesis-account "$PROV_ACCOUNT_ADDR" $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test
interchain-security-pd genesis add-genesis-account "$PROV_ACCOUNT_ADDR" $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test

# Stake 1/1000 user's coins
interchain-security-pd gentx $PROV_KEY $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER
interchain-security-pd genesis gentx $PROV_KEY $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER

## config second node

Expand All @@ -116,30 +116,28 @@ cp ${PROV_NODE_DIR}/config/genesis.json ${PROV_NODE_SUB_DIR}/config/genesis.jso

# Add stake to user
PROV_ACCOUNT_ADDR=$(jq -r '.address' ${PROV_NODE_SUB_DIR}/${PROV_KEY_SUB}.json)
interchain-security-pd add-genesis-account "$PROV_ACCOUNT_ADDR" $USER_COINS --home ${PROV_NODE_SUB_DIR} --keyring-backend test
interchain-security-pd genesis add-genesis-account "$PROV_ACCOUNT_ADDR" $USER_COINS --home ${PROV_NODE_SUB_DIR} --keyring-backend test
waiting 1 ""



cp -r ${PROV_NODE_DIR}/config/gentx/ ${PROV_NODE_SUB_DIR}/config/gentx/

# # Stake 1/1000 user's coins
interchain-security-pd gentx $PROV_KEY_SUB $STAKE2 --chain-id provider --home ${PROV_NODE_SUB_DIR} --keyring-backend test --moniker $MONIKER_SUB
interchain-security-pd genesis gentx $PROV_KEY_SUB $STAKE2 --chain-id provider --home ${PROV_NODE_SUB_DIR} --keyring-backend test --moniker $MONIKER_SUB
waiting 1 ""


interchain-security-pd collect-gentxs --home ${PROV_NODE_SUB_DIR} --gentx-dir ${PROV_NODE_SUB_DIR}/config/gentx/
interchain-security-pd genesis collect-gentxs --home ${PROV_NODE_SUB_DIR} --gentx-dir ${PROV_NODE_SUB_DIR}/config/gentx/

cp ${PROV_NODE_SUB_DIR}/config/genesis.json ${PROV_NODE_DIR}/config/genesis.json



# Start nodes

sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${NODE_IP}:26658\"/" ${PROV_NODE_DIR}/config/client.toml
sed -i -r 's/timeout_commit = "5s"/timeout_commit = "3s"/g' ${PROV_NODE_DIR}/config/config.toml
sed -i -r 's/timeout_propose = "3s"/timeout_propose = "1s"/g' ${PROV_NODE_DIR}/config/config.toml
sed -i -r 's/fast_sync = true/fast_sync = false/g' ${PROV_NODE_DIR}/config/config.toml
sed -i -r 's/block_sync = true/block_sync = false/g' ${PROV_NODE_DIR}/config/config.toml



Expand All @@ -157,9 +155,7 @@ waiting 5 "for provider node to start"
sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${NODE_IP}:26628\"/" ${PROV_NODE_SUB_DIR}/config/client.toml
sed -i -r 's/timeout_commit = "5s"/timeout_commit = "3s"/g' ${PROV_NODE_SUB_DIR}/config/config.toml
sed -i -r 's/timeout_propose = "3s"/timeout_propose = "1s"/g' ${PROV_NODE_SUB_DIR}/config/config.toml
sed -i -r 's/fast_sync = true/fast_sync = false/g' ${PROV_NODE_SUB_DIR}/config/config.toml


sed -i -r 's/block_sync = true/block_sync = false/g' ${PROV_NODE_SUB_DIR}/config/config.toml

# # Start gaia
interchain-security-pd start \
Expand All @@ -176,7 +172,7 @@ waiting 5 "for provider sub-node to start"
tee ${PROV_NODE_DIR}/consumer-proposal.json<<EOF
{
"title": "Create a chain",
"description": "Gonna be a great chain",
"summary": "Gonna be a great chain",
"chain_id": "consumer",
"initial_height": {
"revision_height": 1
Expand All @@ -197,17 +193,45 @@ EOF
interchain-security-pd keys show $PROV_KEY --keyring-backend test --home ${PROV_NODE_DIR}

# Submit consumer chain proposal
interchain-security-pd tx gov submit-proposal consumer-addition ${PROV_NODE_DIR}/consumer-proposal.json --chain-id provider --from $PROV_KEY --home ${PROV_NODE_DIR} --node tcp://${NODE_IP}:26658 --keyring-backend test -b block -y
interchain-security-pd tx gov submit-legacy-proposal consumer-addition ${PROV_NODE_DIR}/consumer-proposal.json --chain-id provider --from $PROV_KEY --home ${PROV_NODE_DIR} --node tcp://${NODE_IP}:26658 --keyring-backend test -y --gas auto

waiting 1 "for proposal to be submitted"
waiting 3 "for proposal to be submitted"

# Vote yes to proposal
interchain-security-pd tx gov vote 1 yes --from $PROV_KEY --chain-id provider --home ${PROV_NODE_DIR} -b block -y --keyring-backend test

waiting 3 "for proposal to be voted on"
interchain-security-pd tx gov vote 1 yes --from $PROV_KEY --chain-id provider --home ${PROV_NODE_DIR} -y --keyring-backend test

# CONSUMER CHAIN ##

### Assert that the proposal for the consumer chain passed
PROPOSAL_STATUS_PASSED="PROPOSAL_STATUS_PASSED"
MAX_TRIES=10
TRIES=0

cat ${PROV_NODE_DIR}/config/genesis.json | grep "period"

while [ $TRIES -lt $MAX_TRIES ]; do
output=$(interchain-security-pd query gov proposal 1 --home ${PROV_NODE_DIR} --node tcp://${NODE_IP}:26658 --output json)

proposal_status=$(echo "$output" | grep -o '"status":"[^"]*' | awk -F ':"' '{print $2}')
if [ "$proposal_status" = "$PROPOSAL_STATUS_PASSED" ]; then
echo "Proposal status is now $proposal_status. Exiting loop."
break
else
echo "Proposal status is $proposal_status. Continuing to check..."
fi
((TRIES++))

sleep 2
done

if [ $TRIES -eq $MAX_TRIES ]; then
echo "[ERROR] Failed due to an issue with the consumer proposal"
echo "This is likely due to a misconfiguration in the test script."
exit 0
fi

waiting 3 "for passed proposal to be executed"

# Build genesis file and node directory structure
interchain-security-cd init $MONIKER --chain-id consumer --home ${CONS_NODE_DIR}
waiting 1 ""
Expand All @@ -217,7 +241,7 @@ interchain-security-cd keys add $PROV_KEY --home ${CONS_NODE_DIR} --keyring-bac

# Add stake to user account
CONS_ACCOUNT_ADDR=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY}.json)
interchain-security-cd add-genesis-account "$CONS_ACCOUNT_ADDR" 1000000000stake --home ${CONS_NODE_DIR}
interchain-security-cd genesis add-genesis-account "$CONS_ACCOUNT_ADDR" 1000000000stake --home ${CONS_NODE_DIR}

# Add consumer genesis states to genesis file
interchain-security-pd query provider consumer-genesis consumer --home ${PROV_NODE_DIR} -o json > consumer_gen.json
Expand All @@ -234,8 +258,7 @@ cp ${PROV_NODE_DIR}/config/node_key.json ${CONS_NODE_DIR}/config/node_key.json

# Set default client port
sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${NODE_IP}:26648\"/" ${CONS_NODE_DIR}/config/client.toml
sed -i -r 's/fast_sync = true/fast_sync = false/g' ${CONS_NODE_DIR}/config/config.toml

sed -i -r 's/block_sync = true/block_sync = false/g' ${CONS_NODE_DIR}/config/config.toml

# Start gaia
interchain-security-cd start --home ${CONS_NODE_DIR} \
Expand Down
Loading

0 comments on commit 190862d

Please sign in to comment.