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(cheatcodes): access broadcast artifacts #9107

Merged
merged 56 commits into from
Oct 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
95ad043
refac(`script`): extract script sequence and related types to new crate
yash-atreya Oct 11, 2024
4ac9e83
replace MultiChainSequence in script crate
yash-atreya Oct 11, 2024
7c23df8
replace TransactionWithMetadata and AdditionalContract
yash-atreya Oct 11, 2024
3870290
replace ScriptSequence
yash-atreya Oct 11, 2024
3da2355
replace all underlying ScriptSequence and related types
yash-atreya Oct 11, 2024
c06159b
doc nits
yash-atreya Oct 11, 2024
159f51d
Merge branch 'master' into yash/refac-script-sequence
yash-atreya Oct 14, 2024
a7237f8
add `ScriptTransactionBuilder`
yash-atreya Oct 14, 2024
388ce6b
remove `TxWithMetadata`
yash-atreya Oct 14, 2024
f20e276
mv verify fns and use `ScriptSequence` directly
yash-atreya Oct 14, 2024
a32c3c4
clippy
yash-atreya Oct 14, 2024
9c38c02
feat(`cheatcodes`): vm.getDeployment
yash-atreya Oct 14, 2024
6e6ced1
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 16, 2024
f0c863f
cargo cheats
yash-atreya Oct 16, 2024
f7ccff7
getBroadcast by txType
yash-atreya Oct 16, 2024
9a829c4
get all broadcast txs
yash-atreya Oct 16, 2024
b273968
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 18, 2024
c91546c
nits
yash-atreya Oct 18, 2024
caea855
fix
yash-atreya Oct 18, 2024
bbc53d6
feat: getBroadcasts by txType
yash-atreya Oct 18, 2024
80a86e1
nit
yash-atreya Oct 18, 2024
15bf2cf
fix
yash-atreya Oct 18, 2024
32704c1
mv `BroadcastReader` to script-sequence
yash-atreya Oct 18, 2024
0881db6
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 22, 2024
11f12c9
fix: search all broadcast files and then apply filters
yash-atreya Oct 22, 2024
28e1309
fix: ignore run-latest to avoid duplicating entries
yash-atreya Oct 22, 2024
5769329
nit
yash-atreya Oct 22, 2024
da67563
sort by descending block number
yash-atreya Oct 22, 2024
9646bac
tests
yash-atreya Oct 22, 2024
3ed202b
feat(`CheatsConfig`): add `broadcast` dir path
yash-atreya Oct 23, 2024
83e2184
feat: read multichain sequences
yash-atreya Oct 23, 2024
9cdca2e
nit
yash-atreya Oct 23, 2024
6ae60a5
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 23, 2024
4ce9df2
minify json
yash-atreya Oct 23, 2024
687aaf0
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 24, 2024
1b302f5
use walkdir
yash-atreya Oct 24, 2024
9223724
fix
yash-atreya Oct 24, 2024
af2426e
Merge branch 'master' into yash/get-deployment-data
yash-atreya Oct 28, 2024
084f45e
fix path
yash-atreya Oct 28, 2024
f430821
feat: getDeployment cheatcodes
yash-atreya Oct 28, 2024
970452d
feat: read broadcasts with multiple tx types
yash-atreya Oct 28, 2024
6db3976
test: getDeployment
yash-atreya Oct 28, 2024
5b2ed48
nit
yash-atreya Oct 28, 2024
bf47b35
fmt
yash-atreya Oct 28, 2024
8a64238
fix
yash-atreya Oct 28, 2024
17e2e1f
nit
yash-atreya Oct 28, 2024
e5ca585
cli test
yash-atreya Oct 28, 2024
0f7bde5
nit
yash-atreya Oct 28, 2024
4dcfab1
remove solidity test
yash-atreya Oct 28, 2024
d7818cb
nit
yash-atreya Oct 28, 2024
0e6af96
nit
yash-atreya Oct 29, 2024
2f4ab12
fix
yash-atreya Oct 29, 2024
1418d93
nits
yash-atreya Oct 29, 2024
118c694
use find
yash-atreya Oct 29, 2024
6b8083a
fix: use absolute broadcast path in `CheatsConfig`
yash-atreya Oct 29, 2024
72274d3
feat: getDeployment current chain
yash-atreya Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cli test
  • Loading branch information
yash-atreya committed Oct 28, 2024
commit e5ca585a83feea8784267f525c5cd14fc66ce821
203 changes: 203 additions & 0 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Contains various tests for `forge test`.

