|
| 1 | +import { |
| 2 | + Address, |
| 3 | + Bytes, |
| 4 | + DataSourceContext, |
| 5 | + ethereum, |
| 6 | +} from '@graphprotocol/graph-ts'; |
| 7 | +import { |
| 8 | + afterAll, |
| 9 | + assert, |
| 10 | + beforeAll, |
| 11 | + clearStore, |
| 12 | + createMockedFunction, |
| 13 | + dataSourceMock, |
| 14 | + describe, |
| 15 | + readFile, |
| 16 | + test, |
| 17 | +} from 'matchstick-as/assembly/index'; |
| 18 | +import { ZERO } from '../src/utils'; |
| 19 | +import { createNewItemEvent } from './utils/litem-utils'; |
| 20 | +import { handleNewGTCR } from '../src/LightGTCRFactoryMapping'; |
| 21 | +import { handleNewItem } from '../src/LightGeneralizedTCRMapping'; |
| 22 | +import { handleLItemMetadata } from '../src/fileHandlers/LItemMetadataHandler'; |
| 23 | +import { |
| 24 | + GRAPH_ITEM_ID, |
| 25 | + IPFS_HASH, |
| 26 | + ITEM_DATA, |
| 27 | + ITEM_ID, |
| 28 | + REGISTRY_ADDRESS, |
| 29 | +} from './utils/mockValues'; |
| 30 | +import { createNewGTCREvent } from './utils/lregistry-utils'; |
| 31 | + |
| 32 | +// mock getItemInfo function, called inside handleNewItem |
| 33 | +createMockedFunction( |
| 34 | + Address.fromString(REGISTRY_ADDRESS), |
| 35 | + 'getItemInfo', |
| 36 | + 'getItemInfo(bytes32):(uint8,uint256,uint256)', |
| 37 | +) |
| 38 | + .withArgs([ethereum.Value.fromFixedBytes(Bytes.fromHexString(ITEM_ID))]) |
| 39 | + .returns([ |
| 40 | + ethereum.Value.fromI32(0), |
| 41 | + ethereum.Value.fromUnsignedBigInt(ZERO), |
| 42 | + ethereum.Value.fromUnsignedBigInt(ZERO), |
| 43 | + ]); |
| 44 | + |
| 45 | +describe('Testing LItem creation', () => { |
| 46 | + beforeAll(() => { |
| 47 | + const newGTCREvent = createNewGTCREvent(REGISTRY_ADDRESS); |
| 48 | + |
| 49 | + handleNewGTCR(newGTCREvent); |
| 50 | + |
| 51 | + assert.fieldEquals( |
| 52 | + 'LRegistry', |
| 53 | + REGISTRY_ADDRESS, |
| 54 | + 'id', |
| 55 | + REGISTRY_ADDRESS, |
| 56 | + 'LRegistry not created', |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + test('Should create LItem entity', () => { |
| 61 | + const newItemEvent = createNewItemEvent( |
| 62 | + REGISTRY_ADDRESS, |
| 63 | + ITEM_ID, |
| 64 | + ITEM_DATA, |
| 65 | + ); |
| 66 | + |
| 67 | + handleNewItem(newItemEvent); |
| 68 | + |
| 69 | + assert.fieldEquals('LItem', GRAPH_ITEM_ID, 'id', GRAPH_ITEM_ID); |
| 70 | + }); |
| 71 | + |
| 72 | + test('Should create LItemMetadata datasource', () => { |
| 73 | + // previous test should have created this datasource |
| 74 | + assert.dataSourceExists('LItemMetadata', IPFS_HASH); |
| 75 | + |
| 76 | + const context = new DataSourceContext(); |
| 77 | + context.setString('graphItemID', GRAPH_ITEM_ID); |
| 78 | + context.setString('address', REGISTRY_ADDRESS); |
| 79 | + dataSourceMock.setReturnValues(IPFS_HASH, 'arbitrum-one', context); |
| 80 | + |
| 81 | + const content = readFile('tests/ipfs/item.json'); |
| 82 | + |
| 83 | + handleLItemMetadata(content); |
| 84 | + |
| 85 | + const metadataEntityId = `${IPFS_HASH}-${GRAPH_ITEM_ID}`; |
| 86 | + |
| 87 | + assert.fieldEquals( |
| 88 | + 'LItemMetadata', |
| 89 | + metadataEntityId, |
| 90 | + 'id', |
| 91 | + metadataEntityId, |
| 92 | + ); |
| 93 | + dataSourceMock.resetValues(); |
| 94 | + }); |
| 95 | + |
| 96 | + afterAll(() => { |
| 97 | + clearStore(); |
| 98 | + }); |
| 99 | +}); |
0 commit comments