Skip to content

Commit

Permalink
fix: could not pay payable functions (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: antazoey <[email protected]>
  • Loading branch information
antazoey and antazoey authored Jan 10, 2025
1 parent 0155f68 commit 6758558
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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

0 comments on commit 6758558

Please sign in to comment.