Skip to content

Commit f600e6c

Browse files
committed
Add test for handling OrdersMatched with bulk_cid when no dataset is provided
1 parent 411e6bc commit f600e6c

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

tests/unit/Modules/IexecPoco.test.ts

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
// SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH <[email protected]>
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { BigInt, ethereum } from '@graphprotocol/graph-ts';
5-
import { assert, describe, newTypedMockEventWithParams, test } from 'matchstick-as/assembly/index';
4+
import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts';
5+
import {
6+
assert,
7+
beforeEach,
8+
clearStore,
9+
describe,
10+
newTypedMockEventWithParams,
11+
test,
12+
} from 'matchstick-as/assembly/index';
613
import { OrdersMatched } from '../../../generated/Core/IexecInterfaceToken';
714
import { handleOrdersMatched } from '../../../src/Modules';
815
import { toRLC } from '../../../src/utils';
@@ -40,6 +47,10 @@ const schedulerRewardRatio = BigInt.fromI32(10);
4047
const sponsor = mockAddress('sponsor');
4148

4249
describe('IexecPoco', () => {
50+
beforeEach(() => {
51+
clearStore();
52+
});
53+
4354
test('Should handle OrdersMatched', () => {
4455
mockViewDeal(pocoAddress, dealId).returns([buildDefaultDeal()]);
4556
// Create the mock event
@@ -105,6 +116,65 @@ describe('IexecPoco', () => {
105116
const transactionId = mockEvent.transaction.hash.toHex();
106117
assert.fieldEquals('Transaction', transactionId, 'id', transactionId);
107118
});
119+
120+
test('Should handle OrdersMatched with bulk_cid when no dataset', () => {
121+
const bulkCid = 'QmBulkCID123456789';
122+
const paramsWithBulkCid = `{"bulk_cid": "${bulkCid}"}`;
123+
124+
// Create a deal without dataset (Address.zero()) but with bulk_cid in params
125+
const dealWithBulkCid = buildDeal(
126+
appAddress,
127+
appOwner,
128+
appPrice,
129+
Address.zero(), // zero address for dataset
130+
Address.zero(), // zero address for dataset owner
131+
BigInt.zero(), // zero price for dataset
132+
workerpoolAddress,
133+
workerpoolOwner,
134+
workerpoolPrice,
135+
trust,
136+
category,
137+
tag,
138+
requester,
139+
beneficiary,
140+
callback,
141+
paramsWithBulkCid, // params containing bulk_cid
142+
startTime,
143+
botFirst,
144+
botSize,
145+
workerStake,
146+
schedulerRewardRatio,
147+
sponsor,
148+
);
149+
150+
mockViewDeal(pocoAddress, dealId).returns([dealWithBulkCid]);
151+
152+
// Create the mock event
153+
let mockEvent = newTypedMockEventWithParams<OrdersMatched>(
154+
EventParamBuilder.init()
155+
.bytes('dealid', dealId)
156+
.bytes('appHash', appHash)
157+
.bytes('datasetHash', datasetHash)
158+
.bytes('workerpoolHash', workerpoolHash)
159+
.bytes('requestHash', requestHash)
160+
.build(),
161+
);
162+
mockEvent.block.timestamp = timestamp;
163+
mockEvent.address = pocoAddress;
164+
165+
// Call the handler
166+
handleOrdersMatched(mockEvent);
167+
168+
// Assert that the deal was created with bulk reference
169+
assert.fieldEquals(
170+
'Deal',
171+
dealId.toHex(),
172+
'dataset',
173+
'0x0000000000000000000000000000000000000000',
174+
);
175+
assert.fieldEquals('Deal', dealId.toHex(), 'bulk', dealId.toHex()); // bulk ID should be the dealId
176+
assert.fieldEquals('Deal', dealId.toHex(), 'params', paramsWithBulkCid);
177+
});
108178
});
109179

110180
function buildDefaultDeal(): ethereum.Value {

0 commit comments

Comments
 (0)