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

test: enhancing tests #64

Merged
merged 7 commits into from
Dec 26, 2024
Merged

test: enhancing tests #64

merged 7 commits into from
Dec 26, 2024

Conversation

kupermind
Copy link
Collaborator

  • Enhancing tests.

Comment on lines 205 to 217
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;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@DavidMinarsch will this work as a small amounts withdraw protection?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest this instead:

marketplaceFee = (balance * fee + (FEE_BASE - 1)) / FEE_BASE;

This uses
\text{ceil}(a, b) = \frac{a + b - 1}{b}
formula

Copy link
Contributor

Choose a reason for hiding this comment

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

It will always return at least one for balance >0.

@@ -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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to check zero values here

Comment on lines +362 to +366
// Response timeout bounds
if (responseTimeout < minResponseTimeout || responseTimeout > maxResponseTimeout) {
revert OutOfBounds(responseTimeout, minResponseTimeout, maxResponseTimeout);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No change, just swapped places

Comment on lines +450 to 453
// Check if request has been delivered
if (mechDelivery.deliveryMech != address(0)) {
revert AlreadyDelivered(requestId);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Comment on lines +532 to +541
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();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is now more than enough, the rest was code duplication.

Comment on lines -17 to -21
enum RequestStatus {
DoesNotExist,
Requested,
Delivered
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Leftovers from previous versions without MM

Comment on lines -25 to -31
// Domain separator type hash
bytes32 public constant DOMAIN_SEPARATOR_TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// Original domain separator value
bytes32 public immutable domainSeparator;
// Original chain Id
uint256 public immutable chainId;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Leftovers from previous versions without MM

Comment on lines +302 to 308
/// @dev Gets mech operator (service multisig).
/// @return Service multisig address.
function getOperator() public view returns (address) {
// Get service registry and service Id
(address serviceRegistry, uint256 serviceId) = abi.decode(readImmutable(), (address, uint256));

(, address multisig, , , , , IServiceRegistry.ServiceState state) =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is cleaner now, also there must be a possibility to directly get the multisig without doing all the service registry mess.

/// @param data Self-descriptive opaque data-blob.
/// @param nonce Nonce.
/// @return requestId Corresponding request Id.
function getRequestId(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Leftovers from previous versions without MM

/// @notice If marketplace is not zero, use the same function in the mech marketplace contract.
/// @param requestId Request Id.
/// @return status Request status.
function getRequestStatus(uint256 requestId) external view returns (RequestStatus status) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Leftovers from previous versions without MM

contracts/MechMarketplace.sol Outdated Show resolved Hide resolved
Comment on lines 213 to 214
if (balance < FEE_BASE) {
marketplaceFee = 1;
Copy link
Contributor

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..

Copy link
Collaborator Author

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.

Comment on lines 205 to 217
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest this instead:

marketplaceFee = (balance * fee + (FEE_BASE - 1)) / FEE_BASE;

This uses
\text{ceil}(a, b) = \frac{a + b - 1}{b}
formula

Comment on lines 205 to 217
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It will always return at least one for balance >0.

@DavidMinarsch DavidMinarsch merged commit a41de39 into fix Dec 26, 2024
2 checks passed
@DavidMinarsch DavidMinarsch deleted the tests branch December 26, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants