Skip to content

Commit f09dc7b

Browse files
committed
clean up
1 parent 7d8b793 commit f09dc7b

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

crates/cheatcodes/src/inspector.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,6 @@ impl GasMetering {
253253

254254
/// Stop the gas recording.
255255
pub fn stop(&mut self) {
256-
println!("gas records: {:?}", self.gas_records);
257-
258-
// self.gas_records.iter_mut().for_each(|record| {
259-
// record.gas_used.saturating_add(self.recorded_frames.iter().sum::<u64>());
260-
// });
261-
262-
// reduce sum of gas frames to a single value
263256
self.recording = false;
264257
}
265258

testdata/default/cheats/GasSnapshot.t.sol

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ pragma solidity 0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";
6+
import "../logs/console.sol";
67

78
contract GasSnapshotTest is DSTest {
89
uint256 public slot0;
10+
uint256 public cachedGas = 0;
911

1012
Vm constant vm = Vm(HEVM_ADDRESS);
1113

@@ -48,11 +50,38 @@ contract GasSnapshotTest is DSTest {
4850
function testGasComplex() public {
4951
TargetB target = new TargetB();
5052

53+
// Warm up the cache.
54+
target.update(1);
55+
56+
// Start a cheatcode snapshot.
5157
vm.startSnapshotGas("testAssertGasComplexA");
5258

53-
target.update(1);
59+
target.update(2);
5460

55-
vm.stopSnapshotGas();
61+
uint256 gasA = vm.stopSnapshotGas();
62+
console.log("gas native A", gasA);
63+
64+
// Start a comparitive Solidity snapshot.
65+
66+
// Warm up the cache.
67+
cachedGas = 1;
68+
69+
// Start the Solidity snapshot.
70+
cachedGas = gasleft();
71+
72+
target.update(3);
73+
74+
uint256 gasAfter = gasleft();
75+
76+
console.log("gas solidity", cachedGas - gasAfter - 100);
77+
78+
// Start a cheatcode snapshot.
79+
vm.startSnapshotGas("testAssertGasComplexB");
80+
81+
target.update(4);
82+
83+
uint256 gasB = vm.stopSnapshotGas();
84+
console.log("gas native B", gasB);
5685
}
5786

5887
// Writes to `GasSnapshotTest` group with custom names.

0 commit comments

Comments
 (0)