Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

test: add tests for required finders fee bps and ensuring a valid update on newly set offers #132

Merged

Conversation

almndbtr
Copy link
Contributor

Description

Towards #126

This adds missing tests for the Offers v1.0 contract.

Motivation and Context

These changes add to the work in #126 by including tests for required finders fee bps and ensuring a valid update on newly set offers. I noticed a handful of other tests were written to check for these cases (like checking that only the seller can update an offer or handling the case where an incoming transfer message value is less than the expected amount).

How has this been tested?

I ran yarn test and they passed on my machine.

Checklist:

  • The module includes tests written for Foundry
  • The module is documented with NATSPEC
  • The documentation includes UML Diagrams for external and public functions
  • The module is a Hyperstructure

@@ -110,6 +110,11 @@ contract OffersV1Test is DSTest {
offers.createOffer(address(token), 0, address(0), 1 ether, 1000);
}

function testFail_CannotCreateOfferWithInvalidFindersFeeBps() public {
vm.prank(address(maker));
offers.createOffer(address(token), 0, address(0), 1 ether, 10001);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10001 bps (basis points) is just one higher than what the require() looks for:

require(_findersFeeBps <= 10000, "createOffer finders fee bps must be less than or equal to 10000");

@@ -200,6 +205,20 @@ contract OffersV1Test is DSTest {
vm.stopPrank();
}

function testRevert_CannotUpdateOfferWithPreviousAmount() public {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to renaming this (and the other) function name to match whatever naming convention the team prefers. ✌️


vm.expectRevert("setOfferAmount invalid _amount");

offers.setOfferAmount{value: 1 ether}(address(token), 0, 1, address(0), 1 ether);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract requires the newly set offer amount to be different from than previous:

// Ensure valid update
require(_amount > 0 && _amount != prevAmount, "setOfferAmount invalid _amount");

Since it's handled this way, it feels like a no-op in the same way we illustrate it for an ask already existing for a token. If that's the case, should we also reflect this behavior as such in the associated UML diagram?

@kulkarohan
Copy link
Contributor

hey @almndbtr thanks for adding these tests! they look great.

@kulkarohan kulkarohan merged commit bb69dda into ourzora:offers Jan 31, 2022
@almndbtr almndbtr deleted the almndbtr/offers__add-missing-tests branch January 31, 2022 22:03
@almndbtr
Copy link
Contributor Author

Thanks again @kulkarohan ! 😌

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants