Skip to content

Commit

Permalink
test: fixtests. Updated perp_test so that error log shows if oracle i…
Browse files Browse the repository at this point in the history
…s not running. (#234)

* chore: delete unused variable

* test: default to using env vars for network setup

* fix: sdk.Coin amount precision

* refactor: message_to_dict refactor

* chore: bump project version

* chore: bump project version to 19.5

* chore: remove unused functions

* fix: auth test

* refactor: clean up code smells

* chore: bump version

* test: fixtests. Updated perp_test so that error log shows if oracle is not running.

* ci: Run tests on release branches

* Removed lcd_endpoint

* tests: Removed unused env variables

* Removed flake8

* fix pre-commit bug

* Added localnet.sh

---------

Co-authored-by: Kevin Yang <[email protected]>
  • Loading branch information
AnishP15 and k-yang authored Jun 23, 2023
1 parent 0f8b9a8 commit 2e9a915
Show file tree
Hide file tree
Showing 24 changed files with 887 additions and 845 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name: Linting
on:
push:
branches:
- master
branches: ["master"]
pull_request:
branches:
- master
branches: ["master"]


jobs:
test:
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/pytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: E2E 🐍 tests

on:
pull_request:
branches: ["master"]
branches: ["master", "release/*"]
paths:
[
"**.py",
Expand All @@ -11,7 +11,7 @@ on:
".github/workflows/pytests.yml",
]
push:
branches: ["master"]
branches: ["master", "release/*"]
paths:
[
"**.py",
Expand All @@ -29,11 +29,11 @@ jobs:
runs-on: ubuntu-latest
env:
# https://www.notion.so/nibiru/Resources-and-Repo-Configs-b31aa8074a2b419d80b0c946ed5efab0
LCD_ENDPOINT: ${{ secrets.LCD_ENDPOINT }}
GRPC_ENDPOINT: ${{ secrets.GRPC_ENDPOINT }}
TENDERMINT_RPC_ENDPOINT: ${{ secrets.TENDERMINT_RPC_ENDPOINT }}
WEBSOCKET_ENDPOINT: ${{ secrets.WEBSOCKET_ENDPOINT }}
CHAIN_ID: ${{ secrets.CHAIN_ID }}
# LCD_ENDPOINT: ${{ secrets.LCD_ENDPOINT }}
# GRPC_ENDPOINT: ${{ secrets.GRPC_ENDPOINT }}
# TENDERMINT_RPC_ENDPOINT: ${{ secrets.TENDERMINT_RPC_ENDPOINT }}
# WEBSOCKET_ENDPOINT: ${{ secrets.WEBSOCKET_ENDPOINT }}
# CHAIN_ID: ${{ secrets.CHAIN_ID }}
VALIDATOR_MNEMONIC: ${{ secrets.VALIDATOR_MNEMONIC }}
DEVNET_NUMBER: ${{ secrets.DEVNET_NUMBER }}
steps:
Expand All @@ -42,6 +42,13 @@ jobs:
# ----------------------------------------------
- name: Check out the repo
uses: actions/checkout@v3
- name: Install nibid
run: curl -s https://get.nibiru.fi/@v0.19.2! | bash
# Use https://get.nibiru.fi/ to get the most recent release.
- name: Run localnet.sh in the background
run: |
sh scripts/localnet.sh &
- name: Set up Python (3.8)
id: setup-python
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/floatingpurr/sync_with_poetry
rev: "0.4.0" # the revision or tag to clone at
rev: "" # the revision or tag to clone at
hooks:
- id: sync_with_poetry
args: [] # optional args
Expand Down
5 changes: 5 additions & 0 deletions examples/colab_notebook.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
4 changes: 2 additions & 2 deletions nibiru/grpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def get_bank_balances(self, address: str) -> dict:
Returns
dict: balances for each coin
"""
return query_clients.deserialize(
return query_clients.message_to_dict(
self.stubBank.AllBalances(
bank_query.QueryAllBalancesRequest(address=address)
)
Expand All @@ -370,7 +370,7 @@ def get_bank_balance(self, address: str, denom: str) -> dict:
Returns:
dict: balance for the coin with denom, 'denom'
"""
return query_clients.deserialize(
return query_clients.message_to_dict(
self.stubBank.Balance(
bank_query.QueryBalanceRequest(address=address, denom=denom)
)
Expand Down
6 changes: 3 additions & 3 deletions nibiru/query_clients/perp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from nibiru_proto.proto.perp.v1 import query_pb2 as perp_type
from nibiru_proto.proto.perp.v1 import query_pb2_grpc as perp_query

from nibiru.query_clients.util import QueryClient, deserialize
from nibiru.query_clients.util import QueryClient, message_to_dict
from nibiru.utils import from_sdk_dec


Expand Down Expand Up @@ -98,7 +98,7 @@ def position(self, pair: str, trader: str) -> dict:
api_callable=self.api.QueryPosition, req=req, should_deserialize=False
)

return deserialize(proto_output)
return message_to_dict(proto_output)

def all_positions(self, trader: str) -> Dict[str, dict]:
"""
Expand Down Expand Up @@ -138,7 +138,7 @@ def all_positions(self, trader: str) -> Dict[str, dict]:
proto_output: perp_type.QueryPositionsResponse = self.query(
api_callable=self.api.QueryPositions, req=req, should_deserialize=False
)
proto_as_dict: dict[str, list] = deserialize(proto_output)
proto_as_dict: dict[str, list] = message_to_dict(proto_output)

position_resps: Union[List[dict], None] = proto_as_dict.get("positions")
if position_resps is None:
Expand Down
36 changes: 9 additions & 27 deletions nibiru/query_clients/spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,9 @@ def pools(self, **kwargs):
output = {}

return format_fields_nested(
object=format_fields_nested(
object=output,
fn=lambda x: from_sdk_dec_n(x, 18),
fields=["swapFee", "exitFee"],
),
fn=lambda x: from_sdk_dec_n(x, 6),
fields=["amount"],
object=output,
fn=lambda x: from_sdk_dec_n(x, 18),
fields=["swapFee", "exitFee"],
)

def total_liquidity(self) -> dict:
Expand Down Expand Up @@ -164,9 +160,7 @@ def total_liquidity(self) -> dict:
)

output = MessageToDict(proto_output)
return format_fields_nested(
object=output, fn=lambda x: from_sdk_dec_n(x, 6), fields=["amount"]
)
return output

def total_pool_liquidity(self, pool_id: int) -> dict:
"""
Expand Down Expand Up @@ -200,9 +194,7 @@ def total_pool_liquidity(self, pool_id: int) -> dict:
)

output = MessageToDict(proto_output)
return format_fields_nested(
object=output, fn=lambda x: from_sdk_dec_n(x, 6), fields=["amount"]
)
return output

def total_shares(self, pool_id: int) -> dict:
"""
Expand Down Expand Up @@ -230,9 +222,7 @@ def total_shares(self, pool_id: int) -> dict:
)

output = MessageToDict(proto_output)
return format_fields_nested(
object=output, fn=lambda x: from_sdk_dec_n(x, 6), fields=["amount"]
)
return output

def spot_price(
self, pool_id: int, token_in_denom: str, token_out_denom: str
Expand Down Expand Up @@ -295,9 +285,7 @@ def estimate_swap_exact_amount_in(
)

output = MessageToDict(proto_output)
return format_fields_nested(
object=output, fn=lambda x: from_sdk_dec_n(x, 6), fields=["amount"]
)
return output

def estimate_join_exact_amount_in(
self, pool_id: int, tokens_ins: List[Coin]
Expand Down Expand Up @@ -336,11 +324,7 @@ def estimate_join_exact_amount_in(
)

output = MessageToDict(proto_output)
return format_fields_nested(
object=output,
fn=lambda x: from_sdk_dec_n(x, 6),
fields=["amount", "poolSharesOut"],
)
return output

def estimate_exit_exact_amount_in(self, pool_id: int, num_shares: int) -> dict:
"""
Expand Down Expand Up @@ -376,6 +360,4 @@ def estimate_exit_exact_amount_in(self, pool_id: int, num_shares: int) -> dict:
should_deserialize=False,
)
output = MessageToDict(proto_output)
return format_fields_nested(
object=output, fn=lambda x: from_sdk_dec_n(x, 6), fields=["amount"]
)
return output
40 changes: 12 additions & 28 deletions nibiru/query_clients/stablecoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from nibiru_proto.proto.stablecoin import query_pb2 as stablecoin_type
from nibiru_proto.proto.stablecoin import query_pb2_grpc as stablecoin_query

from nibiru.query_clients.util import QueryClient, dict_keys_from_camel_to_snake
from nibiru.query_clients.util import QueryClient
from nibiru.utils import format_fields_nested, from_sdk_dec_n


Expand All @@ -23,41 +23,25 @@ def params(self) -> dict:
Example Return Value:
{
"params": {
"coll_ratio": "140000",
"fee_ratio": "2000",
"ef_fee_ratio": "500000",
"bonus_rate_recoll": "2000",
"distr_epoch_identifier": "15 min",
"adjustment_step": "2500",
"price_lower_bound": "999900",
"price_upper_bound": "1000100",
"is_collateral_ratio_valid": true
"coll_ratio": "140000",
"fee_ratio": "2000",
"ef_fee_ratio": "500000",
"bonus_rate_recoll": "2000",
"distr_epoch_identifier": "15 min",
"adjustment_step": "2500",
"price_lower_bound": "999900",
"price_upper_bound": "1000100",
"is_collateral_ratio_valid": true
}
}
Returns:
dict: The parameters fo the stablecoin module.
"""
proto_output = self.query(
return self.query(
api_callable=self.api.Params,
req=stablecoin_type.QueryParamsRequest(),
should_deserialize=False,
)
output = MessageToDict(proto_output, including_default_value_fields=True)
return dict_keys_from_camel_to_snake(
format_fields_nested(
object=output,
fn=lambda x: from_sdk_dec_n(x, 6),
fields=[
"collRatio",
"feeRatio",
"efFeeRatio",
"bonusRateRecoll",
"adjustmentStep",
"priceLowerBound",
"priceUpperBound",
],
)
should_deserialize=True,
)

def circulating_supplies(self, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions nibiru/query_clients/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from nibiru_proto.proto.cosmos.staking.v1beta1 import query_pb2 as staking_type
from nibiru_proto.proto.cosmos.staking.v1beta1 import query_pb2_grpc as staking_query

from nibiru.query_clients.util import QueryClient, deserialize, get_page_request
from nibiru.query_clients.util import QueryClient, message_to_dict, get_page_request


class StakingQueryClient(QueryClient):
Expand Down Expand Up @@ -318,4 +318,4 @@ def validators(self, **kwargs) -> dict:
should_deserialize=False,
height=kwargs.get("height"),
)
return deserialize(proto_output)
return message_to_dict(proto_output)
Loading

0 comments on commit 2e9a915

Please sign in to comment.