Skip to content

Commit 619bfa6

Browse files
authored
Merge pull request #23 from iExecBlockchainComputing/feature/poco-sponsoring
Add DealSponsored event handler
2 parents 550d4de + 508680d commit 619bfa6

File tree

9 files changed

+111
-51
lines changed

9 files changed

+111
-51
lines changed

docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
FROM node:22
22
WORKDIR /iexec-poco-subgraph
3-
RUN apt-get update && apt-get install -y git
43
COPY package*.json .
54
RUN npm ci
65
COPY schema.graphql .

itest/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Integration tests', () => {
1919
before(async () => {
2020
console.log('Starting services..');
2121
const environment = new DockerComposeEnvironment('docker/test/', 'docker-compose.yml')
22-
.withStartupTimeout(3 * MINUTES)
22+
.withStartupTimeout(5 * MINUTES)
2323
.withWaitStrategy(
2424
'poco-subgraph-deployer-1',
2525
Wait.forLogMessage(

package-lock.json

Lines changed: 36 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"create": "graph create ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020}",
1313
"deploy": "graph deploy ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --version-label ${VERSION_LABEL:-bellecour/poco-v5}",
1414
"deploy:all": "npm run build && npm run create && npm run deploy",
15-
"itest": "DEBUG=:* mocha"
15+
"itest": "DEBUG=testcontainers:* mocha"
16+
1617
},
1718
"lint-staged": {
1819
"*.{js,ts}": [
@@ -41,7 +42,7 @@
4142
"testcontainers": "^10.13.2"
4243
},
4344
"dependencies": {
44-
"@iexec/poco": "5.3.0",
45-
"@iexec/solidity": "0.1.0"
45+
"@iexec/poco": "^5.5.0",
46+
"@iexec/solidity": "^0.1.1"
4647
}
4748
}

schema.graphql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ type OrdersMatched implements DealEvent @entity {
436436
deal: Deal!
437437
}
438438

439+
type DealSponsored implements DealEvent @entity {
440+
id: ID!
441+
transaction: Transaction!
442+
timestamp: BigInt!
443+
deal: Deal!
444+
sponsor: Account!
445+
}
446+
439447
interface TaskEvent {
440448
id: ID!
441449
transaction: Transaction!

src/Modules/IexecPoco.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BigInt } from '@graphprotocol/graph-ts';
55

66
import {
77
AccurateContribution as AccurateContributionEvent,
8+
DealSponsored as DealSponsoredEvent,
89
FaultyContribution as FaultyContributionEvent,
910
IexecInterfaceToken as IexecInterfaceTokenContract,
1011
MatchOrdersCall,
@@ -21,6 +22,7 @@ import {
2122

2223
import {
2324
AccurateContribution,
25+
DealSponsored,
2426
FaultyContribution,
2527
OrdersMatched,
2628
SchedulerNotice,
@@ -421,3 +423,16 @@ export function handleFaultyContribution(event: FaultyContributionEvent): void {
421423
workerAccount.score = faultyContributionEvent.score;
422424
workerAccount.save();
423425
}
426+
427+
export function handleDealSponsored(event: DealSponsoredEvent): void {
428+
let dealSponsoredEvent = DealSponsored.load(createEventID(event));
429+
if (!dealSponsoredEvent) {
430+
dealSponsoredEvent = new DealSponsored(createEventID(event));
431+
}
432+
dealSponsoredEvent.transaction = logTransaction(event).id;
433+
dealSponsoredEvent.transaction = logTransaction(event).id;
434+
dealSponsoredEvent.timestamp = event.block.timestamp;
435+
dealSponsoredEvent.deal = event.params.dealId.toHex();
436+
dealSponsoredEvent.sponsor = event.params.sponsor.toHex();
437+
dealSponsoredEvent.save();
438+
}

src/Modules/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export { handleLock, handleReward, handleSeize, handleTransfer, handleUnlock } f
77

88
export {
99
handleAccurateContribution,
10+
handleDealSponsored,
1011
handleFaultyContribution,
1112
handleMatchOrders,
1213
handleOrdersMatched,

subgraph.template.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ dataSources:
6969
- Seize
7070
- Lock
7171
- Unlock
72+
- DealSponsored
7273
abis:
7374
- name: IexecInterfaceToken
74-
file: node_modules/@iexec/poco/build/contracts/IexecInterfaceNative.json
75+
file: node_modules/@iexec/poco/artifacts/contracts/IexecInterfaceNative.sol/IexecInterfaceNative.json
7576
eventHandlers:
7677
- event: CreateCategory(uint256,string,string,uint256)
7778
handler: handleCreateCategory
@@ -107,6 +108,8 @@ dataSources:
107108
handler: handleLock
108109
- event: Unlock(address,uint256)
109110
handler: handleUnlock
111+
- event: DealSponsored(bytes32,address)
112+
handler: handleDealSponsored
110113
callHandlers:
111114
- 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))
112115
handler: handleMatchOrders

test/Modules/IexecPoco.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-FileCopyrightText: 2024 IEXEC BLOCKCHAIN TECH <[email protected]>
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts';
5+
import { assert, describe, newTypedMockEventWithParams, test } from 'matchstick-as/assembly/index';
6+
import { DealSponsored } from '../../generated/Core/IexecInterfaceToken';
7+
import { handleDealSponsored } from '../../src/Modules';
8+
9+
describe('IexecPoco', () => {
10+
test('Should handle DealSponsored', () => {
11+
// Define mock parameters
12+
const dealId = Bytes.fromHexString(
13+
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
14+
);
15+
const sponsor = Address.fromString('0xabcdef1234567890abcdef1234567890abcdef12');
16+
const timestamp = BigInt.fromI32(123456789);
17+
18+
// Create the mock event
19+
let mockEvent = newTypedMockEventWithParams<DealSponsored>([
20+
new ethereum.EventParam('deal', ethereum.Value.fromFixedBytes(dealId)),
21+
new ethereum.EventParam('sponsor', ethereum.Value.fromAddress(sponsor)),
22+
]);
23+
mockEvent.block.timestamp = timestamp;
24+
25+
// Call the handler
26+
handleDealSponsored(mockEvent);
27+
28+
// Assert that the DealSponsored entity was created and has correct fields
29+
const entityId = mockEvent.block.number
30+
.toString()
31+
.concat('-')
32+
.concat(mockEvent.logIndex.toString());
33+
34+
assert.fieldEquals('DealSponsored', entityId, 'deal', dealId.toHex());
35+
assert.fieldEquals('DealSponsored', entityId, 'sponsor', sponsor.toHex());
36+
assert.fieldEquals('DealSponsored', entityId, 'timestamp', timestamp.toString());
37+
38+
// Assert that a transaction was logged (if applicable)
39+
const transactionId = mockEvent.transaction.hash.toHex();
40+
assert.fieldEquals('Transaction', transactionId, 'id', transactionId);
41+
});
42+
});

0 commit comments

Comments
 (0)