Code Monkey home page Code Monkey logo

foundry-devops's Introduction

foundry-devops

A repo to get the most recent deployment from a given environment in foundry. This way, you can do scripting off previous deployments in solidity.

It will look through your broadcast folder at your most recent deployment.

Getting Started

Requirements

  • git
    • You'll know you did it right if you can run git --version and you see a response like git version x.x.x
  • foundry
    • You'll know you did it right if you can run forge --version and you see a response like forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)
  • jq
    • A lot already have it installed. Try it with jq --version and see a response like jq-1.6

Installation

forge install Cyfrin/foundry-devops --no-commit
  • Update forge-std to use newer FS cheatcodes
git rm -rf lib/forge-std
 rm -rf lib/forge-std
 forge install foundry-rs/[email protected] --no-commit

Usage

  1. Update your foundry.toml to have read permissions on the broadcast folder.
fs_permissions = [{ access = "read", path = "./broadcast" }]
  1. Import the package, and call DevOpsTools.get_most_recent_deployment("MyContract", chainid);

ie:

import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
import {MyContract} from "my-contract/MyContract.sol";
.
.
.
function interactWithPreviouslyDeployedContracts() public {
    address contractAddress = DevOpsTools.get_most_recent_deployment("MyContract", block.chainid);
    MyContract myContract = MyContract(contractAddress);
    myContract.doSomething();
}

Contributing

PRs are welcome!

git clone https://github.com/Cyfrin/foundry-devops
cd foundry-devops
forge install

Testing

forge test

foundry-devops's People

Contributors

allwin199 avatar chefaharoni avatar ikpong-joseph avatar klkvr avatar mds1 avatar mon-1 avatar patrickalphac avatar robocrypter avatar rocknet avatar shikhar229169 avatar tilakmaddy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

foundry-devops's Issues

`vm.keyExists` has been deprecated

I'm currently writing the Lesson 19: Create integration tutorial from Section 1: Fund Me. In there we use the DevOpsTools.get_most_recent_deployment function to get the most recently deployed address of FundMe. The project doesn't build for the following reason:

[⠰] Compiling...
[⠒] Compiling 29 files with Solc 0.8.19
[⠢] Solc 0.8.19 finished in 578.90ms
Error: 
Compiler run failed:
Error (9582): Member "keyExists" not found or not visible after argument-dependent lookup in contract Vm.
   --> lib/foundry-devops/src/DevOpsTools.sol:119:13:
    |
