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

Migrate IexecAccessors tests to ethers v6 #189

Merged

Conversation

jeremyjams
Copy link
Member

See job logs on Run test step ✔️ :

npm run test test/byContract/IexecAccessors/**
[...]
  54 passing (5s)


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

Choose a reason for hiding this comment

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

why remove that ?

Copy link
Member Author

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 👍

test/utils/IexecWrapper.ts Show resolved Hide resolved
return ethers.utils._TypedDataEncoder.hashDomain({
//TODO: Move to utils
export async function hashDomain(domain: IexecLibOrders_v5.EIP712DomainStructOutput) {
return ethers.TypedDataEncoder.hashDomain({

Choose a reason for hiding this comment

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

Suggested change
return ethers.TypedDataEncoder.hashDomain({
return TypedDataEncoder.hashDomain({

other option: directly import TypedDataEncoder module

Copy link
Member Author

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)

utils/odb-tools.ts Outdated Show resolved Hide resolved
utils/createOrders.ts Outdated Show resolved Hide resolved
test/utils/IexecWrapper.ts Show resolved Hide resolved
Comment on lines +571 to +595
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;
Copy link

@Le-Caignec Le-Caignec Feb 13, 2025

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}`);
  }
};

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

test/byContract/IexecMaintenance/IexecMaintenance.test.ts Outdated Show resolved Hide resolved
test/utils/IexecWrapper.ts Outdated Show resolved Hide resolved
test/utils/IexecWrapper.ts Outdated Show resolved Hide resolved
utils/createOrders.ts Show resolved Hide resolved
utils/poco-tools.ts Outdated Show resolved Hide resolved
Base automatically changed from feature/hardhat-and-ethers-upgrade-part1 to feature/migration-to-ether-v6 February 13, 2025 16:58
@jeremyjams jeremyjams merged commit 106e67f into feature/migration-to-ether-v6 Feb 14, 2025
1 check failed
@jeremyjams jeremyjams deleted the feature/ethers-v6-tests-accessors branch February 14, 2025 09:35
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.

4 participants