Skip to content

Commit

Permalink
Add dd test
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed Nov 13, 2023
1 parent b49cb2e commit 75a216b
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion test/zkbob/ZkBobSequencer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ abstract contract AbstractZkBobPoolSequencerTest is AbstractForkTest {
vm.stopPrank();
}

function testDirectDeposits() public {
function testCommitProveDirectDeposits() public {
_setUpDD();

vm.startPrank(user1);
Expand All @@ -355,6 +355,49 @@ abstract contract AbstractZkBobPoolSequencerTest is AbstractForkTest {
sequencer.proveDirectDeposit(_randFR(), indices, outCommitment, batchProof, _randProof());
}

function testCantCommitAlreadyCommitedDirectDeposits() public {
_setUpDD();

vm.startPrank(user1);
_directDeposit(1 ether / D, user2, zkAddress);
_directDeposit(2 ether / D, user2, zkAddress);
_directDeposit(3 ether / D, user2, zkAddress);
_directDeposit(4 ether / D, user2, zkAddress);
vm.stopPrank();

uint256[] memory firstBatchIndices = new uint256[](3);
firstBatchIndices[0] = 0;
firstBatchIndices[1] = 1;
firstBatchIndices[2] = 2;
uint256 firstBatchCommitment = _randFR();
uint256[8] memory firstBatchProof = _randProof();

vm.prank(prover1);
sequencer.commitDirectDeposits(firstBatchIndices, firstBatchCommitment, firstBatchProof);

uint256[] memory secondBatchIndices = new uint256[](2);
secondBatchIndices[0] = 2;
secondBatchIndices[1] = 3;
uint256 secondBatchCommitment = _randFR();
uint256[8] memory secondBatchProof = _randProof();

vm.prank(prover2);
vm.expectRevert();
sequencer.commitDirectDeposits(secondBatchIndices, secondBatchCommitment, secondBatchProof);

sequencer.proveDirectDeposit(_randFR(), firstBatchIndices, firstBatchCommitment, firstBatchProof, _randProof());

uint256[] memory thirdBatchIndices = new uint256[](1);
thirdBatchIndices[0] = 3;
uint256 thirdBatchCommitment = _randFR();
uint256[8] memory thirdBatchProof = _randProof();

vm.prank(prover2);
sequencer.commitDirectDeposits(thirdBatchIndices, thirdBatchCommitment, thirdBatchProof);

sequencer.proveDirectDeposit(_randFR(), thirdBatchIndices, thirdBatchCommitment, thirdBatchProof, _randProof());
}

function deposit(int256 amount, uint64 proxyFee, uint64 proverFee, address prover) internal {
(bytes memory commitData, bytes memory proveData) = _encodeDeposit(amount, proxyFee, proverFee, prover);

Expand Down

0 comments on commit 75a216b

Please sign in to comment.