Skip to content

Commit

Permalink
feat: add selector to constructor ABI (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Dec 13, 2022
1 parent 7203a16 commit 941578f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ethpm_types/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ def signature(self) -> str:
input_args = ", ".join(i.signature for i in self.inputs)
return f"constructor({input_args})"

def selector(self) -> str:
"""
String representing the constructor selector.
"""

input_names = ",".join(i.canonical_type for i in self.inputs)
return f"constructor({input_names})"


class FallbackABI(BaseModel):
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_abi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ethpm_types.abi import ABIType, ConstructorABI


def test_constructor_selector():
constructor = ConstructorABI(
type="constructor",
inputs=[ABIType(name="contract_address", type="address", internalType="address")],
)
assert constructor.selector() == "constructor(address)"

0 comments on commit 941578f

Please sign in to comment.