Skip to content

Commit 549ef40

Browse files
committed
chore: add wip, refactor test utils
1 parent b4236ce commit 549ef40

File tree

5 files changed

+88
-57
lines changed

5 files changed

+88
-57
lines changed

packages/solidity-contracts/test/messagesOutgoingV2.test.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import chai from 'chai';
33
import type { Provider } from 'ethers';
44
import {
55
MaxUint256,
6+
Wallet,
67
hexlify,
78
parseEther,
89
randomBytes,
@@ -11,11 +12,14 @@ import {
1112
import { deployments, ethers, upgrades } from 'hardhat';
1213

1314
import { randomBytes32 } from '../protocol/utils';
14-
import type { FuelChainState, FuelMessagePortalV2 } from '../typechain';
15+
import {
16+
FuelMessagePortalV2__factory,
17+
type FuelChainState,
18+
type FuelMessagePortalV2,
19+
FuelChainState__factory,
20+
} from '../typechain';
1521
import type { MessageTester } from '../typechain/MessageTester';
1622

17-
import {} from '@openzeppelin/hardhat-upgrades';
18-
1923
import { addressToB256 } from './utils/addressConversion';
2024

2125
const { expect } = chai;
@@ -79,6 +83,11 @@ describe('FuelMessagesPortalV2 - Outgoing messages', async () => {
7983
await fuelMessagePortalDeployment.getAddress()
8084
).connect(fuelMessagePortalDeployment.runner) as FuelMessagePortalV2;
8185

86+
const wallet = Wallet.createRandom().connect(deployer.provider);
87+
FuelChainState__factory.connect(
88+
await fuelMessagePortal.getAddress(),
89+
wallet
90+
);
8291
const messageTester = (await ethers
8392
.getContractFactory('MessageTester', deployer)
8493
.then(async (factory) =>

packages/test-utils/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
},
1818
"peerDependencies": {
1919
"fuels": "0.71.1",
20-
"ethers": ">=5.7.2"
20+
"ethers": "6.11.0"
2121
},
2222
"devDependencies": {
2323
"@fuel-bridge/fungible-token": "workspace:*",
2424
"@fuel-bridge/message-predicates": "workspace:*",
2525
"@fuel-bridge/solidity-contracts": "workspace:*",
26-
"@ethersproject/abi": "^5.7.0",
27-
"@ethersproject/bytes": "^5.7.0",
28-
"@ethersproject/providers": "^5.7.0",
2926
"dotenv": "^16.0.3",
3027
"typescript": "^5.1.6"
3128
}

packages/test-utils/src/utils/ethers/getOrDeployERC721Contract.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ export async function getOrDeployERC721Contract(env: TestEnvironment) {
1313
if (!ethTestNft) {
1414
debug(`Creating ERC-721 token contract to test with...`);
1515
const eth_tokenFactory = new NFT__factory(ethDeployer);
16-
ethTestNft = await eth_tokenFactory.deploy();
17-
await ethTestNft.deployed();
16+
ethTestNft = await eth_tokenFactory
17+
.deploy()
18+
.then((tx) => tx.waitForDeployment());
19+
1820
debug(
19-
`Ethereum ERC-721 token contract created at address ${ethTestNft.address}.`
21+
`Ethereum ERC-721 token contract created at address ${await ethTestNft.getAddress()}.`
2022
);
2123
}
2224
ethTestNft = ethTestNft.connect(ethAcct);
23-
const ethTestTokenAddress = ethTestNft.address;
2425
debug(
25-
`Testing with Ethereum ERC-721 token contract at ${ethTestTokenAddress}.`
26+
`Testing with Ethereum ERC-721 token contract at ${await ethTestNft.getAddress()}.`
2627
);
2728

2829
return ethTestNft;

packages/test-utils/src/utils/setup.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// @dev The Fuel testing setup.
22
/// A set of useful helper methods for setting up the integration test environment.
3-
import type { Provider as EthProvider } from '@ethersproject/providers';
43
import type {
54
FuelChainState,
65
FuelMessagePortal,
@@ -14,8 +13,8 @@ import {
1413
FuelERC721Gateway__factory,
1514
} from '@fuel-bridge/solidity-contracts/typechain';
1615
import * as dotenv from 'dotenv';
17-
import type { Wallet as EthSigner } from 'ethers';
18-
import { ethers } from 'ethers';
16+
import type { Signer as EthSigner, Provider as EthProvider } from 'ethers';
17+
import { JsonRpcProvider, ethers, formatEther, parseEther } from 'ethers';
1918
import type { WalletUnlocked as FuelWallet } from 'fuels';
2019
import { Wallet, Provider as FuelProvider } from 'fuels';
2120

@@ -148,9 +147,8 @@ export async function setupEnvironment(
148147
}
149148

150149
// Create provider and signers from http_ethereum_client
151-
const eth_provider = new ethers.providers.JsonRpcProvider(
152-
http_ethereum_client
153-
);
150+
const eth_provider = new JsonRpcProvider(http_ethereum_client);
151+
154152
try {
155153
await eth_provider.getBlockNumber();
156154
} catch (e) {
@@ -161,29 +159,29 @@ export async function setupEnvironment(
161159
);
162160
}
163161
const eth_deployer = new ethers.Wallet(pk_eth_deployer, eth_provider);
164-
const eth_deployerBalance = await eth_deployer.getBalance();
165-
if (eth_deployerBalance.lt(ethers.utils.parseEther('5'))) {
162+
const eth_deployerBalance = await eth_provider.getBalance(eth_deployer);
163+
if (eth_deployerBalance < parseEther('5')) {
166164
throw new Error(
167165
'Ethereum deployer balance is very low (' +
168-
ethers.utils.formatEther(eth_deployerBalance) +
166+
formatEther(eth_deployerBalance) +
169167
'ETH)'
170168
);
171169
}
172170
const eth_signer1 = new ethers.Wallet(pk_eth_signer1, eth_provider);
173-
const eth_signer1Balance = await eth_signer1.getBalance();
174-
if (eth_signer1Balance.lt(ethers.utils.parseEther('1'))) {
171+
const eth_signer1Balance = await eth_provider.getBalance(eth_signer1);
172+
if (eth_signer1Balance < parseEther('1')) {
175173
const tx = await eth_deployer.sendTransaction({
176174
to: await eth_signer1.getAddress(),
177-
value: ethers.utils.parseEther('1'),
175+
value: parseEther('1'),
178176
});
179177
await tx.wait();
180178
}
181179
const eth_signer2 = new ethers.Wallet(pk_eth_signer2, eth_provider);
182-
const eth_signer2Balance = await eth_signer2.getBalance();
183-
if (eth_signer2Balance.lt(ethers.utils.parseEther('1'))) {
180+
const eth_signer2Balance = await eth_provider.getBalance(eth_signer2);
181+
if (eth_signer2Balance < parseEther('1')) {
184182
const tx = await eth_deployer.sendTransaction({
185183
to: await eth_signer2.getAddress(),
186-
value: ethers.utils.parseEther('1'),
184+
value: parseEther('1'),
187185
});
188186
await tx.wait();
189187
}
@@ -245,6 +243,7 @@ export async function setupEnvironment(
245243
}
246244

247245
// Connect existing contracts
246+
248247
const eth_fuelChainState: FuelChainState = FuelChainState__factory.connect(
249248
eth_fuelChainStateAddress,
250249
eth_deployer

0 commit comments

Comments
 (0)