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

Refactored to use new sdk wrapper and cleanup #6

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
50 changes: 50 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: end-of-file-fixer
exclude: >
(?x)^(
.+\.svg|
.+\.min.js|
.+\.xsd|
.+\.md|
.+\.tsx|
.+\.ts|
.+\.xsd|
.+\.html|
.+\.txt|
.+\.ini|
)$
- id: trailing-whitespace
exclude: >
(?x)^(
.+\.svg|
.+\.min.js|
.+\.xsd|
.+\.md|
.+\.tsx|
.+\.ts|
.+\.xsd|
.+\.html|
.+\.txt|
.+\.ini|
)$

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
files: \.py$

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
files: \.py$
args: ["--profile", "black"]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
4 changes: 4 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ nibiru-py = {path = "."}

[dev-packages]
mypy-protobuf = "*"
black = "*"
pylint = "==2.13.4"
pre-commit = "*"
pep8-naming = "*"

[requires]
python_version = "3"
128 changes: 127 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pip install nibiru-py
### Usage
Requires Python 3.7+

[Examples](https://github.com/NibiruLabs/sdk-python/tree/master/examples)
[Examples](https://github.com/NibiruChain/sdk-python/tree/master/examples)
```bash
$ pipenv shell
$ pipenv install
Expand Down Expand Up @@ -67,3 +67,9 @@ Upgrade `pip` to the latest version, if you see these warnings:
pip uninstall nibiru-py
pip install nibiru-py
```
### Linting
Enable git hook which will perform linting before each commit:
```shell
pre-commit install
```
This will keep your code clean.
4 changes: 2 additions & 2 deletions compatibility-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ The aim of this repo was to test all python versions from 3.7.0 to 3.9.6 for com

A) Downloads all python versions and extracts the contents
B) Opens a subshell and installs python
C) Installs all the dependencies used by the Injective Exchange API and Chain Client
C) Installs all the dependencies used by the Nibiru Exchange API and Chain Client
D) Saves the python version and the stdout/stderr of the tests.py script to the results.txt file to have both successful and error output.
E) Purges python and all its dependencies, repeats until the last version.

- NOTE: DO NOT USE THIS SCRIPT IN YOUR OWN MACHINE, USE IT ONLY IN A TEST ENVIRONMENT AS THE SCRIPT WILL UNINSTALL ALL THE DEPENDENCIES THAT COME WITH PYTHON.

2. tests.py

This python script imports all the libraries used by the Injective Exchange API and Chain Client. It makes a gRPC request and uses the data to broadcast a transaction to the chain with both cosmos-sdk and exchange messages using a REST API endpoint. Certain libraries are imported from injective-py which you can find [here](https://pypi.org/project/injective-py/).
This python script imports all the libraries used by the Nibiru Exchange API and Chain Client. It makes a gRPC request and uses the data to broadcast a transaction to the chain with both cosmos-sdk and exchange messages using a REST API endpoint. Certain libraries are imported from nibiru-py which you can find [here](https://pypi.org/project/injective-py/).

3. results.txt

Expand Down
2 changes: 1 addition & 1 deletion compatibility-tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install_libraries() {
python3 -m pip install grpcio
python3 -m pip install typing
python3 -m pip install protobuf
python3 -m pip install injective-py
python3 -m pip install nibiru-py
}

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
Expand Down
24 changes: 12 additions & 12 deletions compatibility-tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
import grpc

from typing import Any, Dict, List
from injective.chain_client._wallet import (
from nibiru.chain_client._wallet import (
generate_wallet,
privkey_to_address,
privkey_to_pubkey,
pubkey_to_address,
seed_to_privkey,
DEFAULT_BECH32_HRP,
)
from injective.chain_client._typings import SyncMode
import injective.exchange_api.injective_accounts_rpc_pb2 as accounts_rpc_pb
import injective.exchange_api.injective_accounts_rpc_pb2_grpc as accounts_rpc_grpc
from nibiru.chain_client._typings import SyncMode
import nibiru.exchange_api.nibiru_accounts_rpc_pb2 as accounts_rpc_pb
import nibiru.exchange_api.nibiru_accounts_rpc_pb2_grpc as accounts_rpc_grpc


MIN_GAS_PRICE = 500000000
Expand All @@ -35,9 +35,9 @@ def __init__(
sequence: int,
fee: int,
gas: int,
fee_denom: str = "inj",
fee_denom: str = "unibi",
memo: str = "",
chain_id: str = "injective-888",
chain_id: str = "nibiru-888",
hrp: str = DEFAULT_BECH32_HRP,
sync_mode: SyncMode = "block",
) -> None:
Expand Down Expand Up @@ -66,7 +66,7 @@ def add_cosmos_bank_msg_send(self, recipient: str, amount: int, denom: str = "in
}
self._msgs.append(msg)

# Injective • Exchange Module
# Nibiru Exchange Module

def add_exchange_msg_deposit(self, subaccount: str, amount: int, denom: str = "inj") -> None:
msg = {
Expand All @@ -93,7 +93,7 @@ def get_signed(self) -> str:
"signatures": [
{
"signature": self._sign(),
"pub_key": {"type": "injective/PubKeyEthSecp256k1", "value": base64_pubkey},
"pub_key": {"type": "nibiru/PubKeyEthSecp256k1", "value": base64_pubkey},
"account_number": str(self._account_num),
"sequence": str(self._sequence),
}
Expand Down Expand Up @@ -139,8 +139,8 @@ async def main() -> None:

acc_num, acc_seq = await get_account_num_seq(sender_acc_addr)

async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
accounts_rpc = accounts_rpc_grpc.InjectiveAccountsRPCStub(channel)
async with grpc.aio.insecure_channel('testnet-sentry0.nibiru.network:9910') as channel:
accounts_rpc = accounts_rpc_grpc.nibiruAccountsRPCStub(channel)
account_addr = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"

subacc = await accounts_rpc.SubaccountsList(accounts_rpc_pb.SubaccountsListRequest(account_address = account_addr))
Expand Down Expand Up @@ -175,7 +175,7 @@ async def main() -> None:
async def get_account_num_seq(address: str) -> (int, int):
async with aiohttp.ClientSession() as session:
async with session.request(
'GET', 'http://staking-lcd-testnet.injective.network/cosmos/auth/v1beta1/accounts/' + address,
'GET', 'http://staking-lcd-testnet.nibiru.network/cosmos/auth/v1beta1/accounts/' + address,
headers={'Accept-Encoding': 'application/json'},
) as response:
if response.status != 200:
Expand All @@ -189,7 +189,7 @@ async def get_account_num_seq(address: str) -> (int, int):
async def post_tx(tx_json: str):
async with aiohttp.ClientSession() as session:
async with session.request(
'POST', 'http://staking-lcd-testnet.injective.network/txs', data=tx_json,
'POST', 'http://staking-lcd-testnet.nibiru.network/txs', data=tx_json,
headers={'Content-Type': 'application/json'},
) as response:
if response.status != 200:
Expand Down
Loading