Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): Moved priority queue tests from hardhat to foundry #135

Merged
merged 6 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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());
vladbochok marked this conversation as resolved.
Show resolved Hide resolved
}

function test_failGetFront() public {
vm.expectRevert(bytes.concat("D"));
mm-zk marked this conversation as resolved.
Show resolved Hide resolved
priorityQueue.front();
}

function test_failPopFront() public {
vm.expectRevert(bytes.concat("s"));
mm-zk marked this conversation as resolved.
Show resolved Hide resolved
priorityQueue.popFront();
}
}
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();
}
}
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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import {Test} from "forge-std/Test.sol";
import {PriorityQueueTest} from "../../../../../cache/solpp-generated-contracts/dev-contracts/test/PriorityQueueTest.sol";
import {PriorityOperation} from "../../../../../cache/solpp-generated-contracts/dev-contracts/test/PriorityQueueTest.sol";
mm-zk marked this conversation as resolved.
Show resolved Hide resolved

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 l1-contracts/test/unit_tests/priority_queue_test.spec.ts

This file was deleted.

Loading