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

Make VyperDeployer inherit from Test #1

Open
JoshOrndorff opened this issue Jun 10, 2023 · 0 comments
Open

Make VyperDeployer inherit from Test #1

JoshOrndorff opened this issue Jun 10, 2023 · 0 comments

Comments

@JoshOrndorff
Copy link

I'm just reposting this excellent comment from 0xKitsune/Foundry-Vyper#1 (comment)

Hey after taking a look I've got a few suggestions, first I think we should change the name of VyperDeployer.sol -> VyperTest.sol and rewrite the file to look something like this:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Test.sol";

abstract contract VyperTest is Test {

    function compileVyper(
        string memory fileLocation
    ) public returns (bytes memory byteCode) {
        string[] memory cmds = new string[](2);
        cmds[0] = "vyper";
        cmds[1] = fileLocation;
        return vm.ffi(cmds);
    }

    function compileVyper(
        string memory fileLocation, 
        bytes memory args
    ) public returns (bytes memory byteCodeWithArgs) {
        string[] memory cmds = new string[](2);
        cmds[0] = "vyper";
        cmds[1] = fileLocation;
        return abi.encodePacked(vm.ffi(cmds), args);
    }

    function deployByteCode(
        bytes memory vyperByteCode
    ) public returns (address contractAddr) {
        assembly {
            contractAddr := create(0, add(vyperByteCode, 0x20), mload(vyperByteCode))
        }
        require(
            contractAddr != address(0) && contractAddr.code.length > 0,
            "Vyper contract deployment failed"
        );
    }

    function deployContract(
        string memory fileLocation
    ) public returns (address contractAddr) {
        return deployByteCode(compileVyper(fileLocation));
    }

    function deployContract(
        string memory fileLocation, 
        bytes memory args
    ) public returns (address contractAddr) {
        return deployByteCode(compileVyper(fileLocation, args));
    }
}
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

No branches or pull requests

1 participant