Skip to content

Commit b16de95

Browse files
committed
Add abi attributes for ContractEvent
1 parent f11674c commit b16de95

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Diff for: newsfragments/3626.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Add abi properties stateMutability, type, inputs, outputs to the ``ContractFunction`` object as ``state_mutability``, ``type``, ``inputs``, ``outputs``.
2+
Add abi properties type, anonymous, inputs to the ``ContractEvent`` object with the same name.

Diff for: tests/core/contracts/test_contract_example.py

+8
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ def test_functions_abi_outputs(w3, foo_contract):
132132
assert foo_contract.functions.bar.outputs == [{"name": "", "type": "string"}]
133133

134134

135+
def test_events_abi(w3, foo_contract):
136+
assert foo_contract.events.barred.type == "event"
137+
assert foo_contract.events.barred.anonymous is False
138+
assert foo_contract.events.barred.inputs == [
139+
{"indexed": False, "name": "_bar", "type": "string"}
140+
]
141+
142+
135143
@pytest.fixture
136144
def async_eth_tester():
137145
return AsyncEthereumTesterProvider().ethereum_tester

Diff for: web3/contract/base_contract.py

+12
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,18 @@ def topic(self) -> HexStr:
209209
self._topic = encode_hex(keccak(text=self.signature))
210210
return self._topic
211211

212+
@property
213+
def type(self) -> str:
214+
return "event"
215+
216+
@property
217+
def anonymous(self) -> Optional[bool]:
218+
return self.abi.get("anonymous")
219+
220+
@property
221+
def inputs(self) -> Optional[List]:
222+
return self.abi.get("inputs")
223+
212224
@combomethod
213225
def _get_event_abi(cls) -> ABIEvent:
214226
if cls.abi:

0 commit comments

Comments
 (0)