From 83631f8cac3350e4cc65459c9a561b09cccd8054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 15:32:34 +0100 Subject: [PATCH 01/17] Add `sponsor` to `deal` --- CHANGELOG.md | 1 + schema.graphql | 9 +--- src/Modules/IexecPoco.ts | 16 +------ src/Modules/index.ts | 1 - subgraph.template.yaml | 3 -- test/Modules/IexecPoco.test.ts | 78 ++++++++++++++++++++++++++++------ 6 files changed, 67 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 604bad6..6e3eeb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## vNext +- Add `sponsor` to `deal`. (#30) - Update staging deployment hosts. (#29) - Display coverage in Github PR checks. (#26) - Add integration test suite. (#21) diff --git a/schema.graphql b/schema.graphql index 049951e..2632e0a 100644 --- a/schema.graphql +++ b/schema.graphql @@ -367,6 +367,7 @@ type Deal @entity { claimedTasksCount: BigInt! workerStake: BigInt! schedulerRewardRatio: BigInt! + sponsor: Account! timestamp: BigInt! # creation apporder: AppOrder # todo: not available if not broadcasted datasetorder: DatasetOrder # todo: not available if not broadcasted @@ -436,14 +437,6 @@ type OrdersMatched implements DealEvent @entity { deal: Deal! } -type DealSponsored implements DealEvent @entity { - id: ID! - transaction: Transaction! - timestamp: BigInt! - deal: Deal! - sponsor: Account! -} - interface TaskEvent { id: ID! transaction: Transaction! diff --git a/src/Modules/IexecPoco.ts b/src/Modules/IexecPoco.ts index e79c04b..e15eeb0 100644 --- a/src/Modules/IexecPoco.ts +++ b/src/Modules/IexecPoco.ts @@ -5,7 +5,6 @@ import { BigInt } from '@graphprotocol/graph-ts'; import { AccurateContribution as AccurateContributionEvent, - DealSponsored as DealSponsoredEvent, FaultyContribution as FaultyContributionEvent, IexecInterfaceToken as IexecInterfaceTokenContract, MatchOrdersCall, @@ -22,7 +21,6 @@ import { import { AccurateContribution, - DealSponsored, FaultyContribution, OrdersMatched, SchedulerNotice, @@ -156,6 +154,7 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { deal.botSize = viewedDeal.botSize; deal.workerStake = viewedDeal.workerStake; deal.schedulerRewardRatio = viewedDeal.schedulerRewardRatio; + deal.sponsor = viewedDeal.sponsor.toHex(); deal.apporder = event.params.appHash.toHex(); deal.datasetorder = event.params.datasetHash.toHex(); deal.workerpoolorder = event.params.workerpoolHash.toHex(); @@ -423,16 +422,3 @@ export function handleFaultyContribution(event: FaultyContributionEvent): void { workerAccount.score = faultyContributionEvent.score; workerAccount.save(); } - -export function handleDealSponsored(event: DealSponsoredEvent): void { - let dealSponsoredEvent = DealSponsored.load(createEventID(event)); - if (!dealSponsoredEvent) { - dealSponsoredEvent = new DealSponsored(createEventID(event)); - } - dealSponsoredEvent.transaction = logTransaction(event).id; - dealSponsoredEvent.transaction = logTransaction(event).id; - dealSponsoredEvent.timestamp = event.block.timestamp; - dealSponsoredEvent.deal = event.params.dealId.toHex(); - dealSponsoredEvent.sponsor = event.params.sponsor.toHex(); - dealSponsoredEvent.save(); -} diff --git a/src/Modules/index.ts b/src/Modules/index.ts index 2ed936f..05689e0 100644 --- a/src/Modules/index.ts +++ b/src/Modules/index.ts @@ -7,7 +7,6 @@ export { handleLock, handleReward, handleSeize, handleTransfer, handleUnlock } f export { handleAccurateContribution, - handleDealSponsored, handleFaultyContribution, handleMatchOrders, handleOrdersMatched, diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 0be4024..cae1b3d 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -69,7 +69,6 @@ dataSources: - Seize - Lock - Unlock - - DealSponsored abis: - name: IexecInterfaceToken file: node_modules/@iexec/poco/artifacts/contracts/IexecInterfaceNative.sol/IexecInterfaceNative.json @@ -108,8 +107,6 @@ dataSources: handler: handleLock - event: Unlock(address,uint256) handler: handleUnlock - - event: DealSponsored(bytes32,address) - handler: handleDealSponsored callHandlers: - function: matchOrders((address,uint256,uint256,bytes32,address,address,address,bytes32,bytes),(address,uint256,uint256,bytes32,address,address,address,bytes32,bytes),(address,uint256,uint256,bytes32,uint256,uint256,address,address,address,bytes32,bytes),(address,uint256,address,uint256,address,uint256,address,uint256,bytes32,uint256,uint256,address,address,string,bytes32,bytes)) handler: handleMatchOrders diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index 5b56486..8a85cf2 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -1,39 +1,89 @@ -// SPDX-FileCopyrightText: 2024 IEXEC BLOCKCHAIN TECH +// SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'; -import { assert, describe, newTypedMockEventWithParams, test } from 'matchstick-as/assembly/index'; -import { DealSponsored } from '../../generated/Core/IexecInterfaceToken'; -import { handleDealSponsored } from '../../src/Modules'; +import { + assert, + createMockedFunction, + describe, + newTypedMockEventWithParams, + test, +} from 'matchstick-as/assembly/index'; +import { OrdersMatched } from '../../generated/Core/IexecInterfaceToken'; +import { handleOrdersMatched } from '../../src/Modules'; describe('IexecPoco', () => { - test('Should handle DealSponsored', () => { - // Define mock parameters + test('Should handle OrdersMatched', () => { + let pocoProxyAddress = Address.fromString('0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7'); const dealId = Bytes.fromHexString( '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', ); const sponsor = Address.fromString('0xabcdef1234567890abcdef1234567890abcdef12'); const timestamp = BigInt.fromI32(123456789); + const assetAddress = Address.fromString('0x90cBa2Bbb19ecc291A12066Fd8329D65FA1f1947'); + const assetOwner = Address.fromString('0x90cBa2Bbb19ecc291A12066Fd8329D65FA1f1947'); + const assetPrice = 100; + const uint256 = 200; + const bytes32 = dealId; // change it + const address = assetAddress; // change it + const string = 'a string'; + createMockedFunction( + pocoProxyAddress, + 'viewDeal', + 'viewDeal(bytes32):(((address,address,uint256),(address,address,uint256),(address,address,uint256),uint256,uint256,bytes32,address,address,address,string,uint256,uint256,uint256,uint256,uint256,address))', + ) + .withArgs([ethereum.Value.fromBytes(dealId)]) + .returns([ + ethereum.Value.fromArray([ + ethereum.Value.fromAddress(assetAddress), + ethereum.Value.fromAddress(assetOwner), + ethereum.Value.fromI32(assetPrice), + ]), + ethereum.Value.fromArray([ + ethereum.Value.fromAddress(assetAddress), + ethereum.Value.fromAddress(assetOwner), + ethereum.Value.fromI32(assetPrice), + ]), + ethereum.Value.fromArray([ + ethereum.Value.fromAddress(assetAddress), + ethereum.Value.fromAddress(assetOwner), + ethereum.Value.fromI32(assetPrice), + ]), + ethereum.Value.fromI32(uint256), + ethereum.Value.fromI32(uint256), + ethereum.Value.fromBytes(bytes32), + ethereum.Value.fromAddress(address), + ethereum.Value.fromAddress(address), + ethereum.Value.fromAddress(address), + ethereum.Value.fromString(string), + ethereum.Value.fromI32(uint256), + ethereum.Value.fromI32(uint256), + ethereum.Value.fromI32(uint256), + ethereum.Value.fromI32(uint256), + ethereum.Value.fromI32(uint256), + ethereum.Value.fromAddress(address), + ]); // Create the mock event - let mockEvent = newTypedMockEventWithParams([ + let mockEvent = newTypedMockEventWithParams([ new ethereum.EventParam('deal', ethereum.Value.fromFixedBytes(dealId)), - new ethereum.EventParam('sponsor', ethereum.Value.fromAddress(sponsor)), ]); mockEvent.block.timestamp = timestamp; + mockEvent.address = pocoProxyAddress; // Call the handler - handleDealSponsored(mockEvent); + handleOrdersMatched(mockEvent); - // Assert that the DealSponsored entity was created and has correct fields + // Assert that the OrdersMatched entity was created and has correct fields const entityId = mockEvent.block.number .toString() .concat('-') .concat(mockEvent.logIndex.toString()); - assert.fieldEquals('DealSponsored', entityId, 'deal', dealId.toHex()); - assert.fieldEquals('DealSponsored', entityId, 'sponsor', sponsor.toHex()); - assert.fieldEquals('DealSponsored', entityId, 'timestamp', timestamp.toString()); + assert.fieldEquals('OrdersMatched', entityId, 'deal', dealId.toHex()); + assert.fieldEquals('OrdersMatched', entityId, 'timestamp', timestamp.toString()); + assert.fieldEquals('Deal', dealId.toHex(), 'sponsor', sponsor.toHex()); + // TODO: Verify others fields // Assert that a transaction was logged (if applicable) const transactionId = mockEvent.transaction.hash.toHex(); @@ -41,4 +91,4 @@ describe('IexecPoco', () => { }); }); -export { handleDealSponsored }; +export { OrdersMatched }; From e90fe59aae0ede6cde0207d08286ce7db8160942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:05:16 +0100 Subject: [PATCH 02/17] Set FixedBytes for bytes32 --- test/Modules/IexecPoco.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index 8a85cf2..8eb327c 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -32,7 +32,7 @@ describe('IexecPoco', () => { 'viewDeal', 'viewDeal(bytes32):(((address,address,uint256),(address,address,uint256),(address,address,uint256),uint256,uint256,bytes32,address,address,address,string,uint256,uint256,uint256,uint256,uint256,address))', ) - .withArgs([ethereum.Value.fromBytes(dealId)]) + .withArgs([ethereum.Value.fromFixedBytes(dealId)]) .returns([ ethereum.Value.fromArray([ ethereum.Value.fromAddress(assetAddress), @@ -51,7 +51,7 @@ describe('IexecPoco', () => { ]), ethereum.Value.fromI32(uint256), ethereum.Value.fromI32(uint256), - ethereum.Value.fromBytes(bytes32), + ethereum.Value.fromFixedBytes(bytes32), ethereum.Value.fromAddress(address), ethereum.Value.fromAddress(address), ethereum.Value.fromAddress(address), From f29227cad842815d10d645e311d916441c5bdc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:19:27 +0100 Subject: [PATCH 03/17] Use tuple --- test/Modules/IexecPoco.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index 8eb327c..c465c79 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -34,17 +34,17 @@ describe('IexecPoco', () => { ) .withArgs([ethereum.Value.fromFixedBytes(dealId)]) .returns([ - ethereum.Value.fromArray([ + ethereum.Value.fromTuple([ ethereum.Value.fromAddress(assetAddress), ethereum.Value.fromAddress(assetOwner), ethereum.Value.fromI32(assetPrice), ]), - ethereum.Value.fromArray([ + ethereum.Value.fromTuple([ ethereum.Value.fromAddress(assetAddress), ethereum.Value.fromAddress(assetOwner), ethereum.Value.fromI32(assetPrice), ]), - ethereum.Value.fromArray([ + ethereum.Value.fromTuple([ ethereum.Value.fromAddress(assetAddress), ethereum.Value.fromAddress(assetOwner), ethereum.Value.fromI32(assetPrice), From 61f2d84fc47a81f2dc1ca18bac677f8af4c57f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:21:43 +0100 Subject: [PATCH 04/17] Use changetype --- test/Modules/IexecPoco.test.ts | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index c465c79..ad1433a 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -34,21 +34,27 @@ describe('IexecPoco', () => { ) .withArgs([ethereum.Value.fromFixedBytes(dealId)]) .returns([ - ethereum.Value.fromTuple([ - ethereum.Value.fromAddress(assetAddress), - ethereum.Value.fromAddress(assetOwner), - ethereum.Value.fromI32(assetPrice), - ]), - ethereum.Value.fromTuple([ - ethereum.Value.fromAddress(assetAddress), - ethereum.Value.fromAddress(assetOwner), - ethereum.Value.fromI32(assetPrice), - ]), - ethereum.Value.fromTuple([ - ethereum.Value.fromAddress(assetAddress), - ethereum.Value.fromAddress(assetOwner), - ethereum.Value.fromI32(assetPrice), - ]), + ethereum.Value.fromTuple( + changetype([ + ethereum.Value.fromAddress(assetAddress), + ethereum.Value.fromAddress(assetOwner), + ethereum.Value.fromI32(assetPrice), + ]), + ), + ethereum.Value.fromTuple( + changetype([ + ethereum.Value.fromAddress(assetAddress), + ethereum.Value.fromAddress(assetOwner), + ethereum.Value.fromI32(assetPrice), + ]), + ), + ethereum.Value.fromTuple( + changetype([ + ethereum.Value.fromAddress(assetAddress), + ethereum.Value.fromAddress(assetOwner), + ethereum.Value.fromI32(assetPrice), + ]), + ), ethereum.Value.fromI32(uint256), ethereum.Value.fromI32(uint256), ethereum.Value.fromFixedBytes(bytes32), From 555bdbfc2d3ecac7f4c4baced53168bc4bebf0c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:34:09 +0100 Subject: [PATCH 05/17] Create mock --- test/Modules/IexecPoco.test.ts | 41 ++++++++++++++++------------------ 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index ad1433a..099124c 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -2,15 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'; -import { - assert, - createMockedFunction, - describe, - newTypedMockEventWithParams, - test, -} from 'matchstick-as/assembly/index'; +import { createMockedFunction, describe, test } from 'matchstick-as/assembly/index'; import { OrdersMatched } from '../../generated/Core/IexecInterfaceToken'; -import { handleOrdersMatched } from '../../src/Modules'; describe('IexecPoco', () => { test('Should handle OrdersMatched', () => { @@ -35,6 +28,7 @@ describe('IexecPoco', () => { .withArgs([ethereum.Value.fromFixedBytes(dealId)]) .returns([ ethereum.Value.fromTuple( + // app changetype([ ethereum.Value.fromAddress(assetAddress), ethereum.Value.fromAddress(assetOwner), @@ -42,6 +36,7 @@ describe('IexecPoco', () => { ]), ), ethereum.Value.fromTuple( + // dataset changetype([ ethereum.Value.fromAddress(assetAddress), ethereum.Value.fromAddress(assetOwner), @@ -49,27 +44,28 @@ describe('IexecPoco', () => { ]), ), ethereum.Value.fromTuple( + // workerpool changetype([ ethereum.Value.fromAddress(assetAddress), ethereum.Value.fromAddress(assetOwner), ethereum.Value.fromI32(assetPrice), ]), ), - ethereum.Value.fromI32(uint256), - ethereum.Value.fromI32(uint256), - ethereum.Value.fromFixedBytes(bytes32), - ethereum.Value.fromAddress(address), - ethereum.Value.fromAddress(address), - ethereum.Value.fromAddress(address), - ethereum.Value.fromString(string), - ethereum.Value.fromI32(uint256), - ethereum.Value.fromI32(uint256), - ethereum.Value.fromI32(uint256), - ethereum.Value.fromI32(uint256), - ethereum.Value.fromI32(uint256), - ethereum.Value.fromAddress(address), + ethereum.Value.fromI32(uint256), // trust + ethereum.Value.fromI32(uint256), // category + ethereum.Value.fromFixedBytes(bytes32), // tag + ethereum.Value.fromAddress(address), // requester + ethereum.Value.fromAddress(address), // beneficiary + ethereum.Value.fromAddress(address), // callback + ethereum.Value.fromString(string), // params + ethereum.Value.fromI32(uint256), // startTime + ethereum.Value.fromI32(uint256), // botFirst + ethereum.Value.fromI32(uint256), // botSize + ethereum.Value.fromI32(uint256), // workerStake + ethereum.Value.fromI32(uint256), // schedulerRewardRatio + ethereum.Value.fromAddress(address), // sponsor ]); - + /* // Create the mock event let mockEvent = newTypedMockEventWithParams([ new ethereum.EventParam('deal', ethereum.Value.fromFixedBytes(dealId)), @@ -94,6 +90,7 @@ describe('IexecPoco', () => { // Assert that a transaction was logged (if applicable) const transactionId = mockEvent.transaction.hash.toHex(); assert.fieldEquals('Transaction', transactionId, 'id', transactionId); + */ }); }); From d2b6f0ee94f53d2f25ea6d77a472bbbefe617f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:36:45 +0100 Subject: [PATCH 06/17] Return flat deal --- test/Modules/IexecPoco.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index 099124c..9a1f650 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -27,6 +27,7 @@ describe('IexecPoco', () => { ) .withArgs([ethereum.Value.fromFixedBytes(dealId)]) .returns([ + /* ethereum.Value.fromTuple( // app changetype([ @@ -51,6 +52,7 @@ describe('IexecPoco', () => { ethereum.Value.fromI32(assetPrice), ]), ), + */ ethereum.Value.fromI32(uint256), // trust ethereum.Value.fromI32(uint256), // category ethereum.Value.fromFixedBytes(bytes32), // tag From 62fd3b78b899397bfb3e330c32e1d2f153066105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:38:31 +0100 Subject: [PATCH 07/17] Create mock event --- test/Modules/IexecPoco.test.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index 9a1f650..cc2c916 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -2,7 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'; -import { createMockedFunction, describe, test } from 'matchstick-as/assembly/index'; +import { + createMockedFunction, + describe, + newTypedMockEventWithParams, + test, +} from 'matchstick-as/assembly/index'; import { OrdersMatched } from '../../generated/Core/IexecInterfaceToken'; describe('IexecPoco', () => { @@ -27,7 +32,6 @@ describe('IexecPoco', () => { ) .withArgs([ethereum.Value.fromFixedBytes(dealId)]) .returns([ - /* ethereum.Value.fromTuple( // app changetype([ @@ -52,7 +56,6 @@ describe('IexecPoco', () => { ethereum.Value.fromI32(assetPrice), ]), ), - */ ethereum.Value.fromI32(uint256), // trust ethereum.Value.fromI32(uint256), // category ethereum.Value.fromFixedBytes(bytes32), // tag @@ -67,7 +70,7 @@ describe('IexecPoco', () => { ethereum.Value.fromI32(uint256), // schedulerRewardRatio ethereum.Value.fromAddress(address), // sponsor ]); - /* + // Create the mock event let mockEvent = newTypedMockEventWithParams([ new ethereum.EventParam('deal', ethereum.Value.fromFixedBytes(dealId)), @@ -75,6 +78,8 @@ describe('IexecPoco', () => { mockEvent.block.timestamp = timestamp; mockEvent.address = pocoProxyAddress; + /* + // Call the handler handleOrdersMatched(mockEvent); From 07ad2507c9e1bd2c4b875779839a7bd2362a443c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:39:52 +0100 Subject: [PATCH 08/17] Handle orders matched --- test/Modules/IexecPoco.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index cc2c916..7d03168 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -9,6 +9,7 @@ import { test, } from 'matchstick-as/assembly/index'; import { OrdersMatched } from '../../generated/Core/IexecInterfaceToken'; +import { handleOrdersMatched } from '../../src/Modules'; describe('IexecPoco', () => { test('Should handle OrdersMatched', () => { @@ -78,11 +79,11 @@ describe('IexecPoco', () => { mockEvent.block.timestamp = timestamp; mockEvent.address = pocoProxyAddress; - /* - // Call the handler handleOrdersMatched(mockEvent); + /* + // Assert that the OrdersMatched entity was created and has correct fields const entityId = mockEvent.block.number .toString() From 92a3b946ca029adc177cadd6a3fed31b3bcd5411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:42:51 +0100 Subject: [PATCH 09/17] Only save deal --- src/Modules/IexecPoco.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Modules/IexecPoco.ts b/src/Modules/IexecPoco.ts index e15eeb0..f42a4a9 100644 --- a/src/Modules/IexecPoco.ts +++ b/src/Modules/IexecPoco.ts @@ -22,7 +22,6 @@ import { import { AccurateContribution, FaultyContribution, - OrdersMatched, SchedulerNotice, TaskClaimed, TaskConsensus, @@ -128,9 +127,11 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { let contract = IexecInterfaceTokenContract.bind(event.address); let viewedDeal = contract.viewDeal(event.params.dealid); + /* fetchAccount(viewedDeal.requester.toHex()).save(); fetchAccount(viewedDeal.beneficiary.toHex()).save(); fetchAccount(viewedDeal.callback.toHex()).save(); + */ let deal = fetchDeal(event.params.dealid.toHex()); deal.app = viewedDeal.app.pointer.toHex(); @@ -162,6 +163,7 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { deal.timestamp = event.block.timestamp; deal.save(); + /* const dataset = deal.dataset; let apporder = fetchApporder(event.params.appHash.toHex()); @@ -193,6 +195,7 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { protocol.dealsCount = protocol.dealsCount.plus(BigInt.fromI32(1)); protocol.tasksCount = protocol.tasksCount.plus(deal.botSize); protocol.save(); + */ } export function handleSchedulerNotice(event: SchedulerNoticeEvent): void { From 8299551e5c3eccc159678f6500948cdad4c33b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:58:08 +0100 Subject: [PATCH 10/17] View deal --- src/Modules/IexecPoco.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Modules/IexecPoco.ts b/src/Modules/IexecPoco.ts index f42a4a9..9d9733b 100644 --- a/src/Modules/IexecPoco.ts +++ b/src/Modules/IexecPoco.ts @@ -133,6 +133,7 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { fetchAccount(viewedDeal.callback.toHex()).save(); */ + /* let deal = fetchDeal(event.params.dealid.toHex()); deal.app = viewedDeal.app.pointer.toHex(); deal.appOwner = viewedDeal.app.owner.toHex(); @@ -162,6 +163,7 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { deal.requestorder = event.params.requestHash.toHex(); deal.timestamp = event.block.timestamp; deal.save(); + */ /* const dataset = deal.dataset; From 32d286d122be5d7a3cbf0ca2f01fd06084393983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:00:49 +0100 Subject: [PATCH 11/17] Fetch deal --- src/Modules/IexecPoco.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Modules/IexecPoco.ts b/src/Modules/IexecPoco.ts index 9d9733b..d024eee 100644 --- a/src/Modules/IexecPoco.ts +++ b/src/Modules/IexecPoco.ts @@ -132,9 +132,9 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { fetchAccount(viewedDeal.beneficiary.toHex()).save(); fetchAccount(viewedDeal.callback.toHex()).save(); */ - - /* + console.log(viewedDeal.botSize); let deal = fetchDeal(event.params.dealid.toHex()); + /* deal.app = viewedDeal.app.pointer.toHex(); deal.appOwner = viewedDeal.app.owner.toHex(); deal.appPrice = toRLC(viewedDeal.app.price); From e33ce776f720692348dad0ee9af332aef5fa2358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:03:26 +0100 Subject: [PATCH 12/17] Log bot --- src/Modules/IexecPoco.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Modules/IexecPoco.ts b/src/Modules/IexecPoco.ts index d024eee..053e61c 100644 --- a/src/Modules/IexecPoco.ts +++ b/src/Modules/IexecPoco.ts @@ -132,7 +132,7 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { fetchAccount(viewedDeal.beneficiary.toHex()).save(); fetchAccount(viewedDeal.callback.toHex()).save(); */ - console.log(viewedDeal.botSize); + console.log(viewedDeal.botSize.toString()); let deal = fetchDeal(event.params.dealid.toHex()); /* deal.app = viewedDeal.app.pointer.toHex(); From a5ef81879a82b4b50d2ce414e881d141d01dd5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:06:50 +0100 Subject: [PATCH 13/17] Fetch deal --- src/Modules/IexecPoco.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Modules/IexecPoco.ts b/src/Modules/IexecPoco.ts index 053e61c..f06923f 100644 --- a/src/Modules/IexecPoco.ts +++ b/src/Modules/IexecPoco.ts @@ -132,10 +132,9 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { fetchAccount(viewedDeal.beneficiary.toHex()).save(); fetchAccount(viewedDeal.callback.toHex()).save(); */ - console.log(viewedDeal.botSize.toString()); let deal = fetchDeal(event.params.dealid.toHex()); - /* deal.app = viewedDeal.app.pointer.toHex(); + /* deal.appOwner = viewedDeal.app.owner.toHex(); deal.appPrice = toRLC(viewedDeal.app.price); deal.dataset = viewedDeal.dataset.pointer.toHex(); From f9a978d13503b85a3b6270d510e3dc8e7796fa03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:08:35 +0100 Subject: [PATCH 14/17] Only fetch deal --- src/Modules/IexecPoco.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Modules/IexecPoco.ts b/src/Modules/IexecPoco.ts index f06923f..d9d07d0 100644 --- a/src/Modules/IexecPoco.ts +++ b/src/Modules/IexecPoco.ts @@ -133,8 +133,8 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { fetchAccount(viewedDeal.callback.toHex()).save(); */ let deal = fetchDeal(event.params.dealid.toHex()); - deal.app = viewedDeal.app.pointer.toHex(); /* + deal.app = viewedDeal.app.pointer.toHex(); deal.appOwner = viewedDeal.app.owner.toHex(); deal.appPrice = toRLC(viewedDeal.app.price); deal.dataset = viewedDeal.dataset.pointer.toHex(); From 5a6252e1d183832022a2c40814a21ea989cc6579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Thu, 30 Jan 2025 20:05:18 +0100 Subject: [PATCH 15/17] Check sponsor saved to deal --- src/Modules/IexecPoco.ts | 7 +-- test/Modules/IexecPoco.test.ts | 87 +++++++++++++++++++--------------- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/src/Modules/IexecPoco.ts b/src/Modules/IexecPoco.ts index d9d07d0..2edec4e 100644 --- a/src/Modules/IexecPoco.ts +++ b/src/Modules/IexecPoco.ts @@ -22,6 +22,7 @@ import { import { AccurateContribution, FaultyContribution, + OrdersMatched, SchedulerNotice, TaskClaimed, TaskConsensus, @@ -127,13 +128,10 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { let contract = IexecInterfaceTokenContract.bind(event.address); let viewedDeal = contract.viewDeal(event.params.dealid); - /* fetchAccount(viewedDeal.requester.toHex()).save(); fetchAccount(viewedDeal.beneficiary.toHex()).save(); fetchAccount(viewedDeal.callback.toHex()).save(); - */ let deal = fetchDeal(event.params.dealid.toHex()); - /* deal.app = viewedDeal.app.pointer.toHex(); deal.appOwner = viewedDeal.app.owner.toHex(); deal.appPrice = toRLC(viewedDeal.app.price); @@ -162,9 +160,7 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { deal.requestorder = event.params.requestHash.toHex(); deal.timestamp = event.block.timestamp; deal.save(); - */ - /* const dataset = deal.dataset; let apporder = fetchApporder(event.params.appHash.toHex()); @@ -196,7 +192,6 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { protocol.dealsCount = protocol.dealsCount.plus(BigInt.fromI32(1)); protocol.tasksCount = protocol.tasksCount.plus(deal.botSize); protocol.save(); - */ } export function handleSchedulerNotice(event: SchedulerNoticeEvent): void { diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index 7d03168..98afa19 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -3,6 +3,7 @@ import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'; import { + assert, createMockedFunction, describe, newTypedMockEventWithParams, @@ -17,6 +18,10 @@ describe('IexecPoco', () => { const dealId = Bytes.fromHexString( '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', ); + const appHash = dealId; + const datasetHash = dealId; + const workerpoolHash = dealId; + const requestHash = dealId; const sponsor = Address.fromString('0xabcdef1234567890abcdef1234567890abcdef12'); const timestamp = BigInt.fromI32(123456789); const assetAddress = Address.fromString('0x90cBa2Bbb19ecc291A12066Fd8329D65FA1f1947'); @@ -34,47 +39,58 @@ describe('IexecPoco', () => { .withArgs([ethereum.Value.fromFixedBytes(dealId)]) .returns([ ethereum.Value.fromTuple( - // app changetype([ - ethereum.Value.fromAddress(assetAddress), - ethereum.Value.fromAddress(assetOwner), - ethereum.Value.fromI32(assetPrice), + ethereum.Value.fromTuple( + // app + changetype([ + ethereum.Value.fromAddress(assetAddress), + ethereum.Value.fromAddress(assetOwner), + ethereum.Value.fromI32(assetPrice), + ]), + ), + ethereum.Value.fromTuple( + // dataset + changetype([ + ethereum.Value.fromAddress(assetAddress), + ethereum.Value.fromAddress(assetOwner), + ethereum.Value.fromI32(assetPrice), + ]), + ), + ethereum.Value.fromTuple( + // workerpool + changetype([ + ethereum.Value.fromAddress(assetAddress), + ethereum.Value.fromAddress(assetOwner), + ethereum.Value.fromI32(assetPrice), + ]), + ), + ethereum.Value.fromI32(uint256), // trust + ethereum.Value.fromI32(uint256), // category + ethereum.Value.fromFixedBytes(bytes32), // tag + ethereum.Value.fromAddress(address), // requester + ethereum.Value.fromAddress(address), // beneficiary + ethereum.Value.fromAddress(address), // callback + ethereum.Value.fromString(string), // params + ethereum.Value.fromI32(uint256), // startTime + ethereum.Value.fromI32(uint256), // botFirst + ethereum.Value.fromI32(uint256), // botSize + ethereum.Value.fromI32(uint256), // workerStake + ethereum.Value.fromI32(uint256), // schedulerRewardRatio + ethereum.Value.fromAddress(sponsor), // sponsor ]), ), - ethereum.Value.fromTuple( - // dataset - changetype([ - ethereum.Value.fromAddress(assetAddress), - ethereum.Value.fromAddress(assetOwner), - ethereum.Value.fromI32(assetPrice), - ]), - ), - ethereum.Value.fromTuple( - // workerpool - changetype([ - ethereum.Value.fromAddress(assetAddress), - ethereum.Value.fromAddress(assetOwner), - ethereum.Value.fromI32(assetPrice), - ]), - ), - ethereum.Value.fromI32(uint256), // trust - ethereum.Value.fromI32(uint256), // category - ethereum.Value.fromFixedBytes(bytes32), // tag - ethereum.Value.fromAddress(address), // requester - ethereum.Value.fromAddress(address), // beneficiary - ethereum.Value.fromAddress(address), // callback - ethereum.Value.fromString(string), // params - ethereum.Value.fromI32(uint256), // startTime - ethereum.Value.fromI32(uint256), // botFirst - ethereum.Value.fromI32(uint256), // botSize - ethereum.Value.fromI32(uint256), // workerStake - ethereum.Value.fromI32(uint256), // schedulerRewardRatio - ethereum.Value.fromAddress(address), // sponsor ]); // Create the mock event let mockEvent = newTypedMockEventWithParams([ - new ethereum.EventParam('deal', ethereum.Value.fromFixedBytes(dealId)), + new ethereum.EventParam('dealid', ethereum.Value.fromFixedBytes(dealId)), + new ethereum.EventParam('appHash', ethereum.Value.fromFixedBytes(appHash)), + new ethereum.EventParam('datasetHash', ethereum.Value.fromFixedBytes(datasetHash)), + new ethereum.EventParam( + 'workerpoolHash', + ethereum.Value.fromFixedBytes(workerpoolHash), + ), + new ethereum.EventParam('requestHash', ethereum.Value.fromFixedBytes(requestHash)), ]); mockEvent.block.timestamp = timestamp; mockEvent.address = pocoProxyAddress; @@ -82,8 +98,6 @@ describe('IexecPoco', () => { // Call the handler handleOrdersMatched(mockEvent); - /* - // Assert that the OrdersMatched entity was created and has correct fields const entityId = mockEvent.block.number .toString() @@ -98,7 +112,6 @@ describe('IexecPoco', () => { // Assert that a transaction was logged (if applicable) const transactionId = mockEvent.transaction.hash.toHex(); assert.fieldEquals('Transaction', transactionId, 'id', transactionId); - */ }); }); From 335c9e373356bf948fdfc97d35e5685eb2f60e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:20:43 +0100 Subject: [PATCH 16/17] Refactor should handle OrdersMatched test --- src/Modules/IexecPoco.ts | 1 + test/Modules/IexecPoco.test.ts | 198 ++++++++++++++++++-------------- test/utils/EventParamBuilder.ts | 36 ++++++ test/utils/mock.ts | 88 ++++++++++++++ test/utils/utils.ts | 9 ++ 5 files changed, 245 insertions(+), 87 deletions(-) create mode 100644 test/utils/EventParamBuilder.ts create mode 100644 test/utils/mock.ts create mode 100644 test/utils/utils.ts diff --git a/src/Modules/IexecPoco.ts b/src/Modules/IexecPoco.ts index 2edec4e..e15eeb0 100644 --- a/src/Modules/IexecPoco.ts +++ b/src/Modules/IexecPoco.ts @@ -131,6 +131,7 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void { fetchAccount(viewedDeal.requester.toHex()).save(); fetchAccount(viewedDeal.beneficiary.toHex()).save(); fetchAccount(viewedDeal.callback.toHex()).save(); + let deal = fetchDeal(event.params.dealid.toHex()); deal.app = viewedDeal.app.pointer.toHex(); deal.appOwner = viewedDeal.app.owner.toHex(); diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index 98afa19..1a3484f 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -1,99 +1,59 @@ // SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 -import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'; -import { - assert, - createMockedFunction, - describe, - newTypedMockEventWithParams, - test, -} from 'matchstick-as/assembly/index'; +import { BigInt, ethereum } from '@graphprotocol/graph-ts'; +import { assert, describe, newTypedMockEventWithParams, test } from 'matchstick-as/assembly/index'; import { OrdersMatched } from '../../generated/Core/IexecInterfaceToken'; import { handleOrdersMatched } from '../../src/Modules'; +import { EventParamBuilder } from '../utils/EventParamBuilder'; +import { buildDeal, mockAddress, mockBytes32, mockViewDeal } from '../utils/mock'; +import { nRLCToRLC } from '../utils/utils'; + +const pocoAddress = mockAddress('pocoAddress'); +const dealId = mockBytes32('dealId'); +const appHash = mockBytes32('appHash'); +const datasetHash = mockBytes32('datasetHash'); +const workerpoolHash = mockBytes32('workerpoolHash'); +const requestHash = mockBytes32('requestHash'); +const timestamp = BigInt.fromI32(123456789); +const appAddress = mockAddress('appAddress'); +const appOwner = mockAddress('appOwner'); +const appPrice = BigInt.fromI32(1); +const datasetAddress = mockAddress('datasetAddress'); +const datasetOwner = mockAddress('datasetOwner'); +const datasetPrice = BigInt.fromI32(2); +const workerpoolAddress = mockAddress('workerpoolAddress'); +const workerpoolOwner = mockAddress('workerpoolOwner'); +const workerpoolPrice = BigInt.fromI32(3); +const trust = BigInt.fromI32(4); +const category = BigInt.fromI32(5); +const tag = mockBytes32('tag'); +const requester = mockAddress('requester'); +const beneficiary = mockAddress('beneficiary'); +const callback = mockAddress('callback'); +const params = 'params'; +const startTime = BigInt.fromI32(6); +const botFirst = BigInt.fromI32(7); +const botSize = BigInt.fromI32(8); +const workerStake = BigInt.fromI32(9); +const schedulerRewardRatio = BigInt.fromI32(10); +const sponsor = mockAddress('sponsor'); describe('IexecPoco', () => { test('Should handle OrdersMatched', () => { - let pocoProxyAddress = Address.fromString('0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7'); - const dealId = Bytes.fromHexString( - '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', - ); - const appHash = dealId; - const datasetHash = dealId; - const workerpoolHash = dealId; - const requestHash = dealId; - const sponsor = Address.fromString('0xabcdef1234567890abcdef1234567890abcdef12'); - const timestamp = BigInt.fromI32(123456789); - const assetAddress = Address.fromString('0x90cBa2Bbb19ecc291A12066Fd8329D65FA1f1947'); - const assetOwner = Address.fromString('0x90cBa2Bbb19ecc291A12066Fd8329D65FA1f1947'); - const assetPrice = 100; - const uint256 = 200; - const bytes32 = dealId; // change it - const address = assetAddress; // change it - const string = 'a string'; - createMockedFunction( - pocoProxyAddress, - 'viewDeal', - 'viewDeal(bytes32):(((address,address,uint256),(address,address,uint256),(address,address,uint256),uint256,uint256,bytes32,address,address,address,string,uint256,uint256,uint256,uint256,uint256,address))', - ) - .withArgs([ethereum.Value.fromFixedBytes(dealId)]) - .returns([ - ethereum.Value.fromTuple( - changetype([ - ethereum.Value.fromTuple( - // app - changetype([ - ethereum.Value.fromAddress(assetAddress), - ethereum.Value.fromAddress(assetOwner), - ethereum.Value.fromI32(assetPrice), - ]), - ), - ethereum.Value.fromTuple( - // dataset - changetype([ - ethereum.Value.fromAddress(assetAddress), - ethereum.Value.fromAddress(assetOwner), - ethereum.Value.fromI32(assetPrice), - ]), - ), - ethereum.Value.fromTuple( - // workerpool - changetype([ - ethereum.Value.fromAddress(assetAddress), - ethereum.Value.fromAddress(assetOwner), - ethereum.Value.fromI32(assetPrice), - ]), - ), - ethereum.Value.fromI32(uint256), // trust - ethereum.Value.fromI32(uint256), // category - ethereum.Value.fromFixedBytes(bytes32), // tag - ethereum.Value.fromAddress(address), // requester - ethereum.Value.fromAddress(address), // beneficiary - ethereum.Value.fromAddress(address), // callback - ethereum.Value.fromString(string), // params - ethereum.Value.fromI32(uint256), // startTime - ethereum.Value.fromI32(uint256), // botFirst - ethereum.Value.fromI32(uint256), // botSize - ethereum.Value.fromI32(uint256), // workerStake - ethereum.Value.fromI32(uint256), // schedulerRewardRatio - ethereum.Value.fromAddress(sponsor), // sponsor - ]), - ), - ]); - + mockViewDeal(pocoAddress, dealId).returns([buildDefaultDeal()]); // Create the mock event - let mockEvent = newTypedMockEventWithParams([ - new ethereum.EventParam('dealid', ethereum.Value.fromFixedBytes(dealId)), - new ethereum.EventParam('appHash', ethereum.Value.fromFixedBytes(appHash)), - new ethereum.EventParam('datasetHash', ethereum.Value.fromFixedBytes(datasetHash)), - new ethereum.EventParam( - 'workerpoolHash', - ethereum.Value.fromFixedBytes(workerpoolHash), - ), - new ethereum.EventParam('requestHash', ethereum.Value.fromFixedBytes(requestHash)), - ]); + let mockEvent = newTypedMockEventWithParams( + EventParamBuilder.init() + .bytes('dealid', dealId) + .bytes('appHash', appHash) + .bytes('datasetHash', datasetHash) + .bytes('workerpoolHash', workerpoolHash) + .bytes('requestHash', requestHash) + .build(), + ); mockEvent.block.timestamp = timestamp; - mockEvent.address = pocoProxyAddress; + mockEvent.address = pocoAddress; // Call the handler handleOrdersMatched(mockEvent); @@ -106,8 +66,45 @@ describe('IexecPoco', () => { assert.fieldEquals('OrdersMatched', entityId, 'deal', dealId.toHex()); assert.fieldEquals('OrdersMatched', entityId, 'timestamp', timestamp.toString()); + // Check deal + assert.fieldEquals('Deal', dealId.toHex(), 'app', appAddress.toHex()); + assert.fieldEquals('Deal', dealId.toHex(), 'appOwner', appOwner.toHex()); + assert.fieldEquals('Deal', dealId.toHex(), 'appPrice', nRLCToRLC(appPrice).toString()); + assert.fieldEquals('Deal', dealId.toHex(), 'dataset', datasetAddress.toHex()); + assert.fieldEquals('Deal', dealId.toHex(), 'datasetOwner', datasetOwner.toHex()); + assert.fieldEquals( + 'Deal', + dealId.toHex(), + 'datasetPrice', + nRLCToRLC(datasetPrice).toString(), + ); + assert.fieldEquals('Deal', dealId.toHex(), 'workerpool', workerpoolAddress.toHex()); + assert.fieldEquals('Deal', dealId.toHex(), 'workerpoolOwner', workerpoolOwner.toHex()); + assert.fieldEquals( + 'Deal', + dealId.toHex(), + 'workerpoolPrice', + nRLCToRLC(workerpoolPrice).toString(), + ); + assert.fieldEquals('Deal', dealId.toHex(), 'trust', trust.toString()); + assert.fieldEquals('Deal', dealId.toHex(), 'category', category.toString()); + assert.fieldEquals('Deal', dealId.toHex(), 'tag', tag.toHex()); + assert.fieldEquals('Deal', dealId.toHex(), 'requester', requester.toHex()); + assert.fieldEquals('Deal', dealId.toHex(), 'beneficiary', beneficiary.toHex()); + assert.fieldEquals('Deal', dealId.toHex(), 'callback', callback.toHex()); + assert.fieldEquals('Deal', dealId.toHex(), 'params', params); + assert.fieldEquals('Deal', dealId.toHex(), 'startTime', startTime.toString()); + assert.fieldEquals('Deal', dealId.toHex(), 'botFirst', botFirst.toString()); + assert.fieldEquals('Deal', dealId.toHex(), 'botSize', botSize.toString()); + assert.fieldEquals('Deal', dealId.toHex(), 'workerStake', workerStake.toString()); + assert.fieldEquals( + 'Deal', + dealId.toHex(), + 'schedulerRewardRatio', + schedulerRewardRatio.toString(), + ); assert.fieldEquals('Deal', dealId.toHex(), 'sponsor', sponsor.toHex()); - // TODO: Verify others fields + // TODO: Check other saved entities // Assert that a transaction was logged (if applicable) const transactionId = mockEvent.transaction.hash.toHex(); @@ -115,4 +112,31 @@ describe('IexecPoco', () => { }); }); +function buildDefaultDeal(): ethereum.Value { + return buildDeal( + appAddress, + appOwner, + appPrice, + datasetAddress, + datasetOwner, + datasetPrice, + workerpoolAddress, + workerpoolOwner, + workerpoolPrice, + trust, + category, + tag, + requester, + beneficiary, + callback, + params, + startTime, + botFirst, + botSize, + workerStake, + schedulerRewardRatio, + sponsor, + ); +} + export { OrdersMatched }; diff --git a/test/utils/EventParamBuilder.ts b/test/utils/EventParamBuilder.ts new file mode 100644 index 0000000..f7992cc --- /dev/null +++ b/test/utils/EventParamBuilder.ts @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2025 IEXEC BLOCKCHAIN TECH +// SPDX-License-Identifier: Apache-2.0 + +import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'; + +export class EventParamBuilder { + private params: ethereum.EventParam[] = new Array(); + + static init(): EventParamBuilder { + return new EventParamBuilder(); + } + + address(key: string, value: Address): EventParamBuilder { + this.params.push(new ethereum.EventParam(key, ethereum.Value.fromAddress(value))); + return this; + } + + bytes(key: string, value: Bytes): EventParamBuilder { + this.params.push(new ethereum.EventParam(key, ethereum.Value.fromBytes(value))); + return this; + } + + bigInt(key: string, value: BigInt): EventParamBuilder { + this.params.push(new ethereum.EventParam(key, ethereum.Value.fromUnsignedBigInt(value))); + return this; + } + + string(key: string, value: string): EventParamBuilder { + this.params.push(new ethereum.EventParam(key, ethereum.Value.fromString(value))); + return this; + } + + build(): ethereum.EventParam[] { + return this.params; + } +} diff --git a/test/utils/mock.ts b/test/utils/mock.ts new file mode 100644 index 0000000..db14363 --- /dev/null +++ b/test/utils/mock.ts @@ -0,0 +1,88 @@ +// SPDX-FileCopyrightText: 2025 IEXEC BLOCKCHAIN TECH +// SPDX-License-Identifier: Apache-2.0 + +import { Address, BigInt, ByteArray, Bytes, crypto, ethereum } from '@graphprotocol/graph-ts'; +import { createMockedFunction, MockedFunction } from 'matchstick-as'; + +export function mockBytes32(input: string): Bytes { + return Bytes.fromHexString(crypto.keccak256(ByteArray.fromUTF8(input)).toHex()); +} + +export function mockAddress(input: string): Address { + return Address.fromString(mockBytes32(input).toHex().slice(0, 42)); +} + +export function mockViewDeal(pocoProxyAddress: Address, dealId: Bytes): MockedFunction { + return createMockedFunction( + pocoProxyAddress, + 'viewDeal', + 'viewDeal(bytes32):(((address,address,uint256),(address,address,uint256),(address,address,uint256),uint256,uint256,bytes32,address,address,address,string,uint256,uint256,uint256,uint256,uint256,address))', + ).withArgs([ethereum.Value.fromFixedBytes(dealId)]); +} + +export function buildDeal( + appAddress: Address, + appOwner: Address, + appPrice: BigInt, + datasetAddress: Address, + datasetOwner: Address, + datasetPrice: BigInt, + workerpoolAddress: Address, + workerpoolOwner: Address, + workerpoolPrice: BigInt, + trust: BigInt, + category: BigInt, + tag: Bytes, + requester: Address, + beneficiary: Address, + callback: Address, + params: string, + startTime: BigInt, + botFirst: BigInt, + botSize: BigInt, + workerStake: BigInt, + schedulerRewardRatio: BigInt, + sponsor: Address, +): ethereum.Value { + return ethereum.Value.fromTuple( + changetype([ + ethereum.Value.fromTuple( + // app + changetype([ + ethereum.Value.fromAddress(appAddress), + ethereum.Value.fromAddress(appOwner), + ethereum.Value.fromI32(appPrice.toI32()), + ]), + ), + ethereum.Value.fromTuple( + // dataset + changetype([ + ethereum.Value.fromAddress(datasetAddress), + ethereum.Value.fromAddress(datasetOwner), + ethereum.Value.fromI32(datasetPrice.toI32()), + ]), + ), + ethereum.Value.fromTuple( + // workerpool + changetype([ + ethereum.Value.fromAddress(workerpoolAddress), + ethereum.Value.fromAddress(workerpoolOwner), + ethereum.Value.fromI32(workerpoolPrice.toI32()), + ]), + ), + ethereum.Value.fromI32(trust.toI32()), + ethereum.Value.fromI32(category.toI32()), + ethereum.Value.fromFixedBytes(tag), + ethereum.Value.fromAddress(requester), + ethereum.Value.fromAddress(beneficiary), + ethereum.Value.fromAddress(callback), + ethereum.Value.fromString(params), + ethereum.Value.fromI32(startTime.toI32()), + ethereum.Value.fromI32(botFirst.toI32()), + ethereum.Value.fromI32(botSize.toI32()), + ethereum.Value.fromI32(workerStake.toI32()), + ethereum.Value.fromI32(schedulerRewardRatio.toI32()), + ethereum.Value.fromAddress(sponsor), + ]), + ); +} diff --git a/test/utils/utils.ts b/test/utils/utils.ts new file mode 100644 index 0000000..2f5ec4a --- /dev/null +++ b/test/utils/utils.ts @@ -0,0 +1,9 @@ +// SPDX-FileCopyrightText: 2025 IEXEC BLOCKCHAIN TECH +// SPDX-License-Identifier: Apache-2.0 + +import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'; + +export function nRLCToRLC(value: BigInt): BigDecimal { + let divisor = BigDecimal.fromString('1000000000'); + return value.divDecimal(divisor); +} From e42fc3060507d8150f3f3c79f8b69fa7263892b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:27:00 +0100 Subject: [PATCH 17/17] Use existing RLC unit converter --- CHANGELOG.md | 2 +- test/Modules/IexecPoco.test.ts | 13 ++++--------- test/utils/utils.ts | 9 --------- 3 files changed, 5 insertions(+), 19 deletions(-) delete mode 100644 test/utils/utils.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e3eeb4..62151d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## vNext -- Add `sponsor` to `deal`. (#30) +- Add `sponsor` to `deal`. (#31) - Update staging deployment hosts. (#29) - Display coverage in Github PR checks. (#26) - Add integration test suite. (#21) diff --git a/test/Modules/IexecPoco.test.ts b/test/Modules/IexecPoco.test.ts index 1a3484f..27e3778 100644 --- a/test/Modules/IexecPoco.test.ts +++ b/test/Modules/IexecPoco.test.ts @@ -5,9 +5,9 @@ import { BigInt, ethereum } from '@graphprotocol/graph-ts'; import { assert, describe, newTypedMockEventWithParams, test } from 'matchstick-as/assembly/index'; import { OrdersMatched } from '../../generated/Core/IexecInterfaceToken'; import { handleOrdersMatched } from '../../src/Modules'; +import { toRLC } from '../../src/utils'; import { EventParamBuilder } from '../utils/EventParamBuilder'; import { buildDeal, mockAddress, mockBytes32, mockViewDeal } from '../utils/mock'; -import { nRLCToRLC } from '../utils/utils'; const pocoAddress = mockAddress('pocoAddress'); const dealId = mockBytes32('dealId'); @@ -69,22 +69,17 @@ describe('IexecPoco', () => { // Check deal assert.fieldEquals('Deal', dealId.toHex(), 'app', appAddress.toHex()); assert.fieldEquals('Deal', dealId.toHex(), 'appOwner', appOwner.toHex()); - assert.fieldEquals('Deal', dealId.toHex(), 'appPrice', nRLCToRLC(appPrice).toString()); + assert.fieldEquals('Deal', dealId.toHex(), 'appPrice', toRLC(appPrice).toString()); assert.fieldEquals('Deal', dealId.toHex(), 'dataset', datasetAddress.toHex()); assert.fieldEquals('Deal', dealId.toHex(), 'datasetOwner', datasetOwner.toHex()); - assert.fieldEquals( - 'Deal', - dealId.toHex(), - 'datasetPrice', - nRLCToRLC(datasetPrice).toString(), - ); + assert.fieldEquals('Deal', dealId.toHex(), 'datasetPrice', toRLC(datasetPrice).toString()); assert.fieldEquals('Deal', dealId.toHex(), 'workerpool', workerpoolAddress.toHex()); assert.fieldEquals('Deal', dealId.toHex(), 'workerpoolOwner', workerpoolOwner.toHex()); assert.fieldEquals( 'Deal', dealId.toHex(), 'workerpoolPrice', - nRLCToRLC(workerpoolPrice).toString(), + toRLC(workerpoolPrice).toString(), ); assert.fieldEquals('Deal', dealId.toHex(), 'trust', trust.toString()); assert.fieldEquals('Deal', dealId.toHex(), 'category', category.toString()); diff --git a/test/utils/utils.ts b/test/utils/utils.ts deleted file mode 100644 index 2f5ec4a..0000000 --- a/test/utils/utils.ts +++ /dev/null @@ -1,9 +0,0 @@ -// SPDX-FileCopyrightText: 2025 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'; - -export function nRLCToRLC(value: BigInt): BigDecimal { - let divisor = BigDecimal.fromString('1000000000'); - return value.divDecimal(divisor); -}