Skip to content

Commit

Permalink
add multiple voters to index votes test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchristo committed Aug 31, 2023
1 parent 22ff3b7 commit bbb7aca
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 125 deletions.
13 changes: 7 additions & 6 deletions docker/ledger.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ RUN sed -i "s/stake/uregen/g" /root/.regen/config/genesis.json

# Add accounts
RUN printf "trouble alarm laptop turn call stem lend brown play planet grocery survey smooth seed describe hood praise whale smile repeat dry sauce front future\n\n" | regen keys --keyring-backend test add validator -i
RUN printf "cool trust waste core unusual report duck amazing fault juice wish century across ghost cigar diary correct draw glimpse face crush rapid quit equip\n\n" | regen keys --keyring-backend test add user -i
RUN printf "cool trust waste core unusual report duck amazing fault juice wish century across ghost cigar diary correct draw glimpse face crush rapid quit equip\n\n" | regen keys --keyring-backend test add user1 -i
RUN printf "music debris chicken erode flag law demise over fall always put bounce ring school dumb ivory spin saddle ostrich better seminar heart beach kingdom\n\n" | regen keys --keyring-backend test add user2 -i

# Set up validator
RUN regen add-genesis-account validator 1000000000uregen --keyring-backend test
RUN regen gentx validator 1000000uregen

# Set up test acount
RUN regen add-genesis-account user 1000000000uregen --keyring-backend test
# Set up user acounts
RUN regen add-genesis-account user1 1000000000uregen --keyring-backend test
RUN regen add-genesis-account user2 1000000000uregen --keyring-backend test

# Prepare genesis file
RUN regen collect-gentxs

# Set minimum gas price
RUN sed -i "s/minimum-gas-prices = \"\"/minimum-gas-prices = \"0uregen\"/" /root/.regen/config/app.toml

# Set pruning to everything
RUN sed -i "s/pruning = \"default\"/pruning = \"everything\"/" /root/.regen/config/app.toml

# Set cors allow all origins
RUN sed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = [\"*\"]/" /root/.regen/config/config.toml

Expand Down
121 changes: 2 additions & 119 deletions docker/scripts/tester_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,128 +2,11 @@

set -eo pipefail

# test account address
address=regen1l2pwmzk96ftmmt5egpjulyqtneygmmzndf7csk

# transaction flags
regen_tx_flags="--from $address --keyring-backend test --chain-id regen-local --yes"

# wait for indexer to start
sleep 5

##################################################
# index_blocks.py
##################################################

# TODO

##################################################
# index_class_issuers.py
##################################################

# TODO

##################################################
# index_proposals.py
##################################################

# TODO

##################################################
# index_retires.py
##################################################

# TODO

##################################################
# index_votes.py
##################################################

# set group members json
cat > members.json <<EOL
{
"members": [
{
"address": "$address",
"weight": "1",
"metadata": ""
}
]
}
EOL

# create test group
regen tx group create-group "$address" "" members.json $regen_tx_flags

# wait for transaction to be processed
sleep 10

# set group policy json
cat > policy.json <<EOL
{
"@type": "/cosmos.group.v1.ThresholdDecisionPolicy",
"threshold": "1",
"windows": {
"voting_period": "20s",
"min_execution_period": "0s"
}
}
EOL

# create test group policy
regen tx group create-group-policy "$address" 1 "" policy.json $regen_tx_flags

# wait for transaction to be processed
sleep 10

# set group policy address
policy_address=$(regen q group group-policies-by-group 1 --output json | jq -r '.group_policies[-1].address')

# set group proposal json
cat > proposal.json <<EOL
{
"group_policy_address": "$policy_address",
"messages": [],
"metadata": "",
"proposers": ["$address"]
}
EOL

# create group proposal
regen tx group submit-proposal proposal.json $regen_tx_flags

# wait for transaction to be processed
sleep 10

# set proposal id
proposal_id=$(regen q group proposals-by-group-policy "$policy_address" --output json | jq -r '.proposals[-1].id')

# vote "yes" on proposal
regen tx group vote "$proposal_id" "$address" VOTE_OPTION_YES "" $regen_tx_flags

# wait for transaction to be processed
sleep 10

# TODO: confirm vote indexed in database
psql postgres://postgres:password@localhost:5432/postgres -c "SELECT * from votes;"
# TODO: if vote found, then exit 1

# wait for voting period to end
sleep 10

# execute proposal
regen tx group exec "$proposal_id" $regen_tx_flags

# wait for transaction to be processed
sleep 10

# TODO: confirm proposal indexed in database
psql postgres://postgres:password@localhost:5432/postgres -c "SELECT * from proposals;"
# TODO: if proposal not found, then exit 1

# TODO: confirm vote indexed in database
psql postgres://postgres:password@localhost:5432/postgres -c "SELECT * from votes;"
# TODO: if vote not found, then exit 1
# run tester test scripts
/home/tester/scripts/test_index_votes.sh

# exit without error
exit 0
6 changes: 6 additions & 0 deletions docker/tester.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ RUN printf "cool trust waste core unusual report duck amazing fault juice wish c
# Copy tester start script
COPY docker/scripts/tester_start.sh /home/tester/scripts/

# Copy tester test scripts
COPY docker/tester/ /home/tester/scripts/

# Make start script executable
RUN ["chmod", "+x", "/home/tester/scripts/tester_start.sh"]

# Make test scripts executable
RUN ["chmod", "+x", "/home/tester/scripts/test_index_votes.sh"]
106 changes: 106 additions & 0 deletions docker/tester/test_index_votes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash

# test account address
address1=regen1l2pwmzk96ftmmt5egpjulyqtneygmmzndf7csk
address2=regen14v5z5yyl5unnyu6q3ele8ze9jev6y0m7tx6gct

# transaction flags
regen_tx_flags="--keyring-backend test --chain-id regen-local --yes"

# set group members json
cat > members.json <<EOL
{
"members": [
{
"address": "$address1",
"weight": "1",
"metadata": ""
},
{
"address": "$address2",
"weight": "1",
"metadata": ""
}
]
}
EOL

# create test group
regen tx group create-group "$address1" "" members.json --from "$address1" $regen_tx_flags

# wait for transaction to be processed
sleep 10

# set group policy json
cat > policy.json <<EOL
{
"@type": "/cosmos.group.v1.ThresholdDecisionPolicy",
"threshold": "2",
"windows": {
"voting_period": "20s",
"min_execution_period": "0s"
}
}
EOL

# create test group policy
regen tx group create-group-policy "$address1" 1 "" policy.json --from "$address1" $regen_tx_flags

# wait for transaction to be processed
sleep 10

# set group policy address
policy_address=$(regen q group group-policies-by-group 1 --output json | jq -r '.group_policies[-1].address')

# set group proposal json
cat > proposal.json <<EOL
{
"group_policy_address": "$policy_address",
"messages": [],
"metadata": "",
"proposers": ["$address1"]
}
EOL

# create group proposal
regen tx group submit-proposal proposal.json --from "$address1" $regen_tx_flags

# wait for transaction to be processed
sleep 10

# set proposal id
proposal_id=$(regen q group proposals-by-group-policy "$policy_address" --output json | jq -r '.proposals[-1].id')

# vote "yes" on proposal with user 1
regen tx group vote "$proposal_id" "$address1" VOTE_OPTION_YES "" --from "$address1" $regen_tx_flags

# wait for transaction to be processed
sleep 10

# TODO: confirm vote NOT indexed in database
psql postgres://postgres:password@localhost:5432/postgres -c "SELECT * from votes;"
# TODO: if vote found, then exit 1

# vote "yes" on proposal with user 2
regen tx group vote "$proposal_id" "$address1" VOTE_OPTION_YES "" --from "$address2" $regen_tx_flags

# wait for transaction to be processed and voting period to end
sleep 10

# TODO: confirm vote NOT indexed in database
psql postgres://postgres:password@localhost:5432/postgres -c "SELECT * from votes;"
# TODO: if vote found, then exit 1

# execute proposal
regen tx group exec "$proposal_id" --from "$address1" $regen_tx_flags

# wait for transaction to be processed
sleep 10

# TODO: confirm proposal indexed in database
psql postgres://postgres:password@localhost:5432/postgres -c "SELECT * from proposals;"
# TODO: if proposal NOT found, then exit 1

# TODO: confirm vote indexed in database
psql postgres://postgres:password@localhost:5432/postgres -c "SELECT * from votes;"
# TODO: if vote NOT found, then exit 1

0 comments on commit bbb7aca

Please sign in to comment.