-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate GPv2Signing set pre-signature tests to Foundry
- Loading branch information
Showing
3 changed files
with
56 additions
and
52 deletions.
There are no files selected for viewing
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
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
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,56 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
pragma solidity ^0.8; | ||
|
||
import {GPv2Signing} from "src/contracts/mixins/GPv2Signing.sol"; | ||
|
||
import {Helper} from "./Helper.sol"; | ||
import {Order} from "test/libraries/Order.sol"; | ||
|
||
contract SetPreSignature is Helper { | ||
address private immutable owner = makeAddr("GPv2Signing.SetPreSignature owner"); | ||
bytes private orderUid = | ||
Order.computeOrderUid(keccak256("GPv2Signing.SetPreSignature order hash"), owner, type(uint32).max); | ||
|
||
// Same constant as in GPv2Signing.PRE_SIGNED. | ||
uint256 private constant PRE_SIGNED = uint256(keccak256("GPv2Signing.Scheme.PreSign")); | ||
uint256 private constant NOT_SIGNED = 0; | ||
|
||
function test_should_set_the_pre_signature() public { | ||
vm.prank(owner); | ||
executor.setPreSignature(orderUid, true); | ||
assertEq(executor.preSignature(orderUid), PRE_SIGNED); | ||
} | ||
|
||
function test_should_unset_the_pre_signature() public { | ||
vm.prank(owner); | ||
executor.setPreSignature(orderUid, true); | ||
vm.prank(owner); | ||
executor.setPreSignature(orderUid, false); | ||
assertEq(executor.preSignature(orderUid), NOT_SIGNED); | ||
} | ||
|
||
function test_should_emit_a_pre_signature_event() public { | ||
vm.prank(owner); | ||
vm.expectEmit(address(executor)); | ||
emit GPv2Signing.PreSignature(owner, orderUid, true); | ||
executor.setPreSignature(orderUid, true); | ||
|
||
vm.prank(owner); | ||
vm.expectEmit(address(executor)); | ||
emit GPv2Signing.PreSignature(owner, orderUid, false); | ||
executor.setPreSignature(orderUid, false); | ||
} | ||
|
||
function test_should_emit_a_PreSignature_event_even_if_storage_does_not_change() public { | ||
emit GPv2Signing.PreSignature(owner, orderUid, true); | ||
vm.prank(owner); | ||
vm.expectEmit(address(executor)); | ||
emit GPv2Signing.PreSignature(owner, orderUid, true); | ||
executor.setPreSignature(orderUid, true); | ||
} | ||
|
||
function test_reverts_if_the_order_owner_is_not_the_transaction_sender() public { | ||
vm.expectRevert("GPv2: cannot presign order"); | ||
executor.setPreSignature(orderUid, true); | ||
} | ||
} |