Skip to content
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
3 changes: 2 additions & 1 deletion api/src/services/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
TAG_MAP,
tagToArray,
excludeTagArray,
DATASET_INFINITE_VOLUME,
} from '../utils/order-utils.js';
import { maxOpenOrdersPerWallet } from '../config.js';
import { ANY } from '../utils/keywords.js';
Expand Down Expand Up @@ -588,7 +589,7 @@ const getDatasetorders = async ({
...(dataset && requiredDatasetOrAnyClause(dataset)),
...(datasetOwner && { signer: datasetOwner }),
...(bulkOnly && {
'order.volume': Number.MAX_SAFE_INTEGER,
'order.volume': { $gte: DATASET_INFINITE_VOLUME - 1 }, // DATASET_INFINITE_VOLUME - 1 is accepted for compatibility with existing orders
'order.datasetprice': 0,
}),
...apprestrictOrAnyClause(app, isAppStrict),
Expand Down
8 changes: 7 additions & 1 deletion api/src/utils/order-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,21 @@ const excludeTagArray = (tagArray) =>
})
.filter((e) => e !== null);

const DATASET_INFINITE_VOLUME = Number.MAX_SAFE_INTEGER;

const isDatasetBulkOrder = (order = {}) => {
return order?.volume >= Number.MAX_SAFE_INTEGER && order?.datasetprice === 0;
return (
order?.volume >= DATASET_INFINITE_VOLUME - 1 && // DATASET_INFINITE_VOLUME - 1 is accepted for compatibility with existing orders
order?.datasetprice === 0
);
};

export {
OBJ_MAP,
STATUS_MAP,
TAG_MAP,
UNPUBLISH_TARGET_MAP,
DATASET_INFINITE_VOLUME,
tagToArray,
excludeTagArray,
isDatasetBulkOrder,
Expand Down
32 changes: 26 additions & 6 deletions api/test/datasetorders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import supertest from 'supertest';
import { Wallet } from 'ethers';
import { IExec, utils } from 'iexec';
import { chains } from '../src/config.js';
import { STATUS_MAP } from '../src/utils/order-utils.js';
import {
DATASET_INFINITE_VOLUME,
STATUS_MAP,
} from '../src/utils/order-utils.js';
import {
WALLETS,
sleep,
Expand Down Expand Up @@ -950,15 +953,15 @@ describe('Offchain marketplace', () => {
noRestrictOrders.push(...datasetPrice0);
allOrders.push(...datasetPrice0);

const bulk = await Promise.all(
Array(2)
const bulk = await Promise.all([
...Array(2)
.fill(null)
.map(async () => {
const order = await iexecUser.order
.createDatasetorder({
dataset: datasetAddress,
datasetprice: 0, // bulk order must be free
volume: Number.MAX_SAFE_INTEGER, // bulk order must have max volume
volume: DATASET_INFINITE_VOLUME, // bulk order must have max volume
})
.then(iexecUser.order.signDatasetorder);
const orderHash = await iexecUser.order.hashDatasetorder(order);
Expand All @@ -968,7 +971,24 @@ describe('Offchain marketplace', () => {
signer: ownerAddress,
};
}),
);
...Array(2)
.fill(null)
.map(async () => {
const order = await iexecUser.order
.createDatasetorder({
dataset: datasetAddress,
datasetprice: 0, // bulk order must be free
volume: DATASET_INFINITE_VOLUME - 1, // DATASET_INFINITE_VOLUME - 1 is accepted for compatibility with existing orders
})
.then(iexecUser.order.signDatasetorder);
const orderHash = await iexecUser.order.hashDatasetorder(order);
return {
order,
orderHash,
signer: ownerAddress,
};
}),
]);
bulkOrders.push(...bulk);
minVolumeOrders.push(...bulk);
noRestrictOrders.push(...bulk);
Expand Down Expand Up @@ -1864,7 +1884,7 @@ describe('Offchain marketplace', () => {
expect(Array.isArray(notOnlyBulkRes.data.orders)).toBe(true);
notOnlyBulkRes.data.orders.forEach((e) => {
if (
e.order.volume >= Number.MAX_SAFE_INTEGER &&
e.order.volume >= DATASET_INFINITE_VOLUME - 1 && // DATASET_INFINITE_VOLUME - 1 is accepted for compatibility with existing orders
e.order.datasetprice === 0
) {
expect(e.bulk).toBe(true);
Expand Down
Loading