Skip to content

Commit 6d198eb

Browse files
committed
Forge fmt new backtraces tests
1 parent 39f2cc6 commit 6d198eb

13 files changed

+87
-92
lines changed

crates/forge/tests/cli/backtrace.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Backtrace:
3737
...
3838
Backtrace:
3939
at DelegateTarget.compute (src/DelegateCall.sol:11:84)
40-
at DelegateCaller.delegateCompute (src/DelegateCall.sol:33:20)
40+
at DelegateCaller.delegateCompute (src/DelegateCall.sol:32:101)
4141
at BacktraceTest.testDelegateCallRequire (test/Backtrace.t.sol:82:57)
4242
4343
[FAIL: Delegate call failed] testDelegateCallRevert() ([GAS])
@@ -84,7 +84,7 @@ Backtrace:
8484
...
8585
Backtrace:
8686
at StaticTarget.compute (src/StaticCall.sol:11:77)
87-
at StaticCaller.staticCompute (src/StaticCall.sol:32:20)
87+
at StaticCaller.staticCompute (src/StaticCall.sol:30:124)
8888
at BacktraceTest.testStaticCallRequire (test/Backtrace.t.sol:92:60)
8989
9090
[FAIL: Static call reverted] testStaticCallRevert() ([GAS])
@@ -464,7 +464,7 @@ Ran 5 tests for test/ForkBacktrace.t.sol:ForkBacktraceTest
464464
Backtrace:
465465
at 0x43506849D7C04F9138D1A2050bbF3A0c054402dd.transfer
466466
at 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48.transfer
467-
at ForkBacktraceTest.testDirectOnChainRevert (test/ForkBacktrace.t.sol:38:20)
467+
at ForkBacktraceTest.testDirectOnChainRevert (test/ForkBacktrace.t.sol:36:126)
468468
469469
[FAIL: ERC20: transfer amount exceeds balance] testNestedFailure() ([GAS])
470470
...

crates/forge/tests/fixtures/backtraces/DelegateCall.sol

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ contract DelegateTarget {
66
function fail() public pure {
77
revert("Delegate target failed");
88
}
9-
9+
1010
function compute(uint256 a, uint256 b) public pure returns (uint256) {
1111
require(a > 0, "a must be positive");
1212
require(b > 0, "b must be positive");
@@ -16,21 +16,20 @@ contract DelegateTarget {
1616

1717
contract DelegateCaller {
1818
address public target;
19-
19+
2020
constructor(address _target) {
2121
target = _target;
2222
}
23-
23+
2424
function delegateFail() public {
2525
(bool success,) = target.delegatecall(abi.encodeWithSignature("fail()"));
2626
require(success, "Delegate call failed");
2727
}
28-
28+
2929
function delegateCompute(uint256 a, uint256 b) public returns (uint256) {
30-
(bool success, bytes memory data) = target.delegatecall(
31-
abi.encodeWithSignature("compute(uint256,uint256)", a, b)
32-
);
30+
(bool success, bytes memory data) =
31+
target.delegatecall(abi.encodeWithSignature("compute(uint256,uint256)", a, b));
3332
require(success, "Delegate compute failed");
3433
return abi.decode(data, (uint256));
3534
}
36-
}
35+
}

crates/forge/tests/fixtures/backtraces/ForkBacktrace.t.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ contract ForkBacktraceTest is DSTest {
3232

3333
function testDirectOnChainRevert() public {
3434
// Try to call transfer directly on USDC without having balance
35-
(bool success,) = USDC.call(
36-
abi.encodeWithSignature("transfer(address,uint256)", address(0xdead), 1000000)
37-
);
35+
(bool success,) = USDC.call(abi.encodeWithSignature("transfer(address,uint256)", address(0xdead), 1000000));
3836
require(success, "USDC transfer failed");
3937
}
4038
}

crates/forge/tests/fixtures/backtraces/ForkedERC20Wrapper.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ contract ForkedERC20Wrapper {
3030
function internalCall() internal {
3131
transferWithoutBalance(address(0xdead), 1000000);
3232
}
33-
}
33+
}

crates/forge/tests/fixtures/backtraces/LibraryBacktrace.t.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,65 +10,65 @@ contract LibraryBacktraceTest is DSTest {
1010
Vm constant vm = Vm(HEVM_ADDRESS);
1111
LibraryConsumer consumer;
1212
address constant EXTERNAL_LIB_ADDRESS = 0x1234567890123456789012345678901234567890;
13-
13+
1414
function setUp() public {
1515
// Deploy the external library at the configured address
1616
bytes memory libraryBytecode = type(ExternalMathLib).runtimeCode;
1717
vm.etch(EXTERNAL_LIB_ADDRESS, libraryBytecode);
18-
18+
1919
// Deploy consumer contract
2020
consumer = new LibraryConsumer();
2121
}
22-
22+
2323
// Internal library tests (should show inlined source locations)
24-
24+
2525
/// @notice Test division by zero in internal library
2626
function testInternalDivisionByZero() public {
2727
consumer.internalDivide(100, 0);
2828
}
29-
29+
3030
/// @notice Test underflow in internal library
3131
function testInternalUnderflow() public {
3232
consumer.internalSubtract(10, 20);
3333
}
34-
34+
3535
/// @notice Test overflow in internal library
3636
function testInternalOverflow() public {
3737
consumer.internalMultiply(type(uint256).max, 2);
3838
}
39-
39+
4040
/// @notice Test require in internal library
4141
function testInternalRequire() public {
4242
consumer.internalCheckPositive(0);
4343
}
44-
44+
4545
// External library tests (should show delegatecall to library address)
46-
46+
4747
/// @notice Test division by zero in external library
4848
function testExternalDivisionByZero() public {
4949
consumer.externalDivide(100, 0);
5050
}
51-
51+
5252
/// @notice Test underflow in external library
5353
function testExternalUnderflow() public {
5454
consumer.externalSubtract(10, 20);
5555
}
56-
56+
5757
/// @notice Test overflow in external library
5858
function testExternalOverflow() public {
5959
consumer.externalMultiply(type(uint256).max, 2);
6060
}
61-
61+
6262
/// @notice Test require in external library
6363
function testExternalRequire() public {
6464
consumer.externalCheckPositive(0);
6565
}
66-
66+
6767
// Mixed library usage test
68-
68+
6969
/// @notice Test mixed library usage with failure in external library
7070
function testMixedLibraryFailure() public {
7171
// This will fail at the external library division step (50 - 50 = 0, then divide by 0)
7272
consumer.mixedCalculation(50, 50, 0);
7373
}
74-
}
74+
}

crates/forge/tests/fixtures/backtraces/LibraryConsumer.sol

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,63 @@ import "./libraries/ExternalMathLib.sol";
77
/// @title LibraryConsumer - A contract that uses both internal and external libraries
88
contract LibraryConsumer {
99
using InternalMathLib for uint256;
10-
10+
1111
uint256 public result;
12-
12+
1313
// Internal library functions (inlined into contract bytecode)
14-
14+
1515
/// @notice Perform division using internal library
1616
function internalDivide(uint256 a, uint256 b) public returns (uint256) {
1717
result = a.div(b);
1818
return result;
1919
}
20-
20+
2121
/// @notice Perform multiplication using internal library
2222
function internalMultiply(uint256 a, uint256 b) public returns (uint256) {
2323
result = a.mul(b);
2424
return result;
2525
}
26-
26+
2727
/// @notice Perform subtraction using internal library
2828
function internalSubtract(uint256 a, uint256 b) public returns (uint256) {
2929
result = a.sub(b);
3030
return result;
3131
}
32-
32+
3333
/// @notice Check positive value using internal library
3434
function internalCheckPositive(uint256 value) public returns (uint256) {
3535
result = InternalMathLib.requirePositive(value);
3636
return result;
3737
}
38-
38+
3939
// External library functions (delegatecall to deployed library)
40-
40+
4141
/// @notice Perform division using external library
4242
function externalDivide(uint256 a, uint256 b) public returns (uint256) {
4343
result = ExternalMathLib.div(a, b);
4444
return result;
4545
}
46-
46+
4747
/// @notice Perform multiplication using external library
4848
function externalMultiply(uint256 a, uint256 b) public returns (uint256) {
4949
result = ExternalMathLib.mul(a, b);
5050
return result;
5151
}
52-
52+
5353
/// @notice Perform subtraction using external library
5454
function externalSubtract(uint256 a, uint256 b) public returns (uint256) {
5555
result = ExternalMathLib.sub(a, b);
5656
return result;
5757
}
58-
58+
5959
/// @notice Check positive value using external library
6060
function externalCheckPositive(uint256 value) public returns (uint256) {
6161
result = ExternalMathLib.requirePositive(value);
6262
return result;
6363
}
64-
64+
6565
// Mixed usage example
66-
66+
6767
/// @notice Complex calculation using both libraries
6868
function mixedCalculation(uint256 a, uint256 b, uint256 c) public returns (uint256) {
6969
// First use internal library
@@ -74,4 +74,4 @@ contract LibraryConsumer {
7474
result = step2.mul(10);
7575
return result;
7676
}
77-
}
77+
}

crates/forge/tests/fixtures/backtraces/MultipleLibraryBacktrace.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ import "../src/MultipleLibraryConsumer.sol";
66

77
contract MultipleLibraryBacktraceTest is DSTest {
88
MultipleLibraryConsumer consumer;
9-
9+
1010
function setUp() public {
1111
consumer = new MultipleLibraryConsumer();
1212
}
13-
13+
1414
/// @notice Test that FirstMathLib shows correctly in backtrace
1515
function testFirstLibraryError() public {
1616
consumer.useFirstLib(10, 0); // Division by zero in FirstMathLib
1717
}
18-
18+
1919
/// @notice Test that SecondMathLib shows correctly in backtrace
2020
function testSecondLibraryError() public {
2121
consumer.useSecondLib(5, 10); // Underflow in SecondMathLib
2222
}
23-
23+
2424
/// @notice Test that ThirdMathLib shows correctly in backtrace
2525
function testThirdLibraryError() public {
2626
consumer.useThirdLib(10, 0); // Modulo by zero in ThirdMathLib
2727
}
28-
28+
2929
/// @notice Test complex failure in the first library
3030
function testAllLibrariesFirstFails() public {
3131
consumer.useAllLibraries(10, 0, 5); // Division by zero in FirstMathLib
3232
}
33-
}
33+
}

crates/forge/tests/fixtures/backtraces/MultipleLibraryConsumer.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@ contract MultipleLibraryConsumer {
88
using FirstMathLib for uint256;
99
using SecondMathLib for uint256;
1010
using ThirdMathLib for uint256;
11-
11+
1212
uint256 public result;
13-
13+
1414
/// @notice Test division from FirstMathLib
1515
function useFirstLib(uint256 a, uint256 b) public returns (uint256) {
16-
result = a.divide(b); // Should show FirstMathLib in backtrace
16+
result = a.divide(b); // Should show FirstMathLib in backtrace
1717
return result;
1818
}
19-
19+
2020
/// @notice Test subtraction from SecondMathLib
2121
function useSecondLib(uint256 a, uint256 b) public returns (uint256) {
22-
result = a.subtract(b); // Should show SecondMathLib in backtrace
22+
result = a.subtract(b); // Should show SecondMathLib in backtrace
2323
return result;
2424
}
25-
25+
2626
/// @notice Test modulo from ThirdMathLib
2727
function useThirdLib(uint256 a, uint256 b) public returns (uint256) {
28-
result = a.modulo(b); // Should show ThirdMathLib in backtrace
28+
result = a.modulo(b); // Should show ThirdMathLib in backtrace
2929
return result;
3030
}
31-
31+
3232
/// @notice Complex calculation using all three libraries
3333
function useAllLibraries(uint256 a, uint256 b, uint256 c) public returns (uint256) {
34-
uint256 step1 = a.divide(b); // FirstMathLib
35-
uint256 step2 = step1.add(c); // SecondMathLib
36-
result = step2.modulo(10); // ThirdMathLib
34+
uint256 step1 = a.divide(b); // FirstMathLib
35+
uint256 step2 = step1.add(c); // SecondMathLib
36+
result = step2.modulo(10); // ThirdMathLib
3737
return result;
3838
}
39-
}
39+
}

crates/forge/tests/fixtures/backtraces/SimpleRevert.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ contract SimpleRevert {
66
function doRevert(string memory reason) public pure {
77
revert(reason);
88
}
9-
9+
1010
function doRequire(uint256 value) public pure {
1111
require(value > 0, "Value must be greater than zero");
1212
}
13-
13+
1414
function doAssert() public pure {
1515
assert(false);
1616
}
17-
17+
1818
error CustomError(uint256 code, address sender);
19-
19+
2020
function doCustomError() public view {
2121
revert CustomError(42, msg.sender);
2222
}
23-
}
23+
}

crates/forge/tests/fixtures/backtraces/StaticCall.sol

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ contract StaticTarget {
66
function viewFail() public pure {
77
revert("Static call failed");
88
}
9-
9+
1010
function compute(uint256 value) public pure returns (uint256) {
1111
require(value > 0, "Value must be positive");
1212
return value * 2;
@@ -15,21 +15,19 @@ contract StaticTarget {
1515

1616
contract StaticCaller {
1717
address public target;
18-
18+
1919
constructor(address _target) {
2020
target = _target;
2121
}
22-
22+
2323
function staticCallFail() public view {
2424
(bool success,) = target.staticcall(abi.encodeWithSignature("viewFail()"));
2525
require(success, "Static call reverted");
2626
}
27-
27+
2828
function staticCompute(uint256 value) public view returns (uint256) {
29-
(bool success, bytes memory data) = target.staticcall(
30-
abi.encodeWithSignature("compute(uint256)", value)
31-
);
29+
(bool success, bytes memory data) = target.staticcall(abi.encodeWithSignature("compute(uint256)", value));
3230
require(success, "Static compute failed");
3331
return abi.decode(data, (uint256));
3432
}
35-
}
33+
}

0 commit comments

Comments
 (0)