feat: add "BaseScript"

refactor: rename "DeployFoo" to just "Deploy"
This commit is contained in:
Paul Razvan Berg 2023-04-29 13:11:35 +03:00
parent 9d38a2be03
commit dd56c9c0f1
No known key found for this signature in database
GPG Key ID: 94DB130BAB397DED
4 changed files with 43 additions and 23 deletions

View File

@ -126,7 +126,7 @@ $ forge coverage
Deploy to Anvil:
```sh
$ forge script script/DeployFoo.s.sol --broadcast --fork-url http://localhost:8545
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545
```
For this script to work, you need to have a `MNEMONIC` environment variable set to a valid

29
script/Base.s.sol Normal file
View File

@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { Script } from "forge-std/Script.sol";
abstract contract BaseScript is Script {
/// @dev Included to enable compilation of the script without a $MNEMONIC environment variable.
string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk";
/// @dev Needed for the deterministic deployments.
bytes32 internal constant ZERO_SALT = bytes32(0);
/// @dev The address of the contract deployer.
address internal deployer;
/// @dev Used to derive the deployer's address.
string internal mnemonic;
constructor() {
mnemonic = vm.envOr("MNEMONIC", TEST_MNEMONIC);
(deployer,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
}
modifier broadcaster() {
vm.startBroadcast(deployer);
_;
vm.stopBroadcast();
}
}

13
script/Deploy.s.sol Normal file
View File

@ -0,0 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19;
import { Foo } from "../src/Foo.sol";
import { BaseScript } from "./Base.s.sol";
/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting
contract Deploy is BaseScript {
function run() public broadcaster returns (Foo foo) {
foo = new Foo();
}
}

View File

@ -1,22 +0,0 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19;
import { Script } from "forge-std/Script.sol";
import { Foo } from "../src/Foo.sol";
/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting
contract DeployFoo is Script {
address internal deployer;
Foo internal foo;
function setUp() public virtual {
string memory mnemonic = vm.envString("MNEMONIC");
(deployer,) = deriveRememberKey(mnemonic, 0);
}
function run() public {
vm.startBroadcast(deployer);
foo = new Foo();
vm.stopBroadcast();
}
}