Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for delegate-feed-consent #14

Merged
merged 4 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/modules/oracle/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def query_params():
--chain-id {CHAINID} --output json"""
return exec_command(command)

def query_feeder_delegation(valAddress):
command = f"""{DAEMON} q oracle feeder-delegation {valAddress} --node {RPC} \
--chain-id {CHAINID} --output json"""
return exec_command(command)

def node_status():
command = f"{DAEMON} status --node {RPC}"
return exec_command(command)
77 changes: 61 additions & 16 deletions internal/modules/oracle/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import time
import logging
import unittest
import json
import inspect
import pathlib
from internal.modules.gov.tx import submit_and_pass_proposal
Expand All @@ -14,12 +13,14 @@
from internal.core.keys import keys_show

from modules.oracle.query import (
query_feeder_delegation,
query_params,
)

from modules.oracle.tx import (
tx_submit_prevote,
tx_submit_vote,
tx_delegate_feed_consent,
)

from modules.oracle.hash import (
Expand All @@ -46,9 +47,9 @@
validator2_home = f"{env.DAEMON_HOME}-2"
validator3_home = f"{env.DAEMON_HOME}-3"

validator1_acc = keys_show("validator1", "val")[1]
validator2_acc = keys_show("validator2", "val", validator2_home)[1]
validator3_acc = keys_show("validator3", "val", validator3_home)[1]
validator1_val = keys_show("validator1", "val")[1]
validator2_val = keys_show("validator2", "val", validator2_home)[1]
validator3_val = keys_show("validator3", "val", validator3_home)[1]

def get_block_height():
_, message = node_status()
Expand Down Expand Up @@ -78,28 +79,28 @@ def test_query_oracle_params(self):
# test_prevotes tests to make sure that we can submit prevotes
def test_prevotes(self):
# Get Hash
vote_hash_1 = get_hash(EXCHANGE_RATES.ToString(), STATIC_SALT, validator1_acc["address"])
vote_hash_2 = get_hash(EXCHANGE_RATES.ToString(), STATIC_SALT, validator2_acc["address"])
vote_hash_1 = get_hash(EXCHANGE_RATES.ToString(), STATIC_SALT, validator1_val["address"])
vote_hash_2 = get_hash(EXCHANGE_RATES.ToString(), STATIC_SALT, validator2_val["address"])

wait_for_next_voting_period()

# Submit 1st prevote
status = tx_submit_prevote(validator1_acc["name"], vote_hash_1, validator1_home)
status, prevote_1 = tx_submit_prevote(validator1_val["name"], vote_hash_1, validator1_home)
zarazan marked this conversation as resolved.
Show resolved Hide resolved
self.assertTrue(status)

# Query to verify 1st prevote exists
status, prevote_1 = query_aggregate_prevote(validator1_acc["address"])
status, prevote_1 = query_aggregate_prevote(validator1_val["address"])
self.assertTrue(status)
self.assertEqual(prevote_1["aggregate_prevote"]["hash"].upper(), vote_hash_1)

wait_for_next_voting_period()

# # Submit 2nd prevote
status = tx_submit_prevote(validator2_acc["name"], vote_hash_2, validator2_home)
status, prevote_2 = tx_submit_prevote(validator2_val["name"], vote_hash_2, validator2_home)
zarazan marked this conversation as resolved.
Show resolved Hide resolved
self.assertTrue(status)

# Query to verify 2nd prevote exists
status, prevote_2 = query_aggregate_prevote(validator2_acc["address"])
status, prevote_2 = query_aggregate_prevote(validator2_val["address"])
self.assertTrue(status)
self.assertEqual(prevote_2["aggregate_prevote"]["hash"].upper(), vote_hash_2)

Expand All @@ -108,30 +109,74 @@ def test_prevotes(self):
# test_votes tests to make sure that we can submit votes
def test_votes(self):
# Get Hash
vote_hash = get_hash(EXCHANGE_RATES.ToString(), STATIC_SALT, validator3_acc["address"])
vote_hash = get_hash(EXCHANGE_RATES.ToString(), STATIC_SALT, validator3_val["address"])

wait_for_next_voting_period()

# Submit prevote
status, prevote_1 = tx_submit_prevote(validator3_acc["name"], vote_hash, validator3_home)
status, prevote_1 = tx_submit_prevote(validator3_val["name"], vote_hash, validator3_home)
self.assertTrue(status)

# Wait until next voting period
time.sleep(1.5)
time.sleep(1.5) # Wait until next voting period

# Submit vote
status, vote_1 = tx_submit_vote(validator3_acc["name"], STATIC_SALT, validator3_home, EXCHANGE_RATES.ToString())
status, vote_1 = tx_submit_vote(validator3_val["name"], STATIC_SALT, validator3_home, EXCHANGE_RATES.ToString())
self.assertTrue(status)

# Query votes to make sure they exist, and are correct
status, vote_1 = query_aggregate_vote(validator3_acc["address"])
status, vote_1 = query_aggregate_vote(validator3_val["address"])
self.assertTrue(status)

self.assertEqual(len(vote_1["aggregate_vote"]["exchange_rate_tuples"]), EXCHANGE_RATES.Len())

for rate in vote_1["aggregate_vote"]["exchange_rate_tuples"]:
self.assertEqual(float(rate["exchange_rate"]), float(EXCHANGE_RATES.GetRate(rate["denom"])))

# Test delegating feed consent from operator to delegate,
# then submit voting from delegate on behalf of operator
def test_delegate_feed_consent(self):
operator_name = validator1_val["name"]
operator_val_address = validator1_val["address"]
operator_home = validator1_home

# Using a non-validator account
sender = keys_show("account2")[1]
delegate_name = sender["name"]
delegate_home = validator1_home
delegate_acc_address = sender["address"]

status, response = tx_delegate_feed_consent(operator_name, delegate_acc_address, operator_home)
self.assertTrue(status)

# Test query route and verify feeder is delegated correctly
status, response = query_feeder_delegation(operator_val_address)
self.assertTrue(status)
self.assertEqual(delegate_acc_address, response["feeder_addr"])

vote_hash = get_hash(EXCHANGE_RATES.ToString(), STATIC_SALT, operator_val_address)

wait_for_next_voting_period()

status = tx_submit_prevote(delegate_name, vote_hash, delegate_home, operator_val_address)
self.assertTrue(status)

status, response = query_aggregate_prevote(operator_val_address)
self.assertTrue(status)

time.sleep(1.5) # Wait until next voting period

status = tx_submit_vote(
delegate_name,
STATIC_SALT,
validator1_home,
EXCHANGE_RATES.ToString(),
operator_val_address
)
self.assertTrue(status)

status = query_aggregate_vote(validator1_val["address"])
self.assertTrue(status)

# test_hash makes sure our hasher is accurate
def test_hash(self):
hash = get_hash("ATOM:11.1,USDT:1.00001", "salt", "umeevaloper1zypqa76je7pxsdwkfah6mu9a583sju6xjettez")
Expand Down
35 changes: 27 additions & 8 deletions internal/modules/oracle/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
RPC = env.RPC
CHAINID = env.CHAINID
DEFAULT_GAS = env.DEFAULT_GAS
DEFAULT_BROADCAST_MODE = "block"

# tx_submit_prevote submits an aggregate prevote tx given a hash and
# feeder address.
def tx_submit_prevote(
from_key,
hash,
home,
broadcast_mode='block',
validator="",
broadcast_mode=DEFAULT_BROADCAST_MODE,
gas=DEFAULT_GAS,
):
command = f"""{DAEMON} tx oracle exchange-rate-prevote {hash} \
--chain-id {CHAINID} --keyring-backend test \
--home {home} --from {from_key} --node {RPC} --output json -y --gas {gas} -b {broadcast_mode}"""
command = f"""{DAEMON} tx oracle exchange-rate-prevote {hash} {validator} \
--chain-id {CHAINID} --keyring-backend test \
--home {home} --from {from_key} --node {RPC} --output json \
--gas {gas} -b {broadcast_mode} -y"""
return exec_command(command)

# tx_submit_vote submits an aggregate vote tx given a salt, exchange
Expand All @@ -27,10 +30,26 @@ def tx_submit_vote(
salt,
home,
exchange_rates,
broadcast_mode='block',
validator="",
broadcast_mode=DEFAULT_BROADCAST_MODE,
gas=DEFAULT_GAS,
):
command = f"""{DAEMON} tx oracle exchange-rate-vote {salt} {exchange_rates} \
--chain-id {CHAINID} --keyring-backend test \
--home {home} --from {from_key} --node {RPC} --output json -y --gas {gas} -b {broadcast_mode}"""
command = f"""{DAEMON} tx oracle exchange-rate-vote {salt} {exchange_rates} {validator} \
--chain-id {CHAINID} --keyring-backend test \
--home {home} --from {from_key} --node {RPC} --output json \
--gas {gas} -b {broadcast_mode} -y"""
return exec_command(command)

# tx_delegate_feed_consent submits a tx
def tx_delegate_feed_consent(
operator,
delegate,
home,
broadcast_mode=DEFAULT_BROADCAST_MODE,
gas=DEFAULT_GAS,
):
command = f"""{DAEMON} tx oracle delegate-feed-consent {operator} {delegate} \
--chain-id {CHAINID} --keyring-backend test \
--home {home} --from {operator} --node {RPC} --output json \
--gas {gas} -b {broadcast_mode} -y"""
return exec_command(command)