From 54f593870a39722224313359e0dacb06676287fa Mon Sep 17 00:00:00 2001 From: Jerry Okolo Date: Tue, 6 Sep 2022 15:35:54 +0100 Subject: [PATCH] test cleanup --- tests/handleAssign.test.ts | 54 +++++++++++++++++++ ...mapping.test.ts => handleTransfer.test.ts} | 6 +-- tests/helpers/utils.ts | 34 ++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 tests/handleAssign.test.ts rename tests/{CryptoPunks/mapping.test.ts => handleTransfer.test.ts} (93%) create mode 100644 tests/helpers/utils.ts diff --git a/tests/handleAssign.test.ts b/tests/handleAssign.test.ts new file mode 100644 index 0000000..1625f95 --- /dev/null +++ b/tests/handleAssign.test.ts @@ -0,0 +1,54 @@ +import { Bytes, BigInt, Address, ethereum } from '@graphprotocol/graph-ts' +import { Assign } from '../generated/cryptopunks/cryptopunks' +import { + newMockEvent, + test, + assert, + clearStore, + afterEach, + describe, + beforeEach, +} from 'matchstick-as/assembly/index' +import { handleAssign } from '../src/mapping' +import Utils from '../tests/helpers/utils' + +describe('handleAssign', () => { + beforeEach(() => { + Utils.seedEntity() + }) + + afterEach(() => { + clearStore() + }) + + test('can handle new bounty closed', () => { + let newAssignEvent = createNewAssignEvent(Utils.bountyId, Utils.id_STRING) + + newAssignEvent.transaction.hash = Bytes.fromHexString(Utils.transactionHash) + + handleAssign(newAssignEvent) + + assert.fieldEquals('Bounty', Utils.id, 'AssignTime', Utils.AssignTime) + assert.fieldEquals('Bounty', Utils.id, 'closer', Utils.userId) + assert.fieldEquals('Bounty', Utils.id, 'status', Utils.status_CLOSED) + }) +}) + +export function createNewAssignEvent( + bountyId: string, + bountyAddress: string +): Assign { + let newAssignEvent = changetype(newMockEvent()) + + let parameters: Array = [ + new ethereum.EventParam('bountyId', ethereum.Value.fromString(bountyId)), + new ethereum.EventParam( + 'bountyAddress', + ethereum.Value.fromAddress(Address.fromString(bountyAddress)) + ), + ] + + newAssignEvent.parameters = parameters + + return newAssignEvent +} diff --git a/tests/CryptoPunks/mapping.test.ts b/tests/handleTransfer.test.ts similarity index 93% rename from tests/CryptoPunks/mapping.test.ts rename to tests/handleTransfer.test.ts index 5eede91..23e9975 100644 --- a/tests/CryptoPunks/mapping.test.ts +++ b/tests/handleTransfer.test.ts @@ -7,10 +7,10 @@ import { } from 'matchstick-as/assembly/index' // import { log } from 'matchstick-as/assembly/log' import { logStore } from 'matchstick-as/assembly/store' -import { PunkTransfer } from '../../generated/cryptopunks/cryptopunks' -import { handlePunkTransfer } from '../../src/mapping' +import { PunkTransfer } from '../generated/cryptopunks/cryptopunks' +import { handlePunkTransfer } from '../src/mapping' -import { WRAPPED_PUNK_ADDRESS, ZERO_ADDRESS } from '../../src/constant' +import { WRAPPED_PUNK_ADDRESS, ZERO_ADDRESS } from '../src/constant' /////////////////////////////////// /// Mock Values /// diff --git a/tests/helpers/utils.ts b/tests/helpers/utils.ts new file mode 100644 index 0000000..3d5608a --- /dev/null +++ b/tests/helpers/utils.ts @@ -0,0 +1,34 @@ +import { + Bytes, + BigInt, + Address, + Entity, + store, + log, +} from '@graphprotocol/graph-ts' + +export default class Utils { + constructor() {} + + static get id_BYTES(): Bytes { + return Bytes.fromHexString('0x06b306c85e5f33b1b2d971822ce0ed42fb7ab9a1') + } + + static get id_STRING(): string { + return '0x06b306c85e5f33b1b2d971822ce0ed42fb7ab9a1' + } + + static get Bi_ZERO(): BigInt { + return BigInt.zero() + } + + static seedEntity(): void { + let entity = new Entity() + + entity.setBytes('id', Utils.id_BYTES) + entity.setString('bountyAddress', Utils.id_STRING) + entity.setBigInt('status', Utils.Bi_ZERO) + + store.set('Entity', Utils.id_STRING, entity) + } +}