-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1ccc25
commit 54f5938
Showing
3 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |