Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/out
/cache
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all :; DAPP_BUILD_OPTIMIZE=1 DAPP_BUILD_OPTIMIZE_RUNS=200 dapp --use solc:0.6.12 build
clean :; dapp clean
test :; dapp --use solc:0.6.12 test -v
deploy :; make && dapp create LerpFactory
flatten :; hevm flatten --source-file src/LerpFactory.sol > out/LerpFactory.sol && hevm flatten --source-file src/Lerp.sol > out/Lerp.sol
all :; forge build --use solc:0.6.12 --optimize --optimizer-runs 200
clean :; forge clean
test :; forge test -vvv

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do test :; forge test --use solc:0.6.12 -vvv to force using the specific compiler version as with dapp.

deploy :; make && forge create LerpFactory
flatten :; forge flatten --output out/LerpFactory.flattened.sol src/LerpFactory.sol

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you remove the flattening of Lerp.sol since it's not needed?

2 changes: 1 addition & 1 deletion lib/ds-test
Submodule ds-test updated 2 files
+21 −22 demo/demo.sol
+42 −7 src/test.sol
70 changes: 64 additions & 6 deletions src/Lerp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,37 +117,95 @@ contract DssLerpTest is DSTest {
}

function test_lerp() public {
Lerp lerp = new Lerp(address(target), "value", block.timestamp, 1 * TOLL_ONE_PCT, 1 * TOLL_ONE_PCT / 10, 9 days);
uint256 startTime = block.timestamp;
Lerp lerp = new Lerp(address(target), "value", startTime, 1 * TOLL_ONE_PCT, 1 * TOLL_ONE_PCT / 10, 9 days);

assertEq(lerp.what(), "value");
assertEq(lerp.start(), 1 * TOLL_ONE_PCT);
assertEq(lerp.end(), 1 * TOLL_ONE_PCT / 10);
assertEq(lerp.duration(), 9 days);
assertTrue(!lerp.done());
assertEq(lerp.startTime(), 0);
assertEq(lerp.startTime(), block.timestamp);
assertEq(target.value(), 0);
target.rely(address(lerp));
lerp.tick();
assertTrue(!lerp.done());
assertEq(lerp.startTime(), block.timestamp);
assertEq(target.value(), 1 * TOLL_ONE_PCT);
hevm.warp(1 days);
hevm.warp(startTime + 1 days);
assertEq(target.value(), 1 * TOLL_ONE_PCT);
lerp.tick();
assertEq(target.value(), 9 * TOLL_ONE_PCT / 10); // 0.9%
hevm.warp(2 days);
hevm.warp(startTime + 2 days);
lerp.tick();
assertEq(target.value(), 8 * TOLL_ONE_PCT / 10); // 0.8%
hevm.warp(2 days + 12 hours);
hevm.warp(startTime + 2 days + 12 hours);
lerp.tick();
assertEq(target.value(), 75 * TOLL_ONE_PCT / 100); // 0.75%
hevm.warp(12 days);
hevm.warp(startTime + 12 days);
assertEq(target.wards(address(lerp)), 1);
lerp.tick();
assertEq(target.value(), 1 * TOLL_ONE_PCT / 10); // 0.1%
assertTrue(lerp.done());
assertEq(target.wards(address(lerp)), 0);
}

// Confirm lerp can be used as a durational toggle switch for 0 --> 1 values.
function test_lerp_zero_to_one() public {
uint256 start = 0;
uint256 end = 1;
uint256 duration = 30 days;
uint256 testStart = block.timestamp;

Lerp lerp = new Lerp(address(target), "value", testStart, start, end, duration);
target.rely(address(lerp));
lerp.tick();
assertEq(target.value(), 0);

hevm.warp(testStart + duration/2); // Halfway through

lerp.tick();
assertEq(target.value(), 0);

hevm.warp(testStart + duration - 1); // One block before completion

lerp.tick();
assertEq(target.value(), 0);

hevm.warp(testStart + duration); // End of period

lerp.tick();
assertEq(target.value(), 1);
}

// Confirm lerp can be used as a durational toggle switch for 1 --> 0 values.
function test_lerp_one_to_zero() public {
uint256 start = 1;
uint256 end = 0;
uint256 duration = 30 days;
uint256 testStart = block.timestamp;

Lerp lerp = new Lerp(address(target), "value", testStart, start, end, duration);
target.rely(address(lerp));
lerp.tick();
assertEq(target.value(), 1);

hevm.warp(testStart + duration/2); // Halfway through

lerp.tick();
assertEq(target.value(), 1);

hevm.warp(testStart + duration - 1); // One block before completion

lerp.tick();
assertEq(target.value(), 1);

hevm.warp(testStart + duration); // End of period

lerp.tick();
assertEq(target.value(), 0);
}

function test_lerp_max_values1() public {
uint256 start = 10 ** 59;
uint256 end = 10 ** 59 - 1;
Expand Down