Skip to content

Commit 05f3bdf

Browse files
author
abel
committed
(feat) Added Black to the project and as part of the pre-commit. Fixed all detected issues.
1 parent fa7377d commit 05f3bdf

File tree

141 files changed

+1406
-1391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+1406
-1391
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ repos:
2222
hooks:
2323
- id: isort
2424
name: isort (python)
25+
- repo: https://github.com/psf/black-pre-commit-mirror
26+
rev: 23.9.1
27+
hooks:
28+
- id: black

compatibility-tests/tests.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
class Transaction:
19-
2019
def __init__(
2120
self,
2221
*,
@@ -94,17 +93,14 @@ def get_signed(self) -> str:
9493
return json.dumps(signed_tx, separators=(",", ":"))
9594

9695
def _sign(self) -> str:
97-
message_str = json.dumps(
98-
self._get_sign_message(), separators=(",", ":"), sort_keys=True)
96+
message_str = json.dumps(self._get_sign_message(), separators=(",", ":"), sort_keys=True)
9997
message_bytes = message_str.encode("utf-8")
10098

101-
privkey = ecdsa.SigningKey.from_string(
102-
self._privkey, curve=ecdsa.SECP256k1)
99+
privkey = ecdsa.SigningKey.from_string(self._privkey, curve=ecdsa.SECP256k1)
103100
signature_compact_keccak = privkey.sign_deterministic(
104101
message_bytes, hashfunc=sha3.keccak_256, sigencode=ecdsa.util.sigencode_string_canonize
105102
)
106-
signature_base64_str = base64.b64encode(
107-
signature_compact_keccak).decode("utf-8")
103+
signature_base64_str = base64.b64encode(signature_compact_keccak).decode("utf-8")
108104
return signature_base64_str
109105

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

123119

124120
async def main() -> None:
125-
sender_pk = seed_to_privkey(
126-
"physical page glare junk return scale subject river token door mirror title"
127-
)
121+
sender_pk = seed_to_privkey("physical page glare junk return scale subject river token door mirror title")
128122
sender_acc_addr = privkey_to_address(sender_pk)
129123
print("Sender Account:", sender_acc_addr)
130124

131125
acc_num, acc_seq = await get_account_num_seq(sender_acc_addr)
132126

133-
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
127+
async with grpc.aio.insecure_channel("testnet-sentry0.injective.network:9910") as channel:
134128
accounts_rpc = accounts_rpc_grpc.InjectiveAccountsRPCStub(channel)
135129
account_addr = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
136130

@@ -169,34 +163,38 @@ async def main() -> None:
169163
async def get_account_num_seq(address: str) -> (int, int):
170164
async with aiohttp.ClientSession() as session:
171165
async with session.request(
172-
'GET', 'http://staking-lcd-testnet.injective.network/cosmos/auth/v1beta1/accounts/' + address,
173-
headers={'Accept-Encoding': 'application/json'},
166+
"GET",
167+
"http://staking-lcd-testnet.injective.network/cosmos/auth/v1beta1/accounts/" + address,
168+
headers={"Accept-Encoding": "application/json"},
174169
) as response:
175170
if response.status != 200:
176171
print(await response.text())
177172
raise ValueError("HTTP response status", response.status)
178173

179174
resp = json.loads(await response.text())
180-
acc = resp['account']['base_account']
181-
return acc['account_number'], acc['sequence']
175+
acc = resp["account"]["base_account"]
176+
return acc["account_number"], acc["sequence"]
182177

183178

184179
async def post_tx(tx_json: str):
185180
async with aiohttp.ClientSession() as session:
186181
async with session.request(
187-
'POST', 'http://staking-lcd-testnet.injective.network/txs', data=tx_json,
188-
headers={'Content-Type': 'application/json'},
182+
"POST",
183+
"http://staking-lcd-testnet.injective.network/txs",
184+
data=tx_json,
185+
headers={"Content-Type": "application/json"},
189186
) as response:
190187
if response.status != 200:
191188
print(await response.text())
192189
raise ValueError("HTTP response status", response.status)
193190

194191
resp = json.loads(await response.text())
195-
if 'code' in resp:
192+
if "code" in resp:
196193
print("Response:", resp)
197-
raise ValueError('sdk error %d: %s' % (resp['code'], resp['raw_log']))
194+
raise ValueError("sdk error %d: %s" % (resp["code"], resp["raw_log"]))
195+
196+
return resp["txhash"]
198197

199-
return resp['txhash']
200198

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

compatibility-tests/unit_tests.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
class Transaction:
19-
2019
def __init__(
2120
self,
2221
*,
@@ -92,17 +91,14 @@ def get_signed(self) -> str:
9291
return json.dumps(signed_tx, separators=(",", ":"))
9392

9493
def _sign(self) -> str:
95-
message_str = json.dumps(
96-
self._get_sign_message(), separators=(",", ":"), sort_keys=True)
94+
message_str = json.dumps(self._get_sign_message(), separators=(",", ":"), sort_keys=True)
9795
message_bytes = message_str.encode("utf-8")
9896

99-
privkey = ecdsa.SigningKey.from_string(
100-
self._privkey, curve=ecdsa.SECP256k1)
97+
privkey = ecdsa.SigningKey.from_string(self._privkey, curve=ecdsa.SECP256k1)
10198
signature_compact_keccak = privkey.sign_deterministic(
10299
message_bytes, hashfunc=sha3.keccak_256, sigencode=ecdsa.util.sigencode_string_canonize
103100
)
104-
signature_base64_str = base64.b64encode(
105-
signature_compact_keccak).decode("utf-8")
101+
signature_base64_str = base64.b64encode(signature_compact_keccak).decode("utf-8")
106102
return signature_base64_str
107103

108104
def _get_sign_message(self) -> Dict[str, Any]:
@@ -122,47 +118,48 @@ def _get_sign_message(self) -> Dict[str, Any]:
122118
async def get_account_num_seq(address: str) -> (int, int):
123119
async with aiohttp.ClientSession() as session:
124120
async with session.request(
125-
'GET', 'http://staking-lcd-testnet.injective.network/cosmos/auth/v1beta1/accounts/' + address,
126-
headers={'Accept-Encoding': 'application/json'},
121+
"GET",
122+
"http://staking-lcd-testnet.injective.network/cosmos/auth/v1beta1/accounts/" + address,
123+
headers={"Accept-Encoding": "application/json"},
127124
) as response:
128125
if response.status != 200:
129126
print(await response.text())
130127
raise ValueError("HTTP response status", response.status)
131128

132129
resp = json.loads(await response.text())
133-
acc = resp['account']['base_account']
134-
return acc['account_number'], acc['sequence']
130+
acc = resp["account"]["base_account"]
131+
return acc["account_number"], acc["sequence"]
135132

136133

137134
async def post_tx(tx_json: str):
138135
async with aiohttp.ClientSession() as session:
139136
async with session.request(
140-
'POST', 'http://staking-lcd-testnet.injective.network/txs', data=tx_json,
141-
headers={'Content-Type': 'application/json'},
137+
"POST",
138+
"http://staking-lcd-testnet.injective.network/txs",
139+
data=tx_json,
140+
headers={"Content-Type": "application/json"},
142141
) as response:
143142
if response.status != 200:
144143
print(await response.text())
145144
raise ValueError("HTTP response status", response.status)
146145

147146
resp = json.loads(await response.text())
148-
if 'code' in resp:
147+
if "code" in resp:
149148
print("Response:", resp)
150-
raise ValueError('sdk error %d: %s' % (resp['code'], resp['raw_log']))
149+
raise ValueError("sdk error %d: %s" % (resp["code"], resp["raw_log"]))
151150

152-
return resp['txhash']
151+
return resp["txhash"]
153152

154153

155154
@pytest.fixture
156155
async def msg_send():
157-
sender_pk = seed_to_privkey(
158-
"physical page glare junk return scale subject river token door mirror title"
159-
)
156+
sender_pk = seed_to_privkey("physical page glare junk return scale subject river token door mirror title")
160157
sender_acc_addr = privkey_to_address(sender_pk)
161158
print("Sender Account:", sender_acc_addr)
162159

163160
acc_num, acc_seq = await get_account_num_seq(sender_acc_addr)
164161

165-
async with grpc.aio.insecure_channel('testnet-sentry0.injective.network:9910') as channel:
162+
async with grpc.aio.insecure_channel("testnet-sentry0.injective.network:9910") as channel:
166163
accounts_rpc = accounts_rpc_grpc.InjectiveAccountsRPCStub(channel)
167164
account_addr = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
168165

examples/SendToInjective.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ async def main() -> None:
2020
receiver = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
2121
amount = 1
2222

23-
data = ('{"@type": "/injective.exchange.v1beta1.MsgDeposit",'
24-
'"sender": "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",'
25-
'"subaccountId": "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",'
26-
'"amount": {"denom": "inj","amount": "1000000000000000000"}}'
27-
)
23+
data = (
24+
'{"@type": "/injective.exchange.v1beta1.MsgDeposit",'
25+
'"sender": "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",'
26+
'"subaccountId": "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",'
27+
'"amount": {"denom": "inj","amount": "1000000000000000000"}}'
28+
)
2829

2930
with open("../pyinjective/Peggo_ABI.json") as pego_file:
3031
peggo_data = pego_file.read()
@@ -39,8 +40,9 @@ async def main() -> None:
3940
maxFeePerGas=maxFeePerGas_Gwei,
4041
maxPriorityFeePerGas=maxPriorityFeePerGas_Gwei,
4142
data=data,
42-
peggo_abi=peggo_abi
43+
peggo_abi=peggo_abi,
4344
)
4445

46+
4547
if __name__ == "__main__":
4648
asyncio.get_event_loop().run_until_complete(main())

0 commit comments

Comments
 (0)