use alloy_primitives::U256;
use anvil::{spawn, NodeConfig};
use foundry_config::{Config, FuzzConfig};
use foundry_test_utils::{
rpc, str,
Expand Down Expand Up @@ -2390,3 +2391,205 @@ contract Dummy {

assert!(dump_path.exists());
});

forgetest_async!(can_get_broadcast_txs, |prj, cmd| {
foundry_test_utils::util::initialize(prj.root());

let (api, handle) = spawn(NodeConfig::test().silent()).await;

let chain_id = api.chain_id();
prj.insert_vm();
prj.insert_ds_test();
prj.insert_console();

prj.add_source(
"Counter.sol",
r#"
contract Counter {
uint256 public number;

function setNumber(uint256 newNumber) public {
number = newNumber;
}

function increment() public {
number++;
}
}
"#,
)
.unwrap();

prj.add_script(
"DeployCounter",
r#"
import "forge-std/Script.sol";
import "src/Counter.sol";

contract DeployCounter is Script {
function run() public {
vm.startBroadcast();

Counter counter = new Counter();

counter.increment();

counter.setNumber(10);

vm.stopBroadcast();
}
}
"#,
)
.unwrap();

prj.add_script(
"DeployCounterWithCreate2",
r#"
import "forge-std/Script.sol";
import "src/Counter.sol";

contract DeployCounterWithCreate2 is Script {
function run() public {
vm.startBroadcast();

bytes32 salt = bytes32(uint256(1337));
Counter counter = new Counter{salt: salt}();

counter.increment();

counter.setNumber(20);

vm.stopBroadcast();
}
}
"#,
)
.unwrap();

let test = r#"
import {Vm} from "../src/Vm.sol";
import {DSTest} from "../src/test.sol";
import {console} from "../src/console.sol";

contract GetBroadcastTest is DSTest {

Vm constant vm = Vm(HEVM_ADDRESS);

function test_getLatestBroacast() external {
// Gets the latest create
Vm.BroadcastTxSummary memory broadcast = vm.getBroadcast(
"Counter",
{chain_id},
Vm.BroadcastTxType.Create
);

console.log("latest create");
console.log(broadcast.blockNumber);

assertEq(broadcast.blockNumber, 1);

// Gets the latest create2
Vm.BroadcastTxSummary memory broadcast2 = vm.getBroadcast(
"Counter",
{chain_id},
Vm.BroadcastTxType.Create2
);

console.log("latest create2");
console.log(broadcast2.blockNumber);
assertEq(broadcast2.blockNumber, 4);

// Gets the latest call
Vm.BroadcastTxSummary memory broadcast3 = vm.getBroadcast(
"Counter",
{chain_id},
Vm.BroadcastTxType.Call
);

console.log("latest call");
assertEq(broadcast3.blockNumber, 6);
}

function test_getBroadcasts() public {
// Gets all calls
Vm.BroadcastTxSummary[] memory broadcasts = vm.getBroadcasts(
"Counter",
{chain_id},
Vm.BroadcastTxType.Call
);

assertEq(broadcasts.length, 4);
}

function test_getAllBroadcasts() public {
// Gets all broadcasts
Vm.BroadcastTxSummary[] memory broadcasts2 = vm.getBroadcasts(
"Counter",
{chain_id}
);

assertEq(broadcasts2.length, 6);
}

function test_getLatestDeployment() public {
address deployedAddress = vm.getDeployment(
"Counter",
{chain_id}
);

assertEq(deployedAddress, address(0x030D07c16e2c0a77f74ab16f3C8F10ACeF89FF81));
}

function test_getDeployments() public {
address[] memory deployments = vm.getDeployments(
"Counter",
{chain_id}
);

assertEq(deployments.length, 2);
}

}
"#;

let test = test.replace("{chain_id}", &chain_id.to_string());

prj.add_test("GetBroadcast", &test).unwrap();

let sender = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";

cmd.args([
"script",
"DeployCounter",
"--rpc-url",
&handle.http_endpoint(),
"--sender",
sender,
"--unlocked",
"--broadcast",
"--slow",
])
.assert_success();

cmd.forge_fuse()
.args([
"script",
"DeployCounterWithCreate2",
"--rpc-url",
&handle.http_endpoint(),
"--sender",
sender,
"--unlocked",
"--broadcast",
"--slow",
])
.assert_success();

let broadcast_path = prj.root().join("broadcast");

// Check if the broadcast folder exists
assert!(broadcast_path.exists() && broadcast_path.is_dir());

cmd.forge_fuse().args(["test", "--mc", "GetBroadcastTest", "-vvv"]).assert_success();
});