Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow setting sign to False
Browse files Browse the repository at this point in the history
antazoey committed Jan 31, 2025
1 parent 6f5e848 commit 7ae6878
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ape/api/accounts.py
Original file line number Diff line number Diff line change
@@ -258,7 +258,8 @@ def transfer(
if txn.value < 0:
raise AccountsError("Value cannot be negative.")

return self.call(txn, private=private, **kwargs)
sign = kwargs.pop("sign", True)
return self.call(txn, private=private, sign=sign, **kwargs)

def deploy(
self, contract: "ContractContainer", *args, publish: bool = False, **kwargs
3 changes: 2 additions & 1 deletion src/ape/contracts/base.py
Original file line number Diff line number Diff line change
@@ -90,7 +90,8 @@ def __call__(self, private: bool = False, *args, **kwargs) -> "ReceiptAPI":

if "sender" in kwargs and hasattr(kwargs["sender"], "call"):
sender = kwargs["sender"]
return sender.call(txn, **kwargs)
sign = kwargs.pop("sign", True)
return sender.call(txn, sign=sign, **kwargs)
elif "sender" not in kwargs and self.account_manager.default_sender is not None:
return self.account_manager.default_sender.call(txn, **kwargs)

5 changes: 5 additions & 0 deletions tests/functional/test_accounts.py
Original file line number Diff line number Diff line change
@@ -261,6 +261,11 @@ def test_transfer_mixed_up_sender_and_value(sender, receiver):
sender.transfer("123 wei", receiver)


def test_transfer_sign_is_false(sender, receiver):
with pytest.raises(SignatureError):
sender.transfer(receiver, "1 gwei", sign=False)


def test_deploy(owner, contract_container, clean_contract_caches):
contract = owner.deploy(contract_container, 0)
assert contract.address
6 changes: 6 additions & 0 deletions tests/functional/test_contract_instance.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
ContractLogicError,
CustomError,
MethodNonPayableError,
SignatureError,
)
from ape.types.address import AddressType
from ape_ethereum.transactions import TransactionStatusEnum, TransactionType
@@ -74,6 +75,11 @@ def test_contract_transactions(owner, contract_instance):
assert contract_instance.myNumber() == 2


def test_contract_transaction_when_sign_false(owner, contract_instance):
with pytest.raises(SignatureError):
contract_instance.setNumber(2, sender=owner, sign=False)


def test_wrong_number_of_arguments(owner, contract_instance):
if "sol" in contract_instance.contract_type.source_id.lower():
second = r"\n\t.*setNumber\(uint256 num, address _address\).*"

0 comments on commit 7ae6878

Please sign in to comment.