Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add receipt / txn_hash to ContractInstance #955

Merged

Conversation

antazoey
Copy link
Contributor

@antazoey antazoey commented Aug 9, 2022

What I did

fixes: #806

  • Adds txn_hash to ContractInstance that gets set whenever possible, such as after deployments as well as if instantiating a contract that was previously deployed (using the instance_at() method).
  • Adds .receipt() convenience property to the ContractInstance. Now, after you deploy, you have access to the receipt pretty immediate.

This is needed to unblock my work for publishing deployments but is also kind of nice to have anyway and I think exists in Brownie.

How I did it

  • Add txn_hash arguments to contracts.instance_at() and contract.at()
  • Add transaction_hash key to the deployments cache
  • Set the txn_hash automatically when calling .deploy()
  • Have instance_at() try to look up the txn_hash when it is not provided (if it was from a deployment)
  • Had to refactor a little bit 馃槄 but ultimately feels like a nice iteration.

How to verify it

Make sure you can access the txn hash and receipt on a contract instance:

assert contract.txn_hash
assert contract.receipt

Checklist

  • All changes are completed
  • New test cases have been added
  • Documentation has been updated

@antazoey antazoey marked this pull request as ready for review August 9, 2022 14:48
@NotPeopling2day NotPeopling2day self-requested a review August 9, 2022 15:51
NotPeopling2day
NotPeopling2day previously approved these changes Aug 9, 2022
Copy link
Contributor

@NotPeopling2day NotPeopling2day left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran a few examples locally and looks great to me!

johnson2427
johnson2427 previously approved these changes Aug 9, 2022
Copy link
Contributor

@johnson2427 johnson2427 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave an approval, but I made one suggestion, which you can implement if you think it's necessary

docs/userguides/transactions.md Show resolved Hide resolved
@@ -92,11 +92,9 @@ def test_snapshot_and_restore_unknown_snapshot_id(chain):

def test_snapshot_and_restore_no_snapshots(chain):
chain._snapshots = [] # Ensure empty (gets set in test setup)
with pytest.raises(ChainError) as err:
with pytest.raises(ChainError, match="There are no snapshots to revert to."):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know this existed, this is a really nice implementation

@antazoey antazoey merged commit 16c7a82 into ApeWorX:main Aug 9, 2022
@antazoey antazoey deleted the feat/jules/contract-instance-receipts branch August 9, 2022 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose the transaction receipt when deploying a contract
3 participants