Skip to content

Commit

Permalink
Merge pull request #23 from iExecBlockchainComputing/feature/poco-spo…
Browse files Browse the repository at this point in the history
…nsoring

Add DealSponsored event handler
  • Loading branch information
gfournieriExec authored Dec 13, 2024
2 parents 550d4de + 508680d commit 619bfa6
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 51 deletions.
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM node:22
WORKDIR /iexec-poco-subgraph
RUN apt-get update && apt-get install -y git
COPY package*.json .
RUN npm ci
COPY schema.graphql .
Expand Down
2 changes: 1 addition & 1 deletion itest/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Integration tests', () => {
before(async () => {
console.log('Starting services..');
const environment = new DockerComposeEnvironment('docker/test/', 'docker-compose.yml')
.withStartupTimeout(3 * MINUTES)
.withStartupTimeout(5 * MINUTES)
.withWaitStrategy(
'poco-subgraph-deployer-1',
Wait.forLogMessage(
Expand Down
81 changes: 36 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"create": "graph create ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020}",
"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}",
"deploy:all": "npm run build && npm run create && npm run deploy",
"itest": "DEBUG=:* mocha"
"itest": "DEBUG=testcontainers:* mocha"

},
"lint-staged": {
"*.{js,ts}": [
Expand Down Expand Up @@ -41,7 +42,7 @@
"testcontainers": "^10.13.2"
},
"dependencies": {
"@iexec/poco": "5.3.0",
"@iexec/solidity": "0.1.0"
"@iexec/poco": "^5.5.0",
"@iexec/solidity": "^0.1.1"
}
}
8 changes: 8 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ 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!
Expand Down
15 changes: 15 additions & 0 deletions src/Modules/IexecPoco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BigInt } from '@graphprotocol/graph-ts';

import {
AccurateContribution as AccurateContributionEvent,
DealSponsored as DealSponsoredEvent,
FaultyContribution as FaultyContributionEvent,
IexecInterfaceToken as IexecInterfaceTokenContract,
MatchOrdersCall,
Expand All @@ -21,6 +22,7 @@ import {

import {
AccurateContribution,
DealSponsored,
FaultyContribution,
OrdersMatched,
SchedulerNotice,
Expand Down Expand Up @@ -421,3 +423,16 @@ 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();
}
1 change: 1 addition & 0 deletions src/Modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { handleLock, handleReward, handleSeize, handleTransfer, handleUnlock } f

export {
handleAccurateContribution,
handleDealSponsored,
handleFaultyContribution,
handleMatchOrders,
handleOrdersMatched,
Expand Down
5 changes: 4 additions & 1 deletion subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ dataSources:
- Seize
- Lock
- Unlock
- DealSponsored
abis:
- name: IexecInterfaceToken
file: node_modules/@iexec/poco/build/contracts/IexecInterfaceNative.json
file: node_modules/@iexec/poco/artifacts/contracts/IexecInterfaceNative.sol/IexecInterfaceNative.json
eventHandlers:
- event: CreateCategory(uint256,string,string,uint256)
handler: handleCreateCategory
Expand Down Expand Up @@ -107,6 +108,8 @@ 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
Expand Down
42 changes: 42 additions & 0 deletions test/Modules/IexecPoco.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-FileCopyrightText: 2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// 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';

describe('IexecPoco', () => {
test('Should handle DealSponsored', () => {
// Define mock parameters
const dealId = Bytes.fromHexString(
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
);
const sponsor = Address.fromString('0xabcdef1234567890abcdef1234567890abcdef12');
const timestamp = BigInt.fromI32(123456789);

// Create the mock event
let mockEvent = newTypedMockEventWithParams<DealSponsored>([
new ethereum.EventParam('deal', ethereum.Value.fromFixedBytes(dealId)),
new ethereum.EventParam('sponsor', ethereum.Value.fromAddress(sponsor)),
]);
mockEvent.block.timestamp = timestamp;

// Call the handler
handleDealSponsored(mockEvent);

// Assert that the DealSponsored 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 that a transaction was logged (if applicable)
const transactionId = mockEvent.transaction.hash.toHex();
assert.fieldEquals('Transaction', transactionId, 'id', transactionId);
});
});

0 comments on commit 619bfa6

Please sign in to comment.