|
1 | 1 | // SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH <[email protected]> |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
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'; |
6 | 13 | import { OrdersMatched } from '../../../generated/Core/IexecInterfaceToken'; |
7 | 14 | import { handleOrdersMatched } from '../../../src/Modules'; |
8 | 15 | import { toRLC } from '../../../src/utils'; |
@@ -40,6 +47,10 @@ const schedulerRewardRatio = BigInt.fromI32(10); |
40 | 47 | const sponsor = mockAddress('sponsor'); |
41 | 48 |
|
42 | 49 | describe('IexecPoco', () => { |
| 50 | + beforeEach(() => { |
| 51 | + clearStore(); |
| 52 | + }); |
| 53 | + |
43 | 54 | test('Should handle OrdersMatched', () => { |
44 | 55 | mockViewDeal(pocoAddress, dealId).returns([buildDefaultDeal()]); |
45 | 56 | // Create the mock event |
@@ -105,6 +116,65 @@ describe('IexecPoco', () => { |
105 | 116 | const transactionId = mockEvent.transaction.hash.toHex(); |
106 | 117 | assert.fieldEquals('Transaction', transactionId, 'id', transactionId); |
107 | 118 | }); |
| 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 | + }); |
108 | 178 | }); |
109 | 179 |
|
110 | 180 | function buildDefaultDeal(): ethereum.Value { |
|
0 commit comments