119 |         if (vm.keyExists(json, "$.transactions[0].rpc")) {
    |         

Searching for keyExists in the Foundry Handbook we find out that this cheatcode has been deprecated in favor of keyExistsJson.

I tried replacing the keyExists in lib/foundry-devops/src/DevOpsTools.sol:119 with keyExistsJson but it errored out due to:

[⠰] Compiling...
[⠊] Compiling 29 files with Solc 0.8.19
[⠒] Solc 0.8.19 finished in 559.33ms
Error: 
Compiler run failed:
Error (9582): Member "keyExistsJson" not found or not visible after argument-dependent lookup in contract Vm.
   --> lib/foundry-devops/src/DevOpsTools.sol:119:13:
    |
119 |         if (vm.keyExistsJson(json, "$.transactions[0].rpc")) {
    |             ^^^^^^^^^^^^^^^^

I searched for this function in the Vm.sol of the forge-std that foundry-devops uses and it's not there because the forge-std is too old.

Please update the forge-std libray and replace vm.keyExists with vm.keyExistsJson at foundry-devops/src/DevOpsTools.sol:119

Add Details to update forge-std library

#10 (comment)

As mentioned in the above comment cheat codes like Vm.DirEntry[] and vm.keyExists are available only in the versions above 6.0.

Another issue I noticed is If we don't update forge-std lib. During contract verification, only the DevOpsTools contract is verified.

Adding commands mentioned in the original PR will help.

forge rm forge-std -f
forge install foundry-rs/[email protected]

I am willing to make these changes.

"No contract deployed" error, no known non-standard file location

Hi, I'd like to sort out a "no contract deployed" error while deploying to the Arbitrum testnet. Here were the steps I took:

  1. forge init
  2. install foundry-devops
  3. deploy "ConfigManager" contract from src/ConfigManager.sol with script ConfigManager.s.sol (below)
  4. confirm that broadcast/ConfigManager.s.sol/421613/run-latest.json exists
  5. attempt to run GetConfigManager.s.sol which uses foundry-devops to retrieve the latest deployment
  6. get "No contract deployed" error
  7. check paths/try relative/absolute paths - nothing seems to be misplaced, still getting error
  8. scratch head for a while, time to ask the expert. glad to provide any other info

Thanks in advance for any advice!

-curion

ConfigManager.s.sol:

  pragma solidity ^0.8.15;
  
  import {ConfigManager} from "src/ConfigManager.sol";
  import "lib/forge-std/src/Script.sol";
  
  contract ConfigDeployScript is Script {
  
      ConfigManager public config;
  
      function run() public {
          vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
  
          config = new ConfigManager();
  
          vm.stopBroadcast();
      }
  }

GetConfigManager.s.sol:

  pragma solidity ^0.8.15;
  
  import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
  import {ConfigManager} from "src/ConfigManager.sol";
  import "lib/forge-std/src/Script.sol";
  
  contract GetConfigScript is Script {
  
      ConfigManager public config;
      uint256 public CHAIN_ID = 421613;
  
      function run() public {
          vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
  
          address configAddress = DevOpsTools.get_most_recent_deployment("ConfigManager", CHAIN_ID);
          config = ConfigManager(configAddress); 
  
          vm.stopBroadcast();
      }
  
  }

Traces:

  [777837] → new DevOpsTools@0x4B56260B13555A87725dF82Fe524E0e7afB74409
    └─ ← 3885 bytes of code

  [362678] → new GetConfigScript@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
    └─ ← 1477 bytes of code

  [76886] GetConfigScript::run()
    ├─ [0] VM::envUint(PRIVATE_KEY) [staticcall]
    │   └─ ← <env var value>
    ├─ [0] VM::startBroadcast(<pk>)
    │   └─ ← ()
    ├─ [46254] DevOpsTools::e374cdf1(00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000066eed000000000000000000000000000000000000000000000000000000000000000d436f6e6669674d616e6167657200000000000000000000000000000000000000) [delegatecall]
    │   ├─ [0] VM::ffi([pwd])
    │   │   └─ ← 0x2f686f6d652f637572696f6e2f63727970746f5f6465762f7a4b6172726f742f6b6172726f742d617262
    │   ├─ [0] VM::toString(421613) [staticcall]
    │   │   └─ ← 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000063432313631330000000000000000000000000000000000000000000000000000
    │   ├─ [0] VM::ffi([bash, /home/curion/crypto_dev/projectname/projectname-arb/lib/foundry-devops/src/get_recent_deployment.sh, ConfigManager, 421613, /home/curion/crypto_dev/projectname/projectname-arb//broadcast])
    │   │   └─ ← 0x0000000000000000000000000000000000000000
    │   ├─ [0] console::log(Return Data:) [staticcall]
    │   │   └─ ← ()
    │   ├─ [0] console::log(0x0000000000000000000000000000000000000000) [staticcall]
    │   │   └─ ← ()
    │   └─ ← 0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000144e6f20636f6e7472616374206465706c6f796564000000000000000000000000
    └─ ← "No contract deployed"

Import Errors in DevOpsTools.sol

import {Vm} from "forge-std/Vm.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {StdCheatsSafe} from "forge-std/StdCheats.sol";
import {console} from "forge-std/console.sol";

While using the above lines of code. I am getting an error file not found.

I have replaced it with relative paths and it worked.

import {Vm} from "../../forge-std/src/Vm.sol";
import {stdJson} from "../../forge-std/src/StdJson.sol";
import {StdCheatsSafe} from "../../forge-std/src/StdCheats.sol";
import {console} from "../../forge-std/src/console.sol";

Let me know If I am missing something.

avoid deployment of library contract

on the 0.1.0 tag:

if you call the get_most_recent_deployment function outside the broadcast and then deploy a contract in the same script it will deploy an additional DevOpsTools contract as a library.


on the master branch:

if you provide 3 arguments to the get_most_recent_deployment outside the broadcast and then deploy a contract in the same script it will deploy an additional DevOpsTools contract as a library.


PR: #19

Facing Error - No contract deployed

This package is not able to read the latest deployed address.

Screenshot 2023-05-28 at 5 54 04 PM Screenshot 2023-05-28 at 5 54 15 PM

But if I specify the latest address manually then I can run the script successfully.

Screenshot 2023-05-28 at 5 54 45 PM Screenshot 2023-05-28 at 5 54 53 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.