Skip to content

Commit

Permalink
(feat) Added Black to the project and as part of the pre-commit. Fixe…
Browse files Browse the repository at this point in the history
…d all detected issues.
  • Loading branch information
abel committed Sep 19, 2023
1 parent fa7377d commit 05f3bdf
Show file tree
Hide file tree
Showing 141 changed files with 1,406 additions and 1,391 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ repos:
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black
38 changes: 18 additions & 20 deletions compatibility-tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class Transaction:

def __init__(
self,
*,
Expand Down Expand Up @@ -94,17 +93,14 @@ def get_signed(self) -> str:
return json.dumps(signed_tx, separators=(",", ":"))

def _sign(self) -> str:
message_str = json.dumps(
self._get_sign_message(), separators=(",", ":"), sort_keys=True)
message_str = json.dumps(self._get_sign_message(), separators=(",", ":"), sort_keys=True)
message_bytes = message_str.encode("utf-8")

privkey = ecdsa.SigningKey.from_string(
self._privkey, curve=ecdsa.SECP256k1)
privkey = ecdsa.SigningKey.from_string(self._privkey, curve=ecdsa.SECP256k1)
signature_compact_keccak = privkey.sign_deterministic(
message_bytes, hashfunc=sha3.keccak_256, sigencode=ecdsa.util.sigencode_string_canonize
)
signature_base64_str = base64.b64encode(
signature_compact_keccak).decode("utf-8")
signature_base64_str = base64.b64encode(signature_compact_keccak).decode("utf-8")
return signature_base64_str

def _get_sign_message(self) -> Dict[str, Any]:
Expand All @@ -122,15 +118,13 @@ def _get_sign_message(self) -> Dict[str, Any]:


async def main() -> None:
sender_pk = seed_to_privkey(
"physical page glare junk return scale subject river token door mirror title"
)
sender_pk = seed_to_privkey("physical page glare junk return scale subject river token door mirror title")
sender_acc_addr = privkey_to_address(sender_pk)
print("Sender Account:", sender_acc_addr)

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:
async with grpc.aio.insecure_channel("testnet-sentry0.injective.network:9910") as channel:
accounts_rpc = accounts_rpc_grpc.InjectiveAccountsRPCStub(channel)
account_addr = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"

Expand Down Expand Up @@ -169,34 +163,38 @@ 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,
headers={'Accept-Encoding': 'application/json'},
"GET",
"http://staking-lcd-testnet.injective.network/cosmos/auth/v1beta1/accounts/" + address,
headers={"Accept-Encoding": "application/json"},
) as response:
if response.status != 200:
print(await response.text())
raise ValueError("HTTP response status", response.status)

resp = json.loads(await response.text())
acc = resp['account']['base_account']
return acc['account_number'], acc['sequence']
acc = resp["account"]["base_account"]
return acc["account_number"], acc["sequence"]


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,
headers={'Content-Type': 'application/json'},
"POST",
"http://staking-lcd-testnet.injective.network/txs",
data=tx_json,
headers={"Content-Type": "application/json"},
) as response:
if response.status != 200:
print(await response.text())
raise ValueError("HTTP response status", response.status)

resp = json.loads(await response.text())
if 'code' in resp:
if "code" in resp:
print("Response:", resp)
raise ValueError('sdk error %d: %s' % (resp['code'], resp['raw_log']))
raise ValueError("sdk error %d: %s" % (resp["code"], resp["raw_log"]))

return resp["txhash"]

return resp['txhash']

if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
37 changes: 17 additions & 20 deletions compatibility-tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class Transaction:

def __init__(
self,
*,
Expand Down Expand Up @@ -92,17 +91,14 @@ def get_signed(self) -> str:
return json.dumps(signed_tx, separators=(",", ":"))

def _sign(self) -> str:
message_str = json.dumps(
self._get_sign_message(), separators=(",", ":"), sort_keys=True)
message_str = json.dumps(self._get_sign_message(), separators=(",", ":"), sort_keys=True)
message_bytes = message_str.encode("utf-8")

privkey = ecdsa.SigningKey.from_string(
self._privkey, curve=ecdsa.SECP256k1)
privkey = ecdsa.SigningKey.from_string(self._privkey, curve=ecdsa.SECP256k1)
signature_compact_keccak = privkey.sign_deterministic(
message_bytes, hashfunc=sha3.keccak_256, sigencode=ecdsa.util.sigencode_string_canonize
)
signature_base64_str = base64.b64encode(
signature_compact_keccak).decode("utf-8")
signature_base64_str = base64.b64encode(signature_compact_keccak).decode("utf-8")
return signature_base64_str

def _get_sign_message(self) -> Dict[str, Any]:
Expand All @@ -122,47 +118,48 @@ def _get_sign_message(self) -> Dict[str, Any]:
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,
headers={'Accept-Encoding': 'application/json'},
"GET",
"http://staking-lcd-testnet.injective.network/cosmos/auth/v1beta1/accounts/" + address,
headers={"Accept-Encoding": "application/json"},
) as response:
if response.status != 200:
print(await response.text())
raise ValueError("HTTP response status", response.status)

resp = json.loads(await response.text())
acc = resp['account']['base_account']
return acc['account_number'], acc['sequence']
acc = resp["account"]["base_account"]
return acc["account_number"], acc["sequence"]


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,
headers={'Content-Type': 'application/json'},
"POST",
"http://staking-lcd-testnet.injective.network/txs",
data=tx_json,
headers={"Content-Type": "application/json"},
) as response:
if response.status != 200:
print(await response.text())
raise ValueError("HTTP response status", response.status)

resp = json.loads(await response.text())
if 'code' in resp:
if "code" in resp:
print("Response:", resp)
raise ValueError('sdk error %d: %s' % (resp['code'], resp['raw_log']))
raise ValueError("sdk error %d: %s" % (resp["code"], resp["raw_log"]))

return resp['txhash']
return resp["txhash"]


@pytest.fixture
async def msg_send():
sender_pk = seed_to_privkey(
"physical page glare junk return scale subject river token door mirror title"
)
sender_pk = seed_to_privkey("physical page glare junk return scale subject river token door mirror title")
sender_acc_addr = privkey_to_address(sender_pk)
print("Sender Account:", sender_acc_addr)

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:
async with grpc.aio.insecure_channel("testnet-sentry0.injective.network:9910") as channel:
accounts_rpc = accounts_rpc_grpc.InjectiveAccountsRPCStub(channel)
account_addr = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"

Expand Down
14 changes: 8 additions & 6 deletions examples/SendToInjective.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ async def main() -> None:
receiver = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
amount = 1

data = ('{"@type": "/injective.exchange.v1beta1.MsgDeposit",'
'"sender": "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",'
'"subaccountId": "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",'
'"amount": {"denom": "inj","amount": "1000000000000000000"}}'
)
data = (
'{"@type": "/injective.exchange.v1beta1.MsgDeposit",'
'"sender": "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",'
'"subaccountId": "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",'
'"amount": {"denom": "inj","amount": "1000000000000000000"}}'
)

with open("../pyinjective/Peggo_ABI.json") as pego_file:
peggo_data = pego_file.read()
Expand All @@ -39,8 +40,9 @@ async def main() -> None:
maxFeePerGas=maxFeePerGas_Gwei,
maxPriorityFeePerGas=maxPriorityFeePerGas_Gwei,
data=data,
peggo_abi=peggo_abi
peggo_abi=peggo_abi,
)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Loading

0 comments on commit 05f3bdf

Please sign in to comment.