-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UT for VoucherTypeCreated event #22
base: develop
Are you sure you want to change the base?
Conversation
@@ -191,9 +191,9 @@ export function handleVoucherTypeCreated(event: VoucherTypeCreated): void { | |||
if (!voucherType) { | |||
voucherType = new VoucherType(id); | |||
voucherType.eligibleAssets = []; | |||
voucherType.description = description; | |||
voucherType.duration = duration; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
test('Should create a new VoucherType entity when an event is emitted', () => { | ||
// Prepare mock event data | ||
let id = BigInt.fromI32(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add logic in subgraph sources which checks that:
id == voucherEntities.count()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be an idea
I'm looking on how to do it
But now I'm thinking on how does the subgraph index this ? if it goes from latest block to first block => type 2 is created before type 1 etc. So count won't work (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo it's chronological (from 0 or start block). From a random non official blog post
The Graph Node will identify the data sources, startBlock from which the data source starts indexing, the contract address, and the events or calls to match. Next, Graph Node will start from the oldest start block (0 if no data source has a startBlock set) and go block by block trying to match any data source specified
I didn't check the official doc though :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some reflexion I have made this
If it's not good for you I can remove this
let description = 'Test Voucher'; | ||
let duration = BigInt.fromI32(30); | ||
let eventType1 = createVoucherTypeCreatedEvent(id, description, duration); | ||
handleVoucherTypeCreated(eventType1); | ||
|
||
let descriptionType2 = 'Test Voucher number 2'; | ||
let durationType2 = BigInt.fromI32(150); | ||
let event = createVoucherTypeCreatedEvent(id, descriptionType2, durationType2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe harmonize: description1, duration1, event1 & description2, duration2, event2
tests/unit/utils/utils.ts
Outdated
event.parameters.push(new ethereum.EventParam('id', ethereum.Value.fromUnsignedBigInt(id))); | ||
event.parameters.push( | ||
new ethereum.EventParam('description', ethereum.Value.fromString(description)), | ||
); | ||
event.parameters.push( | ||
new ethereum.EventParam('duration', ethereum.Value.fromUnsignedBigInt(duration)), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's time we define a function setEventParams()
and use it everywhere to avoid repeating code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking deep into it => updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, well done.
} | ||
|
||
export class EventParamBuilder { | ||
private params: EventParam[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not:
private params: EventParam[] = []; | |
private params: ethereum.EventParam[] = new Array<ethereum.EventParam>(); |
build(event: ethereum.Event): void { | ||
event.parameters = new Array<ethereum.EventParam>(); | ||
for (let i = 0; i < this.params.length; i++) { | ||
event.parameters.push( | ||
new ethereum.EventParam(this.params[i].key, this.params[i].value), | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build(event: ethereum.Event): void { | |
event.parameters = new Array<ethereum.EventParam>(); | |
for (let i = 0; i < this.params.length; i++) { | |
event.parameters.push( | |
new ethereum.EventParam(this.params[i].key, this.params[i].value), | |
); | |
} | |
} | |
build(): ethereum.EventParam[] { | |
return this.params; | |
} |
EventParamBuilder.init() | ||
.address('voucher', voucher) | ||
.address('owner', owner) | ||
.bigInt('voucherType', voucherType) | ||
.bigInt('expiration', expiration) | ||
.bigInt('value', value) | ||
.build(event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventParamBuilder.init() | |
.address('voucher', voucher) | |
.address('owner', owner) | |
.bigInt('voucherType', voucherType) | |
.bigInt('expiration', expiration) | |
.bigInt('value', value) | |
.build(event); | |
event.parameters = EventParamBuilder.init() | |
.address('voucher', voucher) | |
.address('owner', owner) | |
.bigInt('voucherType', voucherType) | |
.bigInt('expiration', expiration) | |
.bigInt('value', value) | |
.build(); |
No description provided.