Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjerryokolo committed Sep 8, 2022
1 parent 54f5938 commit 40e5a23
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
57 changes: 57 additions & 0 deletions tests/handlePunkNoLongerForSale.test.ts
Original file line number Diff line number Diff line change
@@ -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<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
}
2 changes: 1 addition & 1 deletion tests/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 40e5a23

Please sign in to comment.