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: updating tests #63

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/BalanceTrackerFixedPriceToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.28;

import {BalanceTrackerFixedPriceBase, ZeroAddress, NoDepositAllowed, TransferFailed} from "./BalanceTrackerFixedPriceBase.sol";
import {IMech} from "./interfaces/IMech.sol";

Check warning on line 5 in contracts/BalanceTrackerFixedPriceToken.sol

View workflow job for this annotation

GitHub Actions / build

imported name IMech is not used

interface IToken {
/// @dev Transfers the token amount.
Expand All @@ -24,9 +24,9 @@
function balanceOf(address account) external view returns (uint256);
}

contract BalanceTrackerFixedPriceNative is BalanceTrackerFixedPriceBase {
contract BalanceTrackerFixedPriceToken is BalanceTrackerFixedPriceBase {
// OLAS token address
address public immutable olas;

Check warning on line 29 in contracts/BalanceTrackerFixedPriceToken.sol

View workflow job for this annotation

GitHub Actions / build

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @dev BalanceTrackerFixedPrice constructor.
/// @param _mechMarketplace Mech marketplace address.
Expand Down
11 changes: 9 additions & 2 deletions contracts/MechFactoryFixedPriceNative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ contract MechFactoryFixedPriceNative {

// Agent factory version number
string public constant VERSION = "0.1.0";
// Mech marketplace address
address public immutable mechMarketplace;

// Nonce
uint256 internal _nonce;

/// @dev MechFactoryFixedPriceNative constructor.
/// @param _mechMarketplace Mech marketplace address.
constructor(address _mechMarketplace) {
mechMarketplace = _mechMarketplace;
Comment on lines +33 to +34
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 set this in constructor

}

/// @dev Registers service as a mech.
/// @param mechMarketplace Mech marketplace address.
/// @param serviceRegistry Service registry address.
/// @param serviceId Service id.
/// @param payload Mech creation payload.
/// @return mech The created mech instance address.
function createMech(
address mechMarketplace,
address serviceRegistry,
uint256 serviceId,
bytes memory payload
Expand Down
13 changes: 10 additions & 3 deletions contracts/MechFactoryFixedPriceToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,29 @@ error MarketplaceOnly(address sender, address marketplace);
error ZeroAddress();

/// @title Mech Factory Basic - Periphery smart contract for managing basic mech creation
contract MechFactoryFixedPriceNative {
contract MechFactoryFixedPriceToken {
event CreateFixedPriceMech(address indexed mech, uint256 indexed serviceId, uint256 maxDeliveryRate);

// Agent factory version number
string public constant VERSION = "0.1.0";
// Mech marketplace address
address public immutable mechMarketplace;

// Nonce
uint256 internal _nonce;

/// @dev MechFactoryFixedPriceNative constructor.
/// @param _mechMarketplace Mech marketplace address.
constructor(address _mechMarketplace) {
mechMarketplace = _mechMarketplace;
}

/// @dev Registers service as a mech.
/// @param mechMarketplace Mech marketplace address.
/// @param serviceRegistry Service registry address.
/// @param serviceId Service id.
/// @param payload Mech creation payload.
/// @return mech The created mech instance address.
function createMech(
address mechMarketplace,
address serviceRegistry,
uint256 serviceId,
bytes memory payload
Expand Down
14 changes: 5 additions & 9 deletions contracts/MechMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {IServiceRegistry} from "./interfaces/IServiceRegistry.sol";

interface IMechFactory {
/// @dev Registers service as a mech.
/// @param mechManager Mech manager address.
/// @param serviceRegistry Service registry address.
/// @param serviceId Service id.
/// @param payload Mech creation payload.
/// @return mech The created mech instance address.
function createMech(address mechManager, address serviceRegistry, uint256 serviceId, bytes memory payload)
function createMech(address serviceRegistry, uint256 serviceId, bytes memory payload)
external returns (address mech);
}

Expand Down Expand Up @@ -114,10 +113,7 @@ contract MechMarketplace is IErrorsMarketplace {
/// @dev MechMarketplace constructor.
/// @param _serviceRegistry Service registry contract address.
/// @param _karma Karma proxy contract address.
constructor(
address _serviceRegistry,
address _karma
) {
constructor(address _serviceRegistry, address _karma) {
// Check for zero address
if (_serviceRegistry == address(0) || _karma == address(0)) {
revert ZeroAddress();
Expand Down Expand Up @@ -262,7 +258,7 @@ contract MechMarketplace is IErrorsMarketplace {
revert UnauthorizedAccount(mechFactory);
}

mech = IMechFactory(mechFactory).createMech(address(this), serviceRegistry, serviceId, payload);
mech = IMechFactory(mechFactory).createMech(serviceRegistry, serviceId, payload);

// This should never be the case
if (mech == address(0)) {
Expand Down Expand Up @@ -333,7 +329,7 @@ contract MechMarketplace is IErrorsMarketplace {
/// @notice The request is going to be registered for a specified priority mech.
/// @param data Self-descriptive opaque data-blob.
/// @param priorityMechServiceId Priority mech service Id.
/// @param requesterServiceId Requester service Id (optional).
/// @param requesterServiceId Requester service Id, or zero if EOA.
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 more correct now.

/// @param responseTimeout Relative response time in sec.
/// @param paymentData Additional payment-related request data (optional).
/// @return requestId Request Id.
Expand Down Expand Up @@ -542,7 +538,7 @@ contract MechMarketplace is IErrorsMarketplace {
uint256 mechServiceId = IMech(mech).tokenId();

// Check mech validity as it must be created and recorded via this marketplace
if (mapServiceIdMech[mechServiceId] == mech) {
if (mapServiceIdMech[mechServiceId] != mech) {
revert UnauthorizedAccount(mech);
}

Expand Down
21 changes: 13 additions & 8 deletions contracts/OlasMech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ abstract contract OlasMech is Mech, IErrorsMech, ImmutableStorage {
// Map of request Id => sender address
mapping(uint256 => address) public mapRequestAddresses;

/// @dev OlasMech constructor.
/// @param _mechMarketplace Mech marketplace address.
/// @param _serviceRegistry Address of the registry contract.
/// @param _serviceId Service Id.
/// @param _maxDeliveryRate Mech max delivery rate.
/// @param _paymentType Mech payment type.
constructor(
address _mechMarketplace,
address _serviceRegistry,
Expand All @@ -64,7 +67,7 @@ abstract contract OlasMech is Mech, IErrorsMech, ImmutableStorage {
bytes32 _paymentType
) {
// Check for zero address
if (mechMarketplace == address(0)) {
if (_mechMarketplace == address(0)) {
revert ZeroAddress();
}

Expand Down Expand Up @@ -197,18 +200,14 @@ abstract contract OlasMech is Mech, IErrorsMech, ImmutableStorage {
address account = mapRequestAddresses[requestId];

// Get the mech delivery info from the mech marketplace
IMechMarketplace.MechDelivery memory mechDelivery = IMechMarketplace(mechMarketplace).getMechDeliveryInfo(requestId);
IMechMarketplace.MechDelivery memory mechDelivery =
IMechMarketplace(mechMarketplace).mapRequestIdDeliveries(requestId);

// Instantly return if the request has been delivered
if (mechDelivery.deliveryMech != address(0)) {
return requestData;
}

// Check for max delivery rate compared to requested one
if (maxDeliveryRate > mechDelivery.deliveryRate) {
revert Overflow(maxDeliveryRate, mechDelivery.deliveryRate);
}

// The account is zero if the delivery mech is different from a priority mech, or if request does not exist
if (account == address(0)) {
account = mechDelivery.requester;
Expand All @@ -222,6 +221,11 @@ abstract contract OlasMech is Mech, IErrorsMech, ImmutableStorage {
_cleanRequestInfo(account, requestId);
}

// Check for max delivery rate compared to requested one
if (maxDeliveryRate > mechDelivery.deliveryRate) {
revert Overflow(maxDeliveryRate, mechDelivery.deliveryRate);
}

// Perform a pre-delivery of the data if it needs additional parsing
requestData = _preDeliver(account, requestId, data);

Expand Down Expand Up @@ -298,7 +302,7 @@ abstract contract OlasMech is Mech, IErrorsMech, ImmutableStorage {

// Mech marketplace delivery finalization if the request was not delivered already
if (requestData.length > 0) {
IMechMarketplace(mechMarketplace).deliverMarketplace(requestId, requestData, tokenId());
IMechMarketplace(mechMarketplace).deliverMarketplace(requestId, requestData);
}

_locked = 1;
Expand Down Expand Up @@ -331,6 +335,7 @@ abstract contract OlasMech is Mech, IErrorsMech, ImmutableStorage {
if (state != IServiceRegistry.ServiceState.Deployed) {
revert WrongServiceState(uint256(state), serviceId);
}

return multisig == signer;
}

Expand Down
11 changes: 9 additions & 2 deletions contracts/integrations/nevermined/MechFactoryNvmSubscription.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ contract MechFactoryNvmSubscription {

// Agent factory version number
string public constant VERSION = "0.1.0";
// Mech marketplace address
address public immutable mechMarketplace;

// Nonce
uint256 internal _nonce;

/// @dev MechFactoryFixedPriceNative constructor.
/// @param _mechMarketplace Mech marketplace address.
constructor(address _mechMarketplace) {
mechMarketplace = _mechMarketplace;
}

/// @dev Registers service as a mech.
/// @param mechMarketplace Mech marketplace address.
/// @param serviceRegistry Service registry address.
/// @param serviceId Service id.
/// @param payload Mech creation payload.
/// @return mech The created mech instance address.
function createMech(
address mechMarketplace,
address serviceRegistry,
uint256 serviceId,
bytes memory payload
Expand Down
6 changes: 2 additions & 4 deletions contracts/interfaces/IMechMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ interface IMechMarketplace {
/// @dev Delivers a request.
/// @param requestId Request id.
/// @param requestData Self-descriptive opaque data-blob.
/// @param deliveryMechServiceId Mech operator service Id.
function deliverMarketplace(
uint256 requestId,
bytes memory requestData,
uint256 deliveryMechServiceId
bytes memory requestData
) external;

/// @dev Gets mech delivery info.
/// @param requestId Request Id.
/// @return Mech delivery info.
function getMechDeliveryInfo(uint256 requestId) external returns (MechDelivery memory);
function mapRequestIdDeliveries(uint256 requestId) external returns (MechDelivery memory);
}
Loading
Loading