Skip to content

Commit

Permalink
chore: upgrade to chain v0.21.9 (#252)
Browse files Browse the repository at this point in the history
* chore: upgrade to chain v0.21.9

* fix: poetry.lock

* fix(scripts): make the flake8 version consistent with pyproject.toml

* refactor: appease linter

* use TypeError instead of generic exception

* fix(utils.py): invalid call of isinstance

* fix tests

* changelog

---------

Co-authored-by: Unique-Divine <realuniquedivine@gmail.com>
  • Loading branch information
onikonychev and Unique-Divine authored Sep 21, 2023
1 parent c87d0f6 commit ddee6d1
Show file tree
Hide file tree
Showing 8 changed files with 515 additions and 467 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.pyc
.coverage
.env
.venv
.pytest_cache
.coveragerc
.DS_Store
.idea
build
.python-version
bin
.vscode/
2 changes: 1 addition & 1 deletion pysdk/.pre-commit-config.yaml → .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
exclude: nibiru/proto/.+

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 22.12.0
hooks:
- id: black
files: \.py$
Expand Down
14 changes: 13 additions & 1 deletion pysdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@

All notable changes to this project will be documented in this file.

## Unreleased
## [Unreleased]

## [v0.21.9](https://github.com/NibiruChain/py-sdk/tree/v0.21.9)

- [#252](https://github.com/NibiruChain/py-sdk/pull/252) Updates the `nibiru-proto` dependency to v0.21.9, corresponding to the same version of NibiruChain/nibiru.
- deps!: This version of the chain uses Cosmos-SDK v0.47
- [#250](https://github.com/NibiruChain/py-sdk/pull/250): feat(perp): add query markets
- [#243](https://github.com/NibiruChain/py-sdk/pull/243): epic(tmrpc): all passing tests for v0.21
- [#238](https://github.com/NibiruChain/py-sdk/pull/238): epic: migration for v0.21 with passing tests
- [#238](https://github.com/NibiruChain/py-sdk/pull/238): epic: migration for v0.21 with passing tests
- [#235](https://github.com/NibiruChain/py-sdk/pull/235): ci: Run tests on release branches
- [#225](https://github.com/NibiruChain/py-sdk/pull/225): chore(deps): bump requests from 2.28.2 to 2.31.0
- [#249](https://github.com/NibiruChain/py-sdk/pull/249): chore(deps): Bump aiohttp from 3.8.4 to 3.8.5 in /pysdk

## v0.19.0

Expand Down
897 changes: 477 additions & 420 deletions pysdk/poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pysdk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nibiru"
version = "0.21.3b7"
version = "0.21.9"
description = "Python SDK for interacting with Nibiru."
authors = ["Nibiru Chain <dev@nibiru.fi>"]
license = "MIT"
Expand Down Expand Up @@ -34,7 +34,7 @@ pre-commit = "^2.20.0"
shutup = "^0.2.0"
websocket-client = "^1.4.1"
packaging = "^21.3"
nibiru-proto = "==0.21.3b7"
nibiru-proto = "==0.21.9"
bip32 = "^3.3"
importlib-metadata = "^5.0.0"
types-protobuf = "^4.23.0.1"
Expand Down
11 changes: 6 additions & 5 deletions pysdk/pysdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def format_fields_nested(
Returns:
Union[list, dict]: The output formatted
"""
if type(object) == dict:
if isinstance(object, dict):
output = {}
for k, v in object.items():
if type(v) in (dict, list):
if isinstance(object, (dict, list)):
output[k] = format_fields_nested(v, fn, fields)
else:
if k in fields:
Expand All @@ -106,17 +106,18 @@ def format_fields_nested(
output[k] = v

return output

if type(object) == list:
elif isinstance(object, list):
output = []

for element in object:
if type(object) in (dict, list):
if isinstance(object, (dict, list)):
output.append(format_fields_nested(element, fn, fields))
else:
output.append(element)

return output
else:
return object


def from_sdk_dec(dec_str: str) -> float:
Expand Down
5 changes: 2 additions & 3 deletions pysdk/scripts/fmt.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
poetry run black .
poetry run isort .
flake8 pysdk
flake8 tests
flake8 examples
poetry run python -m pip install flake8
poetry run flake8 pysdk tests examples
37 changes: 2 additions & 35 deletions pysdk/tests/perp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ def test_open_position(sdk_val: pysdk.Sdk):
)
)
tests.broadcast_tx_must_succeed(res=tx_output)

# TODO deprecated
# tests.LOGGER.info(
# f"nibid tx perp open-position: {tests.format_response(tx_output)}"
# )
# tx_resp = pt.TxResp.from_raw(pt.RawTxResp(tx_output))
# assert "/pysdk.perp.v2.MsgMarketOrder" in tx_resp.rawLog[0].msgs
# events_for_msg: List[str] = [
# "pysdk.perp.v2.PositionChangedEvent",
# ]
# assert all(
# [msg_event in tx_resp.rawLog[0].event_types for msg_event in events_for_msg]
# )
except BaseException as err:
ok_errors: List[str] = [ERRORS.no_prices]
tests.raises(ok_errors, err)
Expand All @@ -69,10 +56,6 @@ def test_perp_query_position(sdk_val: pysdk.Sdk):
"margin_ratio",
],
)
# TODO deprecated
# tests.LOGGER.info(
# f"nibid query perp trader-position: \n{tests.format_response(position_res)}"
# )
position = position_res["position"]
assert position["margin"]
assert position["open_notional"]
Expand Down Expand Up @@ -104,11 +87,7 @@ def test_perp_query_market(sdk_val: pysdk.Sdk):
},
"amm": {
"pair": "ubtc:unusd",
"baseReserve": 30000000000000.0,
"quoteReserve": 30000000000000.0,
"sqrtDepth": 30000000000000.0,
"totalLong": 0.0,
"totalShort": 0.0,
},
},
{
Expand All @@ -128,17 +107,13 @@ def test_perp_query_market(sdk_val: pysdk.Sdk):
},
"amm": {
"pair": "ueth:unusd",
"baseReserve": 30000000000000.0,
"quoteReserve": 30000000000000.0,
"sqrtDepth": 30000000000000.0,
"totalLong": 0.0,
"totalShort": 0.0,
},
},
]
}

# have to assert subset since i don't want to check the price which can change in loclanet
# test subset, exclude changing baseReserve, quoteReserve, totalLong, totalShort
assert_subset(output, expected_to_be_equal)


Expand Down Expand Up @@ -195,13 +170,9 @@ def test_perp_remove_margin(sdk_val: pysdk.Sdk):
Msg.perp.remove_margin(
sender=sdk_val.address,
pair=PAIR,
margin=pt.Coin(5, "unusd"),
margin=pt.Coin(2, "unusd"),
)
)
# TODO deprecated
# tests.LOGGER.info(
# f"nibid tx perp remove-margin: \n{tests.format_response(tx_output)}"
# )
tests.broadcast_tx_must_succeed(res=tx_output)
# TODO test: verify the margin changes using the events
except BaseException as err:
Expand All @@ -220,10 +191,6 @@ def test_perp_close_posititon(sdk_val: pysdk.Sdk):
tx_output = sdk_val.tx.execute_msgs(
Msg.perp.close_position(sender=sdk_val.address, pair=PAIR)
)
# TODO deprecated
# tests.LOGGER.info(
# f"nibid tx perp close-position: \n{tests.format_response(tx_output)}"
# )
tests.broadcast_tx_must_succeed(res=tx_output)

out = sdk_val.query.perp.position(trader=sdk_val.address, pair=PAIR)
Expand Down

0 comments on commit ddee6d1

Please sign in to comment.