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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: could not pay payable functions #6

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ape_titanoboa/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def send_transaction(self, txn: "TransactionAPI") -> "ReceiptAPI":
is_modifying=True,
sender=txn.sender,
receiver=txn.receiver,
value=txn.value,
)

else:
Expand Down Expand Up @@ -576,13 +577,15 @@ def _execute_code(
sender: Optional[Union[str, bytes]] = None,
receiver: Optional[Union[str, bytes]] = None,
is_modifying: bool = False,
value: int = 0,
):
return self.env.execute_code(
data=data,
gas=gas,
is_modifying=is_modifying,
sender=sender,
to_address=receiver,
value=value,
)


Expand Down
5 changes: 5 additions & 0 deletions tests/contracts/VyperContract.vy
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ def setNumber(num: uint256) -> uint256:
log NumberChange(block.prevhash, self.prevNumber, "Dynamic", num, "Dynamic")
return num + 5

@payable
@external
def gimmeMoney():
assert msg.value > 0, "Value must be greater than zero"

@external
def setAddress(_address: address):
self.theAddress = _address
Expand Down
12 changes: 7 additions & 5 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import pytest
from ape import Contract, reverts
from ape.exceptions import (
BlockNotFoundError,
ContractLogicError,
TransactionNotFoundError,
)
from ape.exceptions import BlockNotFoundError, ContractLogicError, TransactionNotFoundError
from eth.exceptions import Revert
from eth_utils import to_hex
from hexbytes import HexBytes
Expand Down Expand Up @@ -72,6 +68,12 @@ def test_send_transaction(chain, contract_instance, contract, owner, networks, n
assert tx.failed


def test_send_transaction_payable(contract_instance, owner):
contract_instance.gimmeMoney(value=1, sender=owner)
with reverts():
contract_instance.gimmeMoney(sender=owner)


def test_send_call(contract_instance, owner, contract, networks):
result = contract_instance.myNumber()
assert result == 123
Expand Down
Loading