Skip to content

Migrate IexecAccessors tests to ethers v6 - #189

Merged
james-toussaint merged 7 commits into
feature/migration-to-ether-v6from
feature/ethers-v6-tests-accessors
Feb 14, 2025
Merged

Migrate IexecAccessors tests to ethers v6#189
james-toussaint merged 7 commits into
feature/migration-to-ether-v6from
feature/ethers-v6-tests-accessors

Conversation

@james-toussaint

Copy link
Copy Markdown
Contributor

See job logs on Run test step ✔️ :

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

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
Copy Markdown
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
Copy Markdown
Contributor 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 👍

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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)

Comment thread utils/odb-tools.ts Outdated
Comment thread utils/createOrders.ts Outdated
Comment thread test/utils/IexecWrapper.ts
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;

@Le-Caignec Le-Caignec Feb 13, 2025

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread test/byContract/IexecAccessors/IexecAccessors.test.ts
Comment thread test/byContract/IexecAccessors/IexecAccessorsABILegacy.test.ts Outdated
Comment thread test/byContract/IexecMaintenance/IexecMaintenance.test.ts Outdated
Comment thread test/utils/IexecWrapper.ts Outdated
Comment thread test/utils/IexecWrapper.ts Outdated
Comment thread utils/createOrders.ts
Comment thread utils/poco-tools.ts Outdated
Base automatically changed from feature/hardhat-and-ethers-upgrade-part1 to feature/migration-to-ether-v6 February 13, 2025 16:58
@james-toussaint
james-toussaint merged commit 106e67f into feature/migration-to-ether-v6 Feb 14, 2025
@james-toussaint
james-toussaint 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