Skip to content

Commit

Permalink
test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjerryokolo committed Sep 6, 2022
1 parent e1ccc25 commit 54f5938
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
54 changes: 54 additions & 0 deletions tests/handleAssign.test.ts
Original file line number Diff line number Diff line change
@@ -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<Assign>(newMockEvent())

let parameters: Array<ethereum.EventParam> = [
new ethereum.EventParam('bountyId', ethereum.Value.fromString(bountyId)),
new ethereum.EventParam(
'bountyAddress',
ethereum.Value.fromAddress(Address.fromString(bountyAddress))
),
]

newAssignEvent.parameters = parameters

return newAssignEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ///
Expand Down
34 changes: 34 additions & 0 deletions tests/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 54f5938

Please sign in to comment.