Skip to content

Commit

Permalink
refactor: rename to contract_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Apr 22, 2024
1 parent d381b0d commit 5142e8d
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/ape/contracts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def range(
pass

if contract:
if creation := contract.creation:
if creation := contract.creation_metadata:
start_block = creation.block

stop_block = start_or_stop
Expand Down Expand Up @@ -887,7 +887,7 @@ def from_receipt(cls, receipt: ReceiptAPI, contract_type: ContractType) -> "Cont
return instance

@property
def creation(self) -> Optional[ContractCreation]:
def creation_metadata(self) -> Optional[ContractCreation]:
"""
Contract creation details: txn_hash, block, deployer, factory, receipt.
"""
Expand Down Expand Up @@ -1144,7 +1144,7 @@ def __dir__(self) -> List[str]:
self.get_event_by_signature.__name__,
self.invoke_transaction.__name__,
self.call_view_method.__name__,
ContractInstance.creation.fget.__name__, # type: ignore[attr-defined]
ContractInstance.creation_metadata.fget.__name__, # type: ignore[attr-defined]
]
return list(
set(self._base_dir_values).union(
Expand Down
2 changes: 1 addition & 1 deletion src/ape/managers/project/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def track_deployment(self, contract: ContractInstance):
if not (contract_name := contract.contract_type.name):
raise ProjectError("Contract name required when publishing.")

if not (creation := contract.creation):
if not (creation := contract.creation_metadata):
raise ProjectError("Unable to find contract creation.")

try:
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/functional/geth/test_gas_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_append_gas(gas_tracker, geth_account, geth_contract):

@geth_process_test
def test_append_gas_deploy(gas_tracker, geth_contract):
tx = geth_contract.creation.receipt
tx = geth_contract.creation_metadata.receipt
trace = tx.trace
gas_tracker.append_gas(trace, geth_contract.address)
report = gas_tracker.session_gas_report
Expand Down
10 changes: 6 additions & 4 deletions tests/functional/geth/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def test_str_and_repr(geth_contract, geth_account, geth_provider):

@geth_process_test
def test_str_and_repr_deploy(geth_contract, geth_provider):
trace = geth_provider.get_transaction_trace(geth_contract.creation.txn_hash)
creation = geth_contract.creation_metadata
trace = geth_provider.get_transaction_trace(creation.txn_hash)
_ = trace.enriched_calltree
expected = rf"{geth_contract.contract_type.name}\.__new__\(\s*num=\d+\s*\) \[\d+ gas\]"
for actual in (str(trace), repr(trace)):
Expand All @@ -179,7 +180,8 @@ def _request(rpc, arguments):
expected = r"0x[a-fA-F0-9]{40}\.0x[a-fA-F0-9]+\(\) \[\d+ gas\]"

try:
trace = mock_geth.get_transaction_trace(geth_contract.creation.txn_hash)
creation = geth_contract.creation_metadata
trace = mock_geth.get_transaction_trace(creation.txn_hash)
assert isinstance(trace, Trace)
for actual in (str(trace), repr(trace)):
assert re.match(expected, actual), actual
Expand Down Expand Up @@ -232,7 +234,7 @@ def test_get_gas_report(gas_tracker, geth_account, geth_contract):

@geth_process_test
def test_get_gas_report_deploy(gas_tracker, geth_contract):
tx = geth_contract.creation.receipt
tx = geth_contract.creation_metadata.receipt
trace = tx.trace
actual = trace.get_gas_report()
contract_name = geth_contract.contract_type.name
Expand All @@ -242,7 +244,7 @@ def test_get_gas_report_deploy(gas_tracker, geth_contract):

@geth_process_test
def test_transaction_trace_create(vyper_contract_instance):
tx_hash = vyper_contract_instance.creation.txn_hash
tx_hash = vyper_contract_instance.creation_metadata.txn_hash
trace = TransactionTrace(transaction_hash=tx_hash)
actual = f"{trace}"
expected = r"VyperContract\.__new__\(num=0\) \[\d+ gas\]"
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/test_contract_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ def test_call_transact(vyper_contract_instance, owner):


def test_creation_receipt(contract_instance, owner):
assert contract_instance.creation is not None
receipt = contract_instance.creation.receipt
assert contract_instance.creation_metadata is not None
receipt = contract_instance.creation_metadata.receipt
assert receipt.txn_hash == contract_instance.txn_hash
assert receipt.contract_address == contract_instance.address
assert receipt.sender == owner
Expand Down Expand Up @@ -590,7 +590,7 @@ def test_dir(vyper_contract_instance):
"code",
"contract_type",
"codesize",
"creation",
"creation_metadata",
"decode_input",
"get_event_by_signature",
"invoke_transaction",
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_gas_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_append_gas(gas_tracker, owner, vyper_contract_instance):


def test_append_gas_deploy(gas_tracker, vyper_contract_instance):
tx = vyper_contract_instance.creation.receipt
tx = vyper_contract_instance.creation_metadata.receipt
trace = tx.trace
gas_tracker.append_gas(trace, vyper_contract_instance.address)
report = gas_tracker.session_gas_report
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def deployment_path(vyper_contract_instance, base_deployments_path):

@pytest.fixture
def contract_block_hash(eth_tester_provider, vyper_contract_instance):
block_number = vyper_contract_instance.creation.block
block_number = vyper_contract_instance.creation_metadata.block
return eth_tester_provider.get_block(block_number).hash.hex()


Expand Down Expand Up @@ -272,7 +272,7 @@ def test_track_deployment(
bip122_chain_id,
):
contract = vyper_contract_instance
receipt = contract.creation.receipt
receipt = contract.creation_metadata.receipt
name = contract.contract_type.name
address = vyper_contract_instance.address

Expand Down Expand Up @@ -308,7 +308,7 @@ def test_track_deployment_from_previously_deployed_contract(
bip122_chain_id,
):
deploy = owner.deploy(vyper_contract_container, 0, required_confirmations=0)
receipt = deploy.creation.receipt
receipt = deploy.creation_metadata.receipt
address = receipt.contract_address
contract = Contract(address, txn_hash=receipt.txn_hash)
name = contract.contract_type.name
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@pytest.fixture
def deploy_receipt(vyper_contract_instance):
return vyper_contract_instance.creation.receipt
return vyper_contract_instance.creation_metadata.receipt


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_get_gas_report(gas_tracker, owner, vyper_contract_instance):


def test_get_gas_report_deploy(gas_tracker, vyper_contract_instance):
tx = vyper_contract_instance.creation.receipt
tx = vyper_contract_instance.creation_metadata.receipt
trace = tx.trace
actual = trace.get_gas_report()
contract_name = vyper_contract_instance.contract_type.name
Expand All @@ -50,7 +50,7 @@ def test_get_gas_report_transfer(gas_tracker, sender, receiver):


def test_transaction_trace_create(vyper_contract_instance):
trace = TransactionTrace(transaction_hash=vyper_contract_instance.creation.txn_hash)
trace = TransactionTrace(transaction_hash=vyper_contract_instance.creation_metadata.txn_hash)
actual = f"{trace}"
expected = r"VyperContract\.__new__\(num=0\) \[\d+ gas\]"
assert re.match(expected, actual)
Expand Down

0 comments on commit 5142e8d

Please sign in to comment.