-
Notifications
You must be signed in to change notification settings - Fork 1
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
test: enhancing tests #64
Changes from 1 commit
6e6e87c
2297cb8
5c3350b
0a3e4b7
cb283c8
eeb2093
ba5f96e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,14 +202,19 @@ abstract contract BalanceTrackerFixedPriceBase { | |
|
||
// Get mech balance | ||
uint256 balance = mapMechBalances[msg.sender]; | ||
// TODO minimal balance value to account for the round-off | ||
if (balance == 0 || balance < 10_000) { | ||
revert InsufficientBalance(balance, 10_000); | ||
if (balance == 0) { | ||
revert ZeroValue(); | ||
} | ||
|
||
// Calculate mech payment and marketplace fee | ||
uint256 fee = IMechMarketplace(mechMarketplace).fee(); | ||
marketplaceFee = (balance * fee) / FEE_BASE; | ||
|
||
// If requested balance is too small, charge the minimal fee | ||
if (balance < FEE_BASE) { | ||
marketplaceFee = 1; | ||
} else { | ||
marketplaceFee = (balance * fee) / FEE_BASE; | ||
} | ||
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. @DavidMinarsch will this work as a small amounts withdraw protection? 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. Suggest this instead:
This uses 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. It will always return at least one for balance >0. |
||
mechPayment = balance - marketplaceFee; | ||
|
||
// Check for zero value, although this must never happen | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,9 @@ contract MechMarketplace is IErrorsMarketplace { | |
// Domain separator type hash | ||
bytes32 public constant DOMAIN_SEPARATOR_TYPE_HASH = | ||
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); | ||
// Fee base constant | ||
uint256 public constant FEE_BASE = 10_000; | ||
DavidMinarsch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Original domain separator value | ||
bytes32 public immutable domainSeparator; | ||
// Original chain Id | ||
|
@@ -157,8 +160,8 @@ contract MechMarketplace is IErrorsMarketplace { | |
} | ||
|
||
// Check for fee value | ||
if (newFee > 10_000) { | ||
revert Overflow(newFee, 10_000); | ||
if (newFee > FEE_BASE) { | ||
revert Overflow(newFee, FEE_BASE); | ||
} | ||
|
||
// Check for sanity values | ||
|
@@ -314,6 +317,11 @@ contract MechMarketplace is IErrorsMarketplace { | |
|
||
// Traverse all the mech types and balanceTrackers | ||
for (uint256 i = 0; i < paymentTypes.length; ++i) { | ||
// Check for zero value | ||
if (paymentTypes[i] == 0) { | ||
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. Need to check zero values here |
||
revert ZeroValue(); | ||
} | ||
|
||
// Check for zero address | ||
if (balanceTrackers[i] == address(0)) { | ||
revert ZeroAddress(); | ||
|
@@ -346,15 +354,16 @@ contract MechMarketplace is IErrorsMarketplace { | |
} | ||
_locked = 2; | ||
|
||
// responseTimeout bounds | ||
if (responseTimeout < minResponseTimeout || responseTimeout > maxResponseTimeout) { | ||
revert OutOfBounds(responseTimeout, minResponseTimeout, maxResponseTimeout); | ||
} | ||
// responseTimeout limits | ||
// Response timeout limits | ||
if (responseTimeout + block.timestamp > type(uint32).max) { | ||
revert Overflow(responseTimeout + block.timestamp, type(uint32).max); | ||
} | ||
|
||
// Response timeout bounds | ||
if (responseTimeout < minResponseTimeout || responseTimeout > maxResponseTimeout) { | ||
revert OutOfBounds(responseTimeout, minResponseTimeout, maxResponseTimeout); | ||
} | ||
|
||
Comment on lines
+362
to
+366
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. No change, just swapped places |
||
// Check for non-zero data | ||
if (data.length == 0) { | ||
revert ZeroValue(); | ||
|
@@ -438,7 +447,7 @@ contract MechMarketplace is IErrorsMarketplace { | |
revert ZeroAddress(); | ||
} | ||
|
||
// Check that the request is not already delivered | ||
// Check if request has been delivered | ||
if (mechDelivery.deliveryMech != address(0)) { | ||
revert AlreadyDelivered(requestId); | ||
} | ||
Comment on lines
+451
to
454
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. Currently this never happens, but let's leave it here for possible mechs change. |
||
|
@@ -517,38 +526,19 @@ contract MechMarketplace is IErrorsMarketplace { | |
)); | ||
} | ||
|
||
/// @dev Checks for service validity. | ||
/// @param serviceId Service Id. | ||
/// @return multisig Service multisig address. | ||
function checkServiceAndGetMultisig( | ||
uint256 serviceId | ||
) public view returns (address multisig) { | ||
// Check mech service Id | ||
IServiceRegistry.ServiceState state; | ||
(, multisig, , , , , state) = IServiceRegistry(serviceRegistry).mapServices(serviceId); | ||
if (state != IServiceRegistry.ServiceState.Deployed) { | ||
revert WrongServiceState(uint256(state), serviceId); | ||
} | ||
} | ||
|
||
/// @dev Checks for mech validity. | ||
/// @param mech Mech contract address. | ||
/// @return multisig Mech service multisig address. | ||
function checkMech(address mech) public view returns (address multisig){ | ||
function checkMech(address mech) public view returns (address multisig) { | ||
uint256 mechServiceId = IMech(mech).tokenId(); | ||
|
||
// Check mech validity as it must be created and recorded via this marketplace | ||
if (mapServiceIdMech[mechServiceId] != mech) { | ||
revert UnauthorizedAccount(mech); | ||
} | ||
|
||
// Check mech service Id | ||
multisig = checkServiceAndGetMultisig(mechServiceId); | ||
|
||
// Check that service multisig is the priority mech service multisig | ||
if (!IMech(mech).isOperator(multisig)) { | ||
revert UnauthorizedAccount(mech); | ||
} | ||
// Check mech service Id and get its multisig | ||
multisig = IMech(mech).getOperator(); | ||
Comment on lines
+533
to
+542
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. This is now more than enough, the rest was code duplication. |
||
} | ||
|
||
/// @dev Checks for requester validity. | ||
|
@@ -561,7 +551,13 @@ contract MechMarketplace is IErrorsMarketplace { | |
) public view { | ||
// Check for requester service | ||
if (requesterServiceId > 0) { | ||
address multisig = checkServiceAndGetMultisig(requesterServiceId); | ||
(, address multisig, , , , , IServiceRegistry.ServiceState state) = | ||
IServiceRegistry(serviceRegistry).mapServices(requesterServiceId); | ||
|
||
// Check for correct service state | ||
if (state != IServiceRegistry.ServiceState.Deployed) { | ||
revert WrongServiceState(uint256(state), requesterServiceId); | ||
} | ||
|
||
// Check staked service multisig | ||
if (multisig != requester) { | ||
|
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.
what if balance < marketplaceFee? need to fail..
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.
This can't happen as
balance
is not zero at this point of time. But that's irrelevant already.