forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNested.t.sol
More file actions
44 lines (34 loc) · 1.03 KB
/
Nested.t.sol
File metadata and controls
44 lines (34 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.18;
import "ds-test/test.sol";
// Linking scenario: contract with a library that depends on a library
library Lib {
function plus100(uint256 a) public pure returns (uint256) {
return a + 100;
}
}
library NestedLib {
function nestedPlus100Plus1(uint256 a) public pure returns (uint256) {
return Lib.plus100(a) + 1;
}
}
contract LibraryConsumer {
function consume(uint256 a) public pure returns (uint256) {
return Lib.plus100(a);
}
function consumeNested(uint256 a) public pure returns (uint256) {
return NestedLib.nestedPlus100Plus1(a);
}
}
contract NestedLibraryLinkingTest is DSTest {
LibraryConsumer consumer;
function setUp() public {
consumer = new LibraryConsumer();
}
function testDirect() public {
assertEq(consumer.consume(1), 101, "library call failed");
}
function testNested() public {
assertEq(consumer.consumeNested(1), 102, "nested library call failed");
}
}