-
Notifications
You must be signed in to change notification settings - Fork 14
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
Migrate IexecAccessors tests to ethers v6 #189
Migrate IexecAccessors tests to ethers v6 #189
Conversation
|
||
const task = await iexecPoco.viewTask(taskId); | ||
expect(task.status).to.equal(TaskStatusEnum.ACTIVE); | ||
expect(task.dealid).to.equal(dealId); | ||
expect(task.idx).to.equal(taskIndex); | ||
expect(task.timeref).to.equal(timeRef); |
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 remove that ?
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.
Good catch, some old testing, updated with Re-add timeref check, thanks 👍
return ethers.utils._TypedDataEncoder.hashDomain({ | ||
//TODO: Move to utils | ||
export async function hashDomain(domain: IexecLibOrders_v5.EIP712DomainStructOutput) { | ||
return ethers.TypedDataEncoder.hashDomain({ |
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.
return ethers.TypedDataEncoder.hashDomain({ | |
return TypedDataEncoder.hashDomain({ |
other option: directly import TypedDataEncoder
module
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.
Sure see Import from ethers (same comment everywhere)
function extractEvents( | ||
logs: Log[], | ||
address: string, | ||
eventName: string, | ||
eventAbi: string[], | ||
): LogDescription[] { | ||
const eventInterface = new ethers.Interface(eventAbi); | ||
const event = eventInterface.getEvent(eventName); | ||
if (!event) { | ||
throw new Error('Event name and abi mismatch'); | ||
} | ||
return ''; | ||
const eventId = event.topicHash; | ||
let extractedEvents = logs | ||
// Get logs of the target contract. | ||
.filter((log) => log.address === address && log.topics.includes(eventId)) | ||
// Parse logs to events. | ||
.map((log) => eventInterface.parseLog(log)) | ||
// Get events with the target name. | ||
.filter((event) => event && event.name === eventName); | ||
// Get only non null elements. | ||
// Note: using .filter(...) returns (LogDescription | null)[] | ||
// which is not desired. | ||
const events: LogDescription[] = []; | ||
extractedEvents.forEach((element) => element && events.push(element)); | ||
return events; |
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.
An other way to do that, that we use in SDK
export const getEventFromLogs = ({ contract, eventName, logs }) => {
const filter = contract.getEvent(eventName);
if (!filter) {
throw new Error(`Event filter not found for ${eventName}`);
}
const eventTopic = filter.fragment.topicHash;
// Find the event in the logs based on the topic
const eventFound = logs.find((log) => log.topics[0] === eventTopic);
if (!eventFound) {
throw new Error(`Event ${eventName} not found in logs`);
}
// Check if the event is already decoded
if (eventFound.args) {
return eventFound;
}
// If not decoded, decode the event
try {
return {
...eventFound,
args: contract.interface.decodeEventLog(
filter.fragment,
eventFound.data,
eventFound.topics
),
};
} catch (error) {
throw new Error(`Failed to decode event ${eventName}: ${error.message}`);
}
};
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.
In fact log.topics.includes(eventId)
could be replace by log.topics[0] === eventTopic
. Indeed this is the first element of the topic that correspond to the event signature.
Other improvements could be considered, such as removing the need to use the address
.
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.
Co-authored-by: Zied Guesmi <[email protected]>
See job logs on
Run test
step ✔️ :