Skip to content

Commit 365fadc

Browse files
committed
Migrate tools.js file to Hardhat and Typescript to remove web3 references.
1 parent 23c5afb commit 365fadc

File tree

4 files changed

+36
-65
lines changed

4 files changed

+36
-65
lines changed

test/utils/IexecWrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
WorkerpoolRegistry__factory,
2626
Workerpool__factory,
2727
} from '../../typechain';
28-
import { IexecPoco1__factory } from '../../typechain/factories/contracts/modules/interfaces/IexecPoco1.v8.sol';
28+
import { IexecPoco1__factory } from '../../typechain/factories/contracts/modules/interfaces/IexecPoco1.v8.sol/IexecPoco1__factory';
2929
import {
3030
IexecOrders,
3131
OrderOperation,

utils/tools.d.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

utils/tools.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

utils/tools.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <[email protected]>
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { assert } from 'chai';
5+
import type { BigNumber } from 'ethers';
6+
import { ethers } from 'hardhat';
7+
8+
import { ContractReceipt, Event } from '@ethersproject/contracts';
9+
10+
export function extractEventsFromReceipt(
11+
txReceipt: ContractReceipt,
12+
address: string,
13+
name: string,
14+
): Event[] {
15+
const receiptEvents = txReceipt?.events || [];
16+
const events = receiptEvents.filter((event) => {
17+
return event.address == address && event.event == name;
18+
});
19+
assert.isNotEmpty(events, `Fail to extract '${name}' event`);
20+
return events;
21+
}
22+
23+
export function compactSignature(signature: string): string {
24+
const split = ethers.utils.splitSignature(signature);
25+
let vs = ethers.utils.arrayify(split.s);
26+
if (split.v == 1 || split.v == 28) {
27+
vs[0] |= 0x80;
28+
}
29+
return ethers.utils.hexlify(ethers.utils.concat([split.r, vs]));
30+
}
31+
32+
export function BN2Address(bignumber: BigNumber) {
33+
const lowercaseAddress = ethers.utils.hexZeroPad(bignumber.toHexString(), 20);
34+
return ethers.utils.getAddress(lowercaseAddress);
35+
}

0 commit comments

Comments
 (0)