Skip to content

Commit 9ae3994

Browse files
committed
Refactor test utilities and handlers for improved readability and consistency
- Updated formatting in loadFixture.test.js for better code structure and readability. - Enhanced getEventFromLogs function in utils.js for clarity. - Reformatted Invariant.t.sol to improve code legibility. - Refactored HandlerCollection.sol to enhance readability and maintainability. - Improved HandlerGlobal.sol by restructuring constant declarations for clarity. - Refined HandlerRenting.sol to enhance code readability. - Enhanced HandlerSale.sol for better code structure. - Improved HandlerSubscription.sol for clarity and consistency. - Updated storage-to-diagrams.js to include eslint-disable comment for unused vars. - Removed .eslintignore file and integrated ignore patterns into eslint.config.mjs for better configuration management.
1 parent 2c9e739 commit 9ae3994

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2917
-2174
lines changed

packages/sharing-smart-contract/.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
WALLET_PRIVATE_KEY=...
33

44
# environment to use for configuration (prod/staging)
5-
ENV=prod
5+
ENV=...
66

77
# IExec PoCo contract address override (deploy script only)
88
POCO_ADDRESS=...

packages/sharing-smart-contract/.eslintignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/sharing-smart-contract/.eslintrc.json

Lines changed: 0 additions & 36 deletions
This file was deleted.

packages/sharing-smart-contract/abis/DataProtectorSharing.sol/DataProtectorSharing.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
},
196196
{
197197
"inputs": [],
198-
"name": "FailedInnerCall",
198+
"name": "FailedCall",
199199
"type": "error"
200200
},
201201
{

packages/sharing-smart-contract/abis/registry/AddOnlyAppWhitelistRegistry.sol/AddOnlyAppWhitelistRegistry.json

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
"stateMutability": "nonpayable",
55
"type": "constructor"
66
},
7-
{
8-
"inputs": [],
9-
"name": "ERC1167FailedCreateClone",
10-
"type": "error"
11-
},
127
{
138
"inputs": [
149
{
@@ -112,6 +107,27 @@
112107
"name": "ERC721NonexistentToken",
113108
"type": "error"
114109
},
110+
{
111+
"inputs": [],
112+
"name": "FailedDeployment",
113+
"type": "error"
114+
},
115+
{
116+
"inputs": [
117+
{
118+
"internalType": "uint256",
119+
"name": "balance",
120+
"type": "uint256"
121+
},
122+
{
123+
"internalType": "uint256",
124+
"name": "needed",
125+
"type": "uint256"
126+
}
127+
],
128+
"name": "InsufficientBalance",
129+
"type": "error"
130+
},
115131
{
116132
"inputs": [],
117133
"name": "InvalidInitialization",

packages/sharing-smart-contract/contracts/DataProtectorSharing.sol

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ contract DataProtectorSharing is
166166
_workerpoolOrder.category
167167
);
168168

169-
dealid = POCO_DELEGATE.matchOrders(_appOrder, _datasetOrder, _workerpoolOrder, requestOrder);
169+
dealid = POCO_DELEGATE.matchOrders(
170+
_appOrder,
171+
_datasetOrder,
172+
_workerpoolOrder,
173+
requestOrder
174+
);
170175
emit ProtectedDataConsumed(dealid, _protectedData, _mode);
171176
}
172177

@@ -178,7 +183,11 @@ contract DataProtectorSharing is
178183

179184
// Overide burn function from ERC721BurnableUpgradeable.
180185
// Enable to burn a collectionTokenID.
181-
function _update(address to, uint256 _collectionTokenId, address auth) internal virtual override returns (address) {
186+
function _update(
187+
address to,
188+
uint256 _collectionTokenId,
189+
address auth
190+
) internal virtual override returns (address) {
182191
CollectionDetails storage _collectionDetails = collectionDetails[_collectionTokenId];
183192
if (to == address(0)) {
184193
if (_collectionDetails.size > 0) {
@@ -192,7 +201,10 @@ contract DataProtectorSharing is
192201
}
193202

194203
/// @inheritdoc IDataProtectorSharing
195-
function getProtectedDataRenter(address _protectedData, address _renterAddress) public view returns (uint48) {
204+
function getProtectedDataRenter(
205+
address _protectedData,
206+
address _renterAddress
207+
) public view returns (uint48) {
196208
return protectedDataDetails[_protectedData].renters[_renterAddress];
197209
}
198210

@@ -205,7 +217,12 @@ contract DataProtectorSharing is
205217
}
206218

207219
/// @inheritdoc IDataProtectorSharing
208-
function receiveApproval(address _sender, uint256, address, bytes calldata _extraData) public returns (bool) {
220+
function receiveApproval(
221+
address _sender,
222+
uint256,
223+
address,
224+
bytes calldata _extraData
225+
) public returns (bool) {
209226
if (msg.sender != address(POCO_DELEGATE)) {
210227
revert OnlyPocoCallerAuthorized(msg.sender);
211228
}
@@ -229,7 +246,10 @@ contract DataProtectorSharing is
229246
_rentProtectedData(protectedData, _sender, rentingParams);
230247
return true;
231248
} else if (selector == this.buyProtectedData.selector) {
232-
(address protectedData, address to, uint72 price) = abi.decode(_extraData[4:], (address, address, uint72));
249+
(address protectedData, address to, uint72 price) = abi.decode(
250+
_extraData[4:],
251+
(address, address, uint72)
252+
);
233253
_buyProtectedData(protectedData, _sender, to, price);
234254
return true;
235255
}
@@ -291,7 +311,11 @@ contract DataProtectorSharing is
291311

292312
delete protectedDataDetails[_protectedData];
293313
collectionDetails[_collectionTokenId].size -= 1;
294-
PROTECTED_DATA_REGISTRY.safeTransferFrom(address(this), msg.sender, uint256(uint160(_protectedData)));
314+
PROTECTED_DATA_REGISTRY.safeTransferFrom(
315+
address(this),
316+
msg.sender,
317+
uint256(uint160(_protectedData))
318+
);
295319
emit ProtectedDataTransfer(_protectedData, 0, _collectionTokenId, address(0));
296320
}
297321

@@ -327,7 +351,11 @@ contract DataProtectorSharing is
327351
_collectionDetails.lastSubscriptionExpiration = uint48(
328352
Math.max(endDate, _collectionDetails.lastSubscriptionExpiration)
329353
);
330-
POCO_DELEGATE.transferFrom(spender, ownerOf(_collectionTokenId), _collectionDetails.subscriptionParams.price);
354+
POCO_DELEGATE.transferFrom(
355+
spender,
356+
ownerOf(_collectionTokenId),
357+
_collectionDetails.subscriptionParams.price
358+
);
331359
emit NewSubscription(_collectionTokenId, spender, endDate);
332360
}
333361

@@ -354,7 +382,10 @@ contract DataProtectorSharing is
354382
}
355383

356384
/// @inheritdoc ISubscription
357-
function setSubscriptionParams(uint256 _collectionTokenId, SubscriptionParams calldata _subscriptionParams) public {
385+
function setSubscriptionParams(
386+
uint256 _collectionTokenId,
387+
SubscriptionParams calldata _subscriptionParams
388+
) public {
358389
_checkCollectionOperator(_collectionTokenId);
359390

360391
collectionDetails[_collectionTokenId].subscriptionParams = _subscriptionParams;
@@ -405,7 +436,10 @@ contract DataProtectorSharing is
405436
}
406437

407438
/// @inheritdoc IRental
408-
function setProtectedDataToRenting(address _protectedData, RentingParams calldata _rentingParams) public {
439+
function setProtectedDataToRenting(
440+
address _protectedData,
441+
RentingParams calldata _rentingParams
442+
) public {
409443
ProtectedDataDetails storage _protectedDataDetails = protectedDataDetails[_protectedData];
410444
uint256 _collectionTokenId = _protectedDataDetails.collection;
411445
_checkCollectionOperator(_collectionTokenId);
@@ -436,14 +470,23 @@ contract DataProtectorSharing is
436470
return _buyProtectedData(_protectedData, msg.sender, _to, _price);
437471
}
438472

439-
function _buyProtectedData(address _protectedData, address spender, address _to, uint72 _price) private {
473+
function _buyProtectedData(
474+
address _protectedData,
475+
address spender,
476+
address _to,
477+
uint72 _price
478+
) private {
440479
ProtectedDataDetails storage _protectedDataDetails = protectedDataDetails[_protectedData];
441480
_checkProtectedDataForSale(_protectedData);
442481
if (_protectedDataDetails.sellingParams.price != _price) {
443482
revert InvalidPriceForPurchase(_protectedData, _price);
444483
}
445484

446-
PROTECTED_DATA_REGISTRY.safeTransferFrom(address(this), _to, uint256(uint160(_protectedData)));
485+
PROTECTED_DATA_REGISTRY.safeTransferFrom(
486+
address(this),
487+
_to,
488+
uint256(uint160(_protectedData))
489+
);
447490
POCO_DELEGATE.transferFrom(
448491
spender,
449492
ownerOf(_protectedDataDetails.collection),

packages/sharing-smart-contract/contracts/ManageOrders.sol

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pragma solidity ^0.8.24;
2020
import {IExecPocoDelegate, IexecLibOrders_v5} from "./interfaces/IExecPocoDelegate.sol";
2121

2222
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
23+
// eslint-disable-next-line quotes
2324
abstract contract ManageOrders {
2425
using IexecLibOrders_v5 for IexecLibOrders_v5.OrderOperationEnum;
2526
using IexecLibOrders_v5 for IexecLibOrders_v5.AppOrder;
@@ -32,7 +33,8 @@ abstract contract ManageOrders {
3233

3334
// ---------------------ManageOrders state----------------------------------
3435
IExecPocoDelegate internal immutable POCO_DELEGATE;
35-
bytes32 internal constant TAG = 0x0000000000000000000000000000000000000000000000000000000000000003; // [tee,scone]
36+
bytes32 internal constant TAG =
37+
0x0000000000000000000000000000000000000000000000000000000000000003; // [tee,scone]
3638
uint256 internal constant TRUST = 0; // No replication
3739
string internal _iexecResultStorageProvider;
3840
string internal _iexecResultStorageProxy;
@@ -49,7 +51,9 @@ abstract contract ManageOrders {
4951
/***************************************************************************
5052
* Functions *
5153
**************************************************************************/
52-
function _createAppOrder(address _appAddress) internal view returns (IexecLibOrders_v5.AppOrder memory) {
54+
function _createAppOrder(
55+
address _appAddress
56+
) internal view returns (IexecLibOrders_v5.AppOrder memory) {
5357
//create AppOrderOperation
5458
return
5559
IexecLibOrders_v5.AppOrder({
@@ -120,28 +124,29 @@ abstract contract ManageOrders {
120124
uint256 _category
121125
) internal returns (IexecLibOrders_v5.RequestOrder memory) {
122126
//create RequestOrderOperation
123-
IexecLibOrders_v5.RequestOrderOperation memory requestOrderOperation = IexecLibOrders_v5.RequestOrderOperation({
124-
order: IexecLibOrders_v5.RequestOrder({
125-
app: _appAddress, //address
126-
appmaxprice: 0, //uint256
127-
dataset: _protectedData, //address
128-
datasetmaxprice: 0, //uint256
129-
workerpool: _workerpoolAddress, //address
130-
workerpoolmaxprice: 0, //uint256
131-
requester: address(this), //address
132-
volume: 1, //uint256
133-
tag: TAG, //bytes32
134-
category: _category, //uint256
135-
trust: TRUST, //uint256
136-
beneficiary: msg.sender, //address
137-
callback: address(0), //address
138-
params: generateParams(), //string
139-
salt: getSalt(), //bytes32
127+
IexecLibOrders_v5.RequestOrderOperation memory requestOrderOperation = IexecLibOrders_v5
128+
.RequestOrderOperation({
129+
order: IexecLibOrders_v5.RequestOrder({
130+
app: _appAddress, //address
131+
appmaxprice: 0, //uint256
132+
dataset: _protectedData, //address
133+
datasetmaxprice: 0, //uint256
134+
workerpool: _workerpoolAddress, //address
135+
workerpoolmaxprice: 0, //uint256
136+
requester: address(this), //address
137+
volume: 1, //uint256
138+
tag: TAG, //bytes32
139+
category: _category, //uint256
140+
trust: TRUST, //uint256
141+
beneficiary: msg.sender, //address
142+
callback: address(0), //address
143+
params: generateParams(), //string
144+
salt: getSalt(), //bytes32
145+
sign: new bytes(0)
146+
}),
147+
operation: IexecLibOrders_v5.OrderOperationEnum.SIGN, //OrderOperationEnum
140148
sign: new bytes(0)
141-
}),
142-
operation: IexecLibOrders_v5.OrderOperationEnum.SIGN, //OrderOperationEnum
143-
sign: new bytes(0)
144-
});
149+
});
145150

146151
// presign
147152
POCO_DELEGATE.manageRequestOrder(requestOrderOperation);
@@ -156,12 +161,13 @@ abstract contract ManageOrders {
156161
function generateParams() private view returns (string memory) {
157162
return
158163
string.concat(
159-
'{"iexec_result_encryption":true',
160-
',"iexec_result_storage_provider":"',
164+
// eslint-disable-next-line quotes
165+
'{"iexec_result_encryption":true', // solhint-disable-line quotes
166+
',"iexec_result_storage_provider":"', // solhint-disable-line quotes
161167
_iexecResultStorageProvider,
162-
'","iexec_result_storage_proxy":"',
168+
'","iexec_result_storage_proxy":"', // solhint-disable-line quotes
163169
_iexecResultStorageProxy,
164-
'"}'
170+
'"}' // solhint-disable-line quotes
165171
);
166172
}
167173
}

packages/sharing-smart-contract/contracts/interfaces/IDataProtectorSharing.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ interface IDataProtectorSharing is ICollection, ISubscription, IRental, ISale {
138138
* @param _renterAddress The address of the renter.
139139
* @return The rental expiration timestamp as a uint48.
140140
*/
141-
function getProtectedDataRenter(address _protectedData, address _renterAddress) external view returns (uint48);
141+
function getProtectedDataRenter(
142+
address _protectedData,
143+
address _renterAddress
144+
) external view returns (uint48);
142145

143146
/**
144147
* Retrieves the subscription expiration timestamp for a specific collection and subscriber.

0 commit comments

Comments
 (0)