diff --git a/tests/handlePunkNoLongerForSale.test.ts b/tests/handlePunkNoLongerForSale.test.ts new file mode 100644 index 0000000..73325dd --- /dev/null +++ b/tests/handlePunkNoLongerForSale.test.ts @@ -0,0 +1,57 @@ +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 { handlePunkNoLongerForSale } from '../src/mapping' +import Utils from '../tests/helpers/utils' + +describe('handleAssign', () => { + beforeEach(() => { + Utils.seedEntity() + }) + + afterEach(() => { + clearStore() + }) + + test('can handle new bounty closed', () => { + let newPunkNoLongerForSaleEvent = 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/helpers/utils.ts b/tests/helpers/utils.ts index 3d5608a..fff3d48 100644 --- a/tests/helpers/utils.ts +++ b/tests/helpers/utils.ts @@ -22,7 +22,7 @@ export default class Utils { return BigInt.zero() } - static seedEntity(): void { + static seedBounty(): void { let entity = new Entity() entity.setBytes('id', Utils.id_BYTES)