-
Notifications
You must be signed in to change notification settings - Fork 4
feat(Escrow): add custom buyer option #117
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
Open
unknownunknown1
wants to merge
1
commit into
dev
Choose a base branch
from
feat/custom-buyer
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[profile.default] | ||
src = 'src' | ||
out = 'out' | ||
libs = ['../node_modules', 'lib'] | ||
libs = ['../node_modules', 'lib'] | ||
via_ir = true |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -380,6 +380,49 @@ contract EscrowUniversalTest is Test { | |
assertEq(escrowToken.balanceOf(seller), 0, "Balance of seller should be 0"); | ||
} | ||
|
||
function test_createERC20TransactionCustomBuyer() public { | ||
uint256 deadline = block.timestamp + txTimeout; | ||
uint256 txId; | ||
vm.prank(buyer); | ||
vm.expectEmit(true, true, true, true); | ||
// Pay a bit less to differ between tests | ||
emit ERC20TransactionCreated(txId, txUri, other, seller, escrowToken, 0.4 ether, deadline); | ||
escrow.createERC20TransactionCustomBuyer(0.4 ether, escrowToken, deadline, txUri, payable(other), payable(seller)); | ||
|
||
( | ||
address escrowBuyer, | ||
address escrowSeller, | ||
uint256 amount, | ||
uint256 settlementBuyer, | ||
uint256 settlementSeller, | ||
uint256 escrowdeadline, | ||
uint256 disputeId, | ||
uint256 buyerFee, | ||
uint256 sellerFee, | ||
uint256 lastFeePaymentTime, | ||
Status status, | ||
IERC20 token | ||
) = escrow.transactions(txId); | ||
|
||
assertEq(escrowBuyer, other, "Wrong custom buyer address"); | ||
assertEq(escrowSeller, seller, "Wrong seller address"); | ||
assertEq(amount, 0.4 ether, "Wrong escrow amount"); | ||
assertEq(settlementBuyer, 0, "settlementBuyer should be 0"); | ||
assertEq(settlementSeller, 0, "settlementSeller should be 0"); | ||
assertEq(escrowdeadline, block.timestamp + 1000, "Wrong deadline"); | ||
assertEq(disputeId, 0, "disputeId should be 0"); | ||
assertEq(sellerFee, 0, "sellerFee should be 0"); | ||
assertEq(lastFeePaymentTime, 0, "lastFeePaymentTime should be 0"); | ||
assertEq(uint256(status), uint256(Status.NoDispute), "Wrong status"); | ||
assertEq(address(token), address(escrowToken), "Wrong token address"); | ||
assertEq(escrow.getTransactionCount(), 1, "Wrong transaction count"); | ||
|
||
assertEq(escrowToken.balanceOf(address(escrow)), 0.4 ether, "Wrong token balance of the escrow"); | ||
assertEq(escrowToken.balanceOf(buyer), 0.6 ether, "Wrong token balance of buyer"); // tx creator | ||
assertEq(escrowToken.balanceOf(seller), 0, "Balance of seller should be 0"); | ||
assertEq(escrowToken.balanceOf(other), 0, "Balance of custom buyer should be 0"); // custom buyer did not have balance of his own | ||
} | ||
Comment on lines
+383
to
+424
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance test coverage for edge cases and security scenarios. The test covers the basic happy path but lacks coverage for important edge cases: Add these additional test cases to ensure comprehensive coverage: function test_createERC20TransactionCustomBuyer_zeroAddresses() public {
uint256 deadline = block.timestamp + txTimeout;
// Test zero buyer address
vm.expectRevert(IEscrow.ZeroBuyerAddress.selector);
vm.prank(buyer);
escrow.createERC20TransactionCustomBuyer(
0.4 ether,
escrowToken,
deadline,
txUri,
payable(address(0)),
payable(seller)
);
// Test zero seller address
vm.expectRevert(IEscrow.ZeroSellerAddress.selector);
vm.prank(buyer);
escrow.createERC20TransactionCustomBuyer(
0.4 ether,
escrowToken,
deadline,
txUri,
payable(other),
payable(address(0))
);
}
function test_createERC20TransactionCustomBuyer_sameBuyerSeller() public {
uint256 deadline = block.timestamp + txTimeout;
vm.expectRevert(IEscrow.BuyerAndSellerCannotBeSame.selector);
vm.prank(buyer);
escrow.createERC20TransactionCustomBuyer(
0.4 ether,
escrowToken,
deadline,
txUri,
payable(other),
payable(other)
);
} 🤖 Prompt for AI Agents
|
||
|
||
function test_createNativeTransaction_approvalMissing() public { | ||
uint256 deadline = block.timestamp + txTimeout; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add validation for custom buyer address and consider security implications.
The new function allows specifying a custom buyer address, which introduces several considerations:
_buyer
is not the zero address_buyer
and_seller
should be allowed to be the same addressApply this diff to add necessary validations and documentation:
Also, add the corresponding error definitions at the top of the contract:
🤖 Prompt for AI Agents