Skip to content

Commit

Permalink
Remove web3js from server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzdogan committed Jun 30, 2023
1 parent 6bdb368 commit 706e6d9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 96 deletions.
2 changes: 1 addition & 1 deletion packages/lib-sourcify/src/lib/CheckedContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export async function performFetch(
hash?: string,
fileName?: string
): Promise<string | null> {
console.log(`Fetching the file ${fileName} from ${url}...`);
console.log(`Fetching the file ${fileName} from ${url}`);
const res = await fetchWithTimeout(url, { timeout: FETCH_TIMEOUT }).catch(
(err) => {
if (err.type === 'aborted')
Expand Down
1 change: 0 additions & 1 deletion test/chains/deployContracts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { deployFromPrivateKey } = require("../helpers/helpers");
const Web3 = require("web3");
const StorageArtifact = require("./sources/shared/1_Storage.json");
const { supportedChainsArray } = require("../../dist/sourcify-chains");
const { program } = require("commander");
Expand Down
18 changes: 7 additions & 11 deletions test/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const unsupportedChain = "3"; // Ropsten

async function deployFromAbiAndBytecode(signer, abi, bytecode, args) {
const contractFactory = new ContractFactory(abi, bytecode, signer);
console.log(`Deploying contract ${args?.length ? `with args ${args}` : ""}}`);
console.log(`Deploying contract ${args?.length ? `with args ${args}` : ""}`);
const deployment = await contractFactory.deploy(...(args || []));
await deployment.waitForDeployment();

Expand All @@ -28,7 +28,6 @@ async function deployFromAbiAndBytecode(signer, abi, bytecode, args) {
/**
* Creator tx hash is needed for tests. This function returns the tx hash in addition to the contract address.
*
* @returns The contract address and the tx hash
*/
async function deployFromAbiAndBytecodeForCreatorTxHash(
signer,
Expand All @@ -37,16 +36,14 @@ async function deployFromAbiAndBytecodeForCreatorTxHash(
args
) {
const contractFactory = new ContractFactory(abi, bytecode, signer);
console.log(`Deploying contract ${args?.length ? `with args ${args}` : ""}}`);
console.log(`Deploying contract ${args?.length ? `with args ${args}` : ""}`);
const deployment = await contractFactory.deploy(...(args || []));
await deployment.waitForDeployment();

const contractAddress = await deployment.getAddress();
const creationTx = deployment.deploymentTransaction();
if (!creationTx) {
throw new Error(
`No deployment transaction found for ${contractAddress} in contract folder ${contractFolderPath}`
);
throw new Error(`No deployment transaction found for ${contractAddress}`);
}
console.log(
`Deployed contract at ${contractAddress} with tx ${creationTx.hash}`
Expand All @@ -60,7 +57,7 @@ async function deployFromAbiAndBytecodeForCreatorTxHash(
async function deployFromPrivateKey(provider, abi, bytecode, privateKey, args) {
const signer = new Wallet(privateKey, provider);
const contractFactory = new ContractFactory(abi, bytecode, signer);
console.log(`Deploying contract ${args?.length ? `with args ${args}` : ""}}`);
console.log(`Deploying contract ${args?.length ? `with args ${args}` : ""}`);
const deployment = await contractFactory.deploy(...(args || []));
await deployment.waitForDeployment();

Expand Down Expand Up @@ -88,7 +85,7 @@ async function callContractMethod(
args
) {
const contract = new BaseContract(contractAddress, abi, provider);
const callResponse = await contract.interface[methodName].staticCall(...args);
const callResponse = await contract[methodName].staticCall(...args);

return callResponse;
}
Expand All @@ -99,12 +96,11 @@ async function callContractMethodWithTx(
abi,
contractAddress,
methodName,
from,
args
) {
const contract = new BaseContract(contractAddress, abi, signer);
const txReceipt = await contract.interface[methodName].send(...args);

const txResponse = await contract[methodName].send(...args);
const txReceipt = await txResponse.wait();
return txReceipt;
}

Expand Down
Loading

0 comments on commit 706e6d9

Please sign in to comment.