Skip to content

Commit

Permalink
epic: migration for v0.21 with passing tests #wip (#238)
Browse files Browse the repository at this point in the history
* Fixing imports for v0.21, need gogoproto for release

 Please enter the commit message for your changes. Lines starting

* Broken epochs from nibiru_proto

* #wip: no import errors on test runs

* saved #wip

* fixed tx service halts #wip

* Pass spot tests if pool dne

* Fix stablecoin test
w with '#' will be ignored, and an empty message aborts the commit.

* all passing tests on v0.21

* Ran pre-commit auto update

* Add tx query to include missing fields from grpc resp

* save #wip: fixing InactiveRpcError

* fix!: improvements to broadcast fn

* fix,docs(tx.py)!:
1. Make sequence errors near-impossible.
2. Use more type hints.
3. Improve wallet.Address initialization robustness.

* fix,ci(scripts): (1) Add --no-build flag for localnet.sh,
(2) CI test the script, and (3) fix version on e2e action

* ci(scripts.yml): trigger run

* ci: fix typo

* ci: lower the sleep time since the network starts pretty quickly

* ci(scripts.yml): run localnet.sh in the background

* appease linter

* ci(lint.yml): make linter more specific

* run black and flake8

* fix: both isort and black should be poetry 'dev' dependencies

* ci(lint.yml): wrong job name

* ci(lint.yml): clean up workflow even more + concurrency restart

* ci(lint.yml): invalid run/uses syntax for job:lint-py

---------

Co-authored-by: Unique-Divine <realuniquedivine@gmail.com>
  • Loading branch information
AnishP15 and Unique-Divine authored Jul 8, 2023
1 parent 13e6238 commit 498263e
Show file tree
Hide file tree
Showing 45 changed files with 1,474 additions and 830 deletions.
77 changes: 54 additions & 23 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,69 @@
name: Linting
name: "Linting"
on:
push:
branches:
- master
pull_request:
branches:
- master
branches: ["master"]
push:
branches: ["master"]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
cancel-in-progress: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}

jobs:
test:
lint-py:
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 2
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Check out the repo
uses: actions/checkout@v3

- name: Setup Python
- name: "Setup Python"
uses: actions/setup-python@v2
with:
python-version: "3.9.13"

#----------------------------------------------
# load pip cache if cache exists
#----------------------------------------------
- uses: actions/cache@v2
- name: "Load pip cache if cache exists"
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip
restore-keys: ${{ runner.os }}-pip
#----------------------------------------------
# install and run linters
#----------------------------------------------
- run: python -m pip install black flake8 isort
- run: |
flake8 .
black . --check
isort .
- name: "Install and run flake8"
run: |
python -m pip install flake8
flake8 nibiru
flake8 tests
flake8 examples
# ----------------------------------------------
# Try to load a cached poetry binary
# See https://github.com/snok/install-poetry#caching-the-poetry-installation for the source
# ----------------------------------------------
- name: "Load cached Poetry installation"
uses: actions/cache@v2
with:
path: ~/.local
key: poetry-0 # increment to reset cache

- name: "Install poetry"
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
version: latest
- name: "Load cached venv"
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: "Install dependencies with poetry (using cache)"
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Run checks for black and isort
run: |
poetry run black . --check
poetry run isort .
33 changes: 16 additions & 17 deletions .github/workflows/pytests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: E2E 🐍 tests
name: "E2E 🐍 tests"

on:
pull_request:
Expand Down Expand Up @@ -29,12 +29,6 @@ jobs:
runs-on: ubuntu-latest
env:
# https://www.notion.so/nibiru/Resources-and-Repo-Configs-b31aa8074a2b419d80b0c946ed5efab0
LCD_ENDPOINT: "http://localhost:1317"
GRPC_ENDPOINT: "localhost:9090"
TENDERMINT_RPC_ENDPOINT: "http://localhost:26657"
USE_LOCALNET: true
WEBSOCKET_ENDPOINT: "ws://localhost:26657/websocket"
CHAIN_ID: "nibiru-localnet-0"
VALIDATOR_MNEMONIC: "guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host"
DEVNET_NUMBER: ${{ secrets.DEVNET_NUMBER }}
steps:
Expand All @@ -54,7 +48,7 @@ jobs:
# 3.8.16 is the highest 3.8 version available on pyenv
# See `grep '3.8' <<< $(pyenv install -l)` to view the available list.

- name: Run python
- name: Run python # sanity check on the installation.
run: python --version && python -c "print('hello')"

# ----------------------------------------------
Expand Down Expand Up @@ -99,16 +93,21 @@ jobs:
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Run chaosnet
uses: NibiruChain/localnet-action@v1.1
id: chaosnet
with:
services: nibiru pricefeeder
ghtoken: ${{ secrets.GITHUB_TOKEN }}
ghactor: ${{ github.actor }}
- name: Run localnet.sh in the background.
run: |
curl -s https://get.nibiru.fi/@v0.21.5! | bash
bash scripts/localnet.sh --no-build &
# - name: Run chaosnet
# uses: NibiruChain/localnet-action@v1.1
# id: chaosnet
# with:
# services: nibiru pricefeeder
# ghtoken: ${{ secrets.GITHUB_TOKEN }}
# ghactor: ${{ github.actor }}

- name: sleep 30 seconds
run: sleep 30
- name: "Sleep so that the network has time to start."
run: sleep 5
#----------------------------------------------
# run tests
#----------------------------------------------
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "py-sdk/scripts"

on:
pull_request:
branches: ["master"]
paths:
[
"scripts",
"**.py",
"pyproject.toml",
"poetry.lock",
".github/workflows/pytests.yml",
]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
cancel-in-progress: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}

jobs:
localnet:
# The localnet job verifies that the repo's script for starting a local Nibiru
# chain runs without errors.
runs-on: ubuntu-latest
env:
# https://www.notion.so/nibiru/Resources-and-Repo-Configs-b31aa8074a2b419d80b0c946ed5efab0
VALIDATOR_MNEMONIC: "guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host"
DEVNET_NUMBER: ${{ secrets.DEVNET_NUMBER }}
steps:
# ----------------------------------------------
# check-out repo and set-up python
# ----------------------------------------------
- name: Check out the repo
uses: actions/checkout@v3

- name: Run localnet.sh in the background.
run: |
curl -s https://get.nibiru.fi/@v0.21.5! | bash
bash scripts/localnet.sh --no-build &
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
coverage.txt
examples/trading_bot.py

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
4 changes: 2 additions & 2 deletions .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: "1.1.0" # the revision or tag to clone at
hooks:
- id: sync_with_poetry
args: [] # optional args
Expand All @@ -14,7 +14,7 @@ repos:
exclude: nibiru/proto/.+

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black
files: \.py$
Expand Down
2 changes: 1 addition & 1 deletion nibiru/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
Network,
NetworkType,
PoolAsset,
TxBroadcastMode,
TxConfig,
TxType,
)
from nibiru.sdk import Sdk # noqa
from nibiru.tx import Transaction # noqa
Expand Down
13 changes: 8 additions & 5 deletions nibiru/event_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from enum import Enum

import google.protobuf.message
from nibiru_proto.proto.oracle.v1 import event_pb2 as oracle_events
from nibiru_proto.proto.perp.v2 import event_pb2 as perp_events
from nibiru_proto.proto.spot.v1 import event_pb2 as spot_events
from nibiru_proto.proto.stablecoin.v1 import events_pb2 as stablecoin_events # noqa
from nibiru_proto.nibiru.oracle.v1 import event_pb2 as oracle_events
from nibiru_proto.nibiru.perp.v2 import event_pb2 as perp_events
from nibiru_proto.nibiru.spot.v1 import event_pb2 as spot_events
from nibiru_proto.nibiru.stablecoin.v1 import events_pb2 as stablecoin_events # noqa


class EventType(Enum):
Expand Down Expand Up @@ -35,7 +35,10 @@ class EventType(Enum):
BuybackEvent = stablecoin_events.EventBuyback

# Oracle events
PriceUpdate = oracle_events.OraclePriceUpdate
PriceUpdate = oracle_events.EventPriceUpdate
EventDelegateFeederConsent = oracle_events.EventDelegateFeederConsent
EventAggregateVote = oracle_events.EventAggregateVote
EventAggregatePrevote = oracle_events.EventAggregatePrevote

# Bank
Transfer = "transfer"
Expand Down
4 changes: 4 additions & 0 deletions nibiru/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ class TxError(NibiruError):
pass


class ErrorQueryTx(NibiruError):
"""Expresses failure to to query a tx with its hash."""


class QueryError(NibiruError):
pass
Loading

0 comments on commit 498263e

Please sign in to comment.