Skip to content

Commit 8203895

Browse files
test: add unit test for AssetTransferredToDestination
1 parent e5a0453 commit 8203895

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,
@@ -195,3 +196,35 @@ export const createConvertedEvent = (
195196

196197
return event;
197198
};
199+
200+
export const createAssetTransferredToDestinationEvent = (
201+
tokenConverterAddress: Address,
202+
receiver: Address,
203+
comptroller: Address,
204+
asset: Address,
205+
amount: string,
206+
): AssetTransferredToDestination => {
207+
const event = changetype<AssetTransferredToDestination>(newMockEvent());
208+
event.address = tokenConverterAddress;
209+
event.parameters = [];
210+
211+
const receiverParam = new ethereum.EventParam('receiver', ethereum.Value.fromAddress(receiver));
212+
event.parameters.push(receiverParam);
213+
214+
const comptrollerParam = new ethereum.EventParam(
215+
'comptroller',
216+
ethereum.Value.fromAddress(comptroller),
217+
);
218+
event.parameters.push(comptrollerParam);
219+
220+
const assetParam = new ethereum.EventParam('asset', ethereum.Value.fromAddress(asset));
221+
event.parameters.push(assetParam);
222+
223+
const amountParam = new ethereum.EventParam(
224+
'amount',
225+
ethereum.Value.fromUnsignedBigInt(BigInt.fromString(amount)),
226+
);
227+
event.parameters.push(amountParam);
228+
229+
return event;
230+
};

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[1].tokenConverter),
222+
tokenConverter2Address,
223+
);
224+
});
200225
});

0 commit comments

Comments
 (0)