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

feat: Raise warning if value= is specified for anything but a payable function [APE-1283] #1599

Merged
merged 37 commits into from
Aug 17, 2023
Merged

feat: Raise warning if value= is specified for anything but a payable function [APE-1283] #1599

merged 37 commits into from
Aug 17, 2023

Conversation

Aviksaikat
Copy link
Contributor

@Aviksaikat Aviksaikat commented Aug 10, 2023

What I did

Raise warning if value= is specified for anything but a payable function

fixes: #1396 (Raise warning if value= is specified for anything but a payable function [APE-874])

How I did it

Added check to see if msg.value is getting passed to a non-payable contract

How to verify it

  1. Create a contract with a non-payable constructor like this
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract NonPayableConstructor {

    address public owner;
    constructor() {
        owner = msg.sender;
    }

    function getOwner() external view returns(address){
        return owner;
    }

}
  1. Create a test or script with the following contents
#!/usr/bin/python3
from ape import project, accounts

user = accounts[1]
user.set_autosign(True)
user.balance += int(100e18)


def test_NonPayableConstructor():
    npc = project.NonPayableConstructor.deploy(sender=user, value="1 ether")
    
    print(npc.getOwner())

def main():
    test_NonPayableConstructor()
  1. run using ape run path/to/script or ape test -k testName
  2. You will see an expectation like this ERROR: (ContractError) Sending funds to a non-payable constructor!!
    image

Checklist

  • All changes are completed
  • New test cases have been added
  • Documentation has been updated (Only applicable if there is a page for Exceptions) you added a docstring to the excpetion, that will get autogenerated

Aviksaikat and others added 21 commits May 31, 2023 22:47
@vany365 vany365 changed the title feat: Raise warning if value= is specified for anything but a payable function feat: Raise warning if value= is specified for anything but a payable function [APE-1283] Aug 10, 2023
fubuloubu
fubuloubu previously approved these changes Aug 11, 2023
Copy link
Member

@fubuloubu fubuloubu left a comment

Choose a reason for hiding this comment

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

Needs a test

src/ape/contracts/base.py Outdated Show resolved Hide resolved
Aviksaikat and others added 5 commits August 12, 2023 01:49
…loy test added & working on test_sending_funds_to_non_payable_constructor_by_accountDeploy
…loy test added & test_sending_funds_to_non_payable_constructor_by_accountDeploy & hopefully final commit. file updated, ~ape/api/accounts.py, ~ape/contracts/base.py, ~ape/exceptions.py, tests/functional/test_contract_instance.py
src/ape/exceptions.py Outdated Show resolved Hide resolved
…rror & exception type changed from ApeException to ContractError
…rror & exception type changed from ApeException to ContractError. fixing the last blunder
fubuloubu
fubuloubu previously approved these changes Aug 13, 2023
src/ape/api/accounts.py Show resolved Hide resolved
fubuloubu
fubuloubu previously approved these changes Aug 16, 2023
src/ape/exceptions.py Outdated Show resolved Hide resolved
@fubuloubu fubuloubu enabled auto-merge (squash) August 16, 2023 13:16
@fubuloubu fubuloubu merged commit bd53369 into ApeWorX:main Aug 17, 2023
17 checks passed
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.

Raise warning if value= is specified for anything but a payable function [APE-874]
3 participants