-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test,feat!: (1) New events and tx resp abstractions. (2) Cater tests …
…to devnet (#180) * feat: add tests for dex * test(common): test parse attributes * feat(pytypes)!: TxResp for easily handling transaction responses - refactor: move types to pytypes. export all types from nibiru.ptypes module. - fix: Find a gas config that works better for the E2E tests. - fix: Get most of the perp tests passing again. * test: use ueth instead of unibi for pricefeed_test. (2) Bump package dev version * docs,refactor(network.py): Dynamically load insecure status using the TM endpoint. Add docstring for 'Network' class. * fix: handle case when the dex pools query returns an empty list * refactor(common.py): Use dataclass for the TxConfig since it's simpler * test: use more semantic names + increase pass rate * (1) dependencies: Use pytest-order to order tests. - (2) test(dex): Remove uusdc as it does not exist on chain * test: passing pricefeed tests * test: passing dex and perp tests * checkpoint #wip * test: improve test ordering and separate large websocket test * test: dex and pricefeed green * test: fix utils_test.py * test: add an env var, "USE_LOCALNET" that lets you test against custom networks * fix(conftest.py) * test,docs: (1) Add additional cases for event_test.py (2) More docstrings * refactor: address PR comments Co-authored-by: Matthias <md2022@matrixsystems.co>
- Loading branch information
1 parent
9f5429e
commit 27ff098
Showing
34 changed files
with
1,152 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# These import statements export the types to 'nibiru.pytypes'. | ||
|
||
from nibiru.pytypes.common import ( # noqa # TODO move constants to a constants.py file.; noqa | ||
GAS_PRICE, | ||
MAX_MEMO_CHARACTERS, | ||
Coin, | ||
Direction, | ||
PoolAsset, | ||
PoolType, | ||
PythonMsg, | ||
Side, | ||
TxConfig, | ||
TxType, | ||
) | ||
from nibiru.pytypes.event import Event, RawEvent, TxLogEvents # noqa | ||
from nibiru.pytypes.tx_resp import RawTxResp, TxResp # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import collections | ||
import pprint | ||
from typing import Dict, List | ||
|
||
|
||
class RawEvent(collections.abc.MutableMapping): | ||
"""Dictionary representing a Tendermint event. In the raw TxOutput of a | ||
successful transaciton, it's the value at | ||
```python | ||
tx_output['rawLog'][0]['events'] | ||
``` | ||
### Keys (KeyType): | ||
- attributes (List[Dict[str,str]]) | ||
- type (str) | ||
### Example: | ||
```python | ||
{'attributes': [ | ||
{'key': 'recipient', 'value': 'nibi1uvu52rxwqj5ndmm59y6atvx33mru9xrz6sqekr'}, | ||
{'key': 'sender', 'value': 'nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl'}, | ||
{'key': 'amount', 'value': '7unibi,70unusd'}], | ||
'type': 'transfer'} | ||
``` | ||
""" | ||
|
||
|
||
class Event: | ||
"""A Tendermint event. An event contains a type and set of attributes. | ||
Events allow application developers to attach additional information to the | ||
'ResponseBeginBlock', 'ResponseEndBlock', 'ResponseCheckTx', and 'ResponseDeliverTx' | ||
functions in the ABCI (application blockchain interface). | ||
In the Tendermint protobuf, the hard definition is: | ||
```proto | ||
message Event { | ||
string type = 1; | ||
repeated EventAttribute attributes = 2; | ||
} | ||
message EventAttribute { | ||
bytes key = 1; | ||
bytes value = 2; | ||
bool index = 3; | ||
} | ||
``` | ||
- Ref: [cosmos-sdk/types/events.go](https://github.com/cosmos/cosmos-sdk/blob/93abfdd21d9892550da315b10308519b43fb1775/types/events.go#L221) | ||
- Ref: [tendermint/tendermint/proto/tendermint/abci/types.proto](https://github.com/tendermint/tendermint/blob/a6dd0d270abc3c01f223eedee44d8b285ae273f6/proto/tendermint/abci/types.proto) | ||
""" | ||
|
||
type: str | ||
attrs: Dict[str, str] | ||
|
||
def __init__(self, raw_event: RawEvent): | ||
self.type = raw_event["type"] | ||
self.attrs = self.parse_attributes(raw_event["attributes"]) | ||
|
||
@staticmethod | ||
def parse_attributes(raw_attributes: List[Dict[str, str]]) -> Dict[str, str]: | ||
try: | ||
attributes: dict[str, str] = { | ||
kv_dict['key']: kv_dict['value'] for kv_dict in raw_attributes | ||
} | ||
return attributes | ||
except: | ||
raise Exception( | ||
f"failed to parse raw attributes:\n{pprint.pformat(raw_attributes)}" | ||
) | ||
|
||
def __repr__(self) -> str: | ||
return f"Event(type={self.type}, attrs={self.attrs})" | ||
|
||
def to_dict(self) -> Dict[str, Dict[str, str]]: | ||
return {self.type: self.attrs} | ||
|
||
|
||
class TxLogEvents: | ||
"""An element of 'TxResp.rawLog'. This object contains events and messages. | ||
Keys (KeyType): | ||
type (str) | ||
attributes (List[EventAttribute]) | ||
Args: | ||
events_raw (List[RawEvent]) | ||
Attributes: | ||
events (List[Event]) | ||
msgs (List[str]) | ||
events_raw (List[RawEvent]) | ||
event_types (List[str]) | ||
""" | ||
|
||
events: List[Event] | ||
msgs: List[str] | ||
events_raw: List[RawEvent] | ||
event_types: List[str] | ||
|
||
def __init__(self, events_raw: List[RawEvent] = []): | ||
self.events_raw = events_raw | ||
self.events = [Event(raw_event) for raw_event in events_raw] | ||
self.msgs = self.get_msg_types() | ||
|
||
def get_msg_types(self) -> List[str]: | ||
|
||
msgs = [] | ||
self.event_types = [] | ||
for event in self.events: | ||
self.event_types.append(event.type) | ||
if event.type == "message": | ||
msgs.append(event.attrs["action"]) | ||
return msgs | ||
|
||
def __repr__(self) -> str: | ||
self_as_dict = dict(msgs=self.msgs, events=[e.to_dict() for e in self.events]) | ||
return pprint.pformat(self_as_dict, indent=2) |
Oops, something went wrong.