-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): Moved priority queue tests from hardhat to foundry (#135)
- Loading branch information
Showing
5 changed files
with
143 additions
and
133 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
l1-contracts/test/foundry/unit/concrete/PriorityQueue/OnEmptyQueue.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pragma solidity 0.8.20; | ||
|
||
import {PriorityQueueSharedTest} from "./_PriorityQueue_Shared.t.sol"; | ||
|
||
contract OnEmptyQueueTest is PriorityQueueSharedTest { | ||
function test_gets() public { | ||
assertEq(0, priorityQueue.getSize()); | ||
assertEq(0, priorityQueue.getFirstUnprocessedPriorityTx()); | ||
assertEq(0, priorityQueue.getTotalPriorityTxs()); | ||
assertTrue(priorityQueue.isEmpty()); | ||
} | ||
|
||
function test_failGetFront() public { | ||
vm.expectRevert(bytes("D")); | ||
priorityQueue.front(); | ||
} | ||
|
||
function test_failPopFront() public { | ||
vm.expectRevert(bytes("s")); | ||
priorityQueue.popFront(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
l1-contracts/test/foundry/unit/concrete/PriorityQueue/PopOperations.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
pragma solidity 0.8.20; | ||
|
||
import {PriorityQueueSharedTest} from "./_PriorityQueue_Shared.t.sol"; | ||
import {PriorityOperation} from "../../../../../cache/solpp-generated-contracts/dev-contracts/test/PriorityQueueTest.sol"; | ||
|
||
contract PopOperationsTest is PriorityQueueSharedTest { | ||
uint public constant NUMBER_OPERATIONS = 10; | ||
|
||
function setUp() public { | ||
push_mock_entries(NUMBER_OPERATIONS); | ||
} | ||
|
||
function test_after_pop() public { | ||
assertEq(NUMBER_OPERATIONS, priorityQueue.getSize()); | ||
|
||
PriorityOperation memory front = priorityQueue.popFront(); | ||
assertEq(keccak256(abi.encode(0)), front.canonicalTxHash); | ||
assertEq(uint64(0), front.expirationTimestamp); | ||
assertEq(uint192(0), front.layer2Tip); | ||
|
||
assertEq(NUMBER_OPERATIONS - 1, priorityQueue.getSize()); | ||
assertEq(1, priorityQueue.getFirstUnprocessedPriorityTx()); | ||
assertEq(NUMBER_OPERATIONS, priorityQueue.getTotalPriorityTxs()); | ||
assertFalse(priorityQueue.isEmpty()); | ||
|
||
// Ok - one more pop | ||
PriorityOperation memory front2 = priorityQueue.popFront(); | ||
assertEq(keccak256(abi.encode(1)), front2.canonicalTxHash); | ||
assertEq(uint64(1), front2.expirationTimestamp); | ||
assertEq(uint192(1), front2.layer2Tip); | ||
|
||
assertEq(NUMBER_OPERATIONS - 2, priorityQueue.getSize()); | ||
assertEq(2, priorityQueue.getFirstUnprocessedPriorityTx()); | ||
assertEq(NUMBER_OPERATIONS, priorityQueue.getTotalPriorityTxs()); | ||
assertFalse(priorityQueue.isEmpty()); | ||
} | ||
|
||
function test_pop_until_limit() public { | ||
for (uint i = 0; i < NUMBER_OPERATIONS; ++i) { | ||
PriorityOperation memory front = priorityQueue.popFront(); | ||
assertEq(keccak256(abi.encode(i)), front.canonicalTxHash); | ||
} | ||
|
||
assertEq(0, priorityQueue.getSize()); | ||
assertEq(NUMBER_OPERATIONS, priorityQueue.getFirstUnprocessedPriorityTx()); | ||
assertEq(NUMBER_OPERATIONS, priorityQueue.getTotalPriorityTxs()); | ||
assertTrue(priorityQueue.isEmpty()); | ||
|
||
// And now let's push something. | ||
|
||
PriorityOperation memory dummyOp = PriorityOperation({ | ||
canonicalTxHash: keccak256(abi.encode(300)), | ||
expirationTimestamp: uint64(300), | ||
layer2Tip: uint192(300) | ||
}); | ||
priorityQueue.pushBack(dummyOp); | ||
|
||
assertEq(1, priorityQueue.getSize()); | ||
assertEq(NUMBER_OPERATIONS, priorityQueue.getFirstUnprocessedPriorityTx()); | ||
assertEq(NUMBER_OPERATIONS + 1, priorityQueue.getTotalPriorityTxs()); | ||
assertFalse(priorityQueue.isEmpty()); | ||
|
||
PriorityOperation memory front_end = priorityQueue.popFront(); | ||
assertEq(keccak256(abi.encode(300)), front_end.canonicalTxHash); | ||
assertTrue(priorityQueue.isEmpty()); | ||
|
||
// And now let's go over the limit and fail. | ||
vm.expectRevert(bytes.concat("s")); | ||
priorityQueue.popFront(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
l1-contracts/test/foundry/unit/concrete/PriorityQueue/PushOperations.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pragma solidity 0.8.20; | ||
|
||
import {PriorityQueueSharedTest} from "./_PriorityQueue_Shared.t.sol"; | ||
import {PriorityOperation} from "../../../../../cache/solpp-generated-contracts/dev-contracts/test/PriorityQueueTest.sol"; | ||
|
||
contract PushOperationsTest is PriorityQueueSharedTest { | ||
uint public constant NUMBER_OPERATIONS = 10; | ||
|
||
function setUp() public { | ||
push_mock_entries(NUMBER_OPERATIONS); | ||
} | ||
|
||
function test_front() public { | ||
assertEq(NUMBER_OPERATIONS, priorityQueue.getSize()); | ||
PriorityOperation memory front = priorityQueue.front(); | ||
assertEq(keccak256(abi.encode(0)), front.canonicalTxHash); | ||
assertEq(uint64(0), front.expirationTimestamp); | ||
assertEq(uint192(0), front.layer2Tip); | ||
// This is 'front' and not popFront, so the amount should not change. | ||
assertEq(NUMBER_OPERATIONS, priorityQueue.getSize()); | ||
assertEq(0, priorityQueue.getFirstUnprocessedPriorityTx()); | ||
assertEq(NUMBER_OPERATIONS, priorityQueue.getTotalPriorityTxs()); | ||
assertFalse(priorityQueue.isEmpty()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
l1-contracts/test/foundry/unit/concrete/PriorityQueue/_PriorityQueue_Shared.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.20; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {PriorityQueueTest, PriorityOperation} from "solpp/dev-contracts/test/PriorityQueueTest.sol"; | ||
|
||
contract PriorityQueueSharedTest is Test { | ||
PriorityQueueTest internal priorityQueue; | ||
|
||
constructor() { | ||
priorityQueue = new PriorityQueueTest(); | ||
} | ||
|
||
// Pushes 'count' entries into the priority queue. | ||
function push_mock_entries(uint count) public { | ||
for (uint i = 0; i < count; ++i) { | ||
PriorityOperation memory dummyOp = PriorityOperation({ | ||
canonicalTxHash: keccak256(abi.encode(i)), | ||
expirationTimestamp: uint64(i), | ||
layer2Tip: uint192(i) | ||
}); | ||
priorityQueue.pushBack(dummyOp); | ||
} | ||
} | ||
} |
133 changes: 0 additions & 133 deletions
133
l1-contracts/test/unit_tests/priority_queue_test.spec.ts
This file was deleted.
Oops, something went wrong.