Skip to content

Commit c5dc4c3

Browse files
committed
Create UT for DealSponsored
1 parent 6d21031 commit c5dc4c3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/Modules/IexecPoco.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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('0x1234567890abcdef1234567890abcdef12345678');
13+
const sponsor = Address.fromString('0xabcdef1234567890abcdef1234567890abcdef12');
14+
const timestamp = BigInt.fromI32(123456789);
15+
16+
// Create the mock event
17+
let mockEvent = newTypedMockEventWithParams<DealSponsored>([
18+
new ethereum.EventParam('dealId', ethereum.Value.fromFixedBytes(dealId)),
19+
new ethereum.EventParam('sponsor', ethereum.Value.fromAddress(sponsor)),
20+
]);
21+
mockEvent.block.timestamp = timestamp;
22+
23+
// Call the handler
24+
handleDealSponsored(mockEvent);
25+
26+
// Assert that the DealSponsored entity was created and has correct fields
27+
const entityId = mockEvent.block.number
28+
.toString()
29+
.concat('-')
30+
.concat(mockEvent.logIndex.toString());
31+
32+
assert.fieldEquals('DealSponsored', entityId, 'deal', dealId.toHex());
33+
assert.fieldEquals('DealSponsored', entityId, 'sponsor', sponsor.toHex());
34+
assert.fieldEquals('DealSponsored', entityId, 'timestamp', timestamp.toString());
35+
36+
// Assert that a transaction was logged (if applicable)
37+
const transactionId = mockEvent.transaction.hash.toHex();
38+
assert.fieldEquals('Transaction', transactionId, 'id', transactionId);
39+
});
40+
});

0 commit comments

Comments
 (0)