Skip to content

Commit 0c6d46e

Browse files
test: add unit test for AssetTransferredToDestination
1 parent 5f2c522 commit 0c6d46e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

subgraphs/protocol-reserve/tests/TokenConverter/events.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts';
22
import { newMockEvent } from 'matchstick-as';
33

44
import {
5+
AssetTransferredToDestination,
56
BaseAssetUpdated,
67
ConvertedExactTokens,
78
ConversionConfigUpdated,
@@ -241,3 +242,35 @@ export const createConvertedEvent = (
241242

242243
return event;
243244
};
245+
246+
export const createAssetTransferredToDestinationEvent = (
247+
tokenConverterAddress: Address,
248+
receiver: Address,
249+
comptroller: Address,
250+
asset: Address,
251+
amount: string,
252+
): AssetTransferredToDestination => {
253+
const event = changetype<AssetTransferredToDestination>(newMockEvent());
254+
event.address = tokenConverterAddress;
255+
event.parameters = [];
256+
257+
const receiverParam = new ethereum.EventParam('receiver', ethereum.Value.fromAddress(receiver));
258+
event.parameters.push(receiverParam);
259+
260+
const comptrollerParam = new ethereum.EventParam(
261+
'comptroller',
262+
ethereum.Value.fromAddress(comptroller),
263+
);
264+
event.parameters.push(comptrollerParam);
265+
266+
const assetParam = new ethereum.EventParam('asset', ethereum.Value.fromAddress(asset));
267+
event.parameters.push(assetParam);
268+
269+
const amountParam = new ethereum.EventParam(
270+
'amount',
271+
ethereum.Value.fromUnsignedBigInt(BigInt.fromString(amount)),
272+
);
273+
event.parameters.push(amountParam);
274+
275+
return event;
276+
};

subgraphs/protocol-reserve/tests/TokenConverter/index.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { assert, beforeAll, describe, test } from 'matchstick-as/assembly/index'
33

44
import { TokenConverter } from '../../generated/schema';
55
import {
6+
handleAssetTransferredToDestination,
67
handleBaseAssetUpdated,
78
handleConversionConfigUpdated,
89
handleConversionEvent,
@@ -20,6 +21,7 @@ import {
2021
createConverterNetworkAddressUpdatedEvent,
2122
createConvertedEvent,
2223
createDestinationAddressUpdatedEvent,
24+
createAssetTransferredToDestinationEvent,
2325
} from './events';
2426
import { createTokenConverterMock, createTokenMock } from './mocks';
2527

@@ -197,4 +199,27 @@ describe('Token Converter', () => {
197199
tokenConverter2Address,
198200
);
199201
});
202+
203+
test('should handle an AssetTransferredToDestination event', () => {
204+
handleAssetTransferredToDestination(
205+
createAssetTransferredToDestinationEvent(
206+
tokenConverter2Address,
207+
destination1Address,
208+
Address.fromString('0x0000000000000000000000000000000000000bca'),
209+
token2Address,
210+
'12345',
211+
),
212+
);
213+
214+
const tokenConverter = TokenConverter.load(getTokenConverterId(tokenConverter2Address))!;
215+
const destinationAmounts = tokenConverter.destinationAmounts.load();
216+
assert.i32Equals(destinationAmounts.length, 2);
217+
assert.bigIntEquals(destinationAmounts[1].amount, BigInt.fromString('12345'));
218+
assert.addressEquals(Address.fromBytes(destinationAmounts[1].token), token2Address);
219+
assert.addressEquals(Address.fromBytes(destinationAmounts[1].address), destination1Address);
220+
assert.addressEquals(
221+
Address.fromBytes(destinationAmounts[0].tokenConverter),
222+
tokenConverter2Address,
223+
);
224+
});
200225
});

0 commit comments

Comments
 (0)