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

Vigneshka/minters 2 1 #290

Merged
merged 12 commits into from
Jul 3, 2023
Prev Previous commit
Add test to ensure no overflow
  • Loading branch information
Vectorized committed Jul 3, 2023
commit 71d1f1c1a29b55e7212acf3cda51483ee8c6af18
45 changes: 45 additions & 0 deletions tests/modules/BaseMinterV2_1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,51 @@ contract MintControllerBaseV2Tests is TestConfig {
_test_withdrawPlatformFeesAccrued(expectedPlatformFees);
}

function testTotalPriceAndFeesNoOverflow(
uint96 price,
uint32 quantity,
uint16 platformFlatFee,
uint16 platformFeeBPS,
uint96 platformPerTxFlatFee,
uint16 BPS_DENOMINATOR,
uint16 affiliateFeeBPS
) public {
if (BPS_DENOMINATOR == 0) BPS_DENOMINATOR = 1;

uint256 subTotal = uint256(quantity) * uint256(price);

uint256 platformFlatFeeTotal = uint256(quantity) * uint256(platformFlatFee) + uint256(platformPerTxFlatFee);

uint256 total = subTotal + platformFlatFeeTotal;

uint256 platformFee = (subTotal * uint256(platformFeeBPS)) / uint256(BPS_DENOMINATOR) + platformFlatFeeTotal;

uint256 affiliateFee = (subTotal * uint256(affiliateFeeBPS)) / uint256(BPS_DENOMINATOR);

assertTrue(subTotal + platformFlatFeeTotal + total + platformFee + affiliateFee < type(uint256).max);
}

function testTotalPriceAndFeesNoOverflow() public {
testTotalPriceAndFeesNoOverflow(
type(uint96).max,
type(uint32).max,
type(uint16).max,
type(uint16).max,
type(uint96).max,
type(uint16).max,
type(uint16).max
);
testTotalPriceAndFeesNoOverflow(
type(uint96).max,
type(uint32).max,
type(uint16).max,
type(uint16).max,
type(uint96).max,
0,
type(uint16).max
);
}

struct _TestTemps {
uint256 subTotal;
uint256 requiredEtherValue;
Expand Down
Loading