Skip to content
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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

gfournieriExec
Copy link
Contributor

No description provided.

@@ -191,9 +191,9 @@ export function handleVoucherTypeCreated(event: VoucherTypeCreated): void {
if (!voucherType) {
voucherType = new VoucherType(id);
voucherType.eligibleAssets = [];
voucherType.description = description;
voucherType.duration = duration;
Copy link
Member

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);
Copy link
Member

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()
?

Copy link
Contributor Author

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 (?)

Copy link
Member

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 :)

Copy link
Contributor Author

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

Comment on lines 32 to 39
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);
Copy link
Member

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

Comment on lines 87 to 93
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)),
);
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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[] = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not:

Suggested change
private params: EventParam[] = [];
private params: ethereum.EventParam[] = new Array<ethereum.EventParam>();

Comment on lines +37 to +44
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),
);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}

Comment on lines +39 to +45
EventParamBuilder.init()
.address('voucher', voucher)
.address('owner', owner)
.bigInt('voucherType', voucherType)
.bigInt('expiration', expiration)
.bigInt('value', value)
.build(event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants