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

Bump outdated evm_js_tests modules. #2018

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions evm_scilla_js_tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
artifacts/
cache/
typechain-types/
dist/
41 changes: 0 additions & 41 deletions evm_scilla_js_tests/AddConfigHelpersToHre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {extendEnvironment} from "hardhat/config";
import {HardhatRuntimeEnvironment} from "hardhat/types/runtime";
import SingerPool from "./helpers/parallel-tests/SignerPool";
import {Contract, ethers, Signer, Wallet} from "ethers";
import {Contract as Web3Contract} from "web3-eth-contract";
import {JsonRpcProvider, TransactionRequest, TransactionResponse} from "@ethersproject/providers";
import BN from "bn.js";
import {ScillaContract, Setup} from "hardhat-scilla-plugin";
import {Account} from "@zilliqa-js/zilliqa";

Expand Down Expand Up @@ -37,11 +35,6 @@ declare module "hardhat/types/runtime" {
deployScillaContractWithSigner: (name: string, signer: Account, ...args: any[]) => Promise<ScillaContract>;
deployContract: (name: string, ...args: any[]) => Promise<Contract>;
deployContractWithSigner: (name: string, signer: Signer, ...args: any[]) => Promise<Contract>;
deployContractWeb3: (
contractName: string,
options: {gasPrice?: string; gasLimit?: number; value?: BN},
...args: any[]
) => Promise<Web3Contract>;
}
}

Expand Down Expand Up @@ -163,38 +156,4 @@ extendEnvironment((hre: HardhatRuntimeEnvironment) => {
const factory = await hre.ethers.getContractFactory(name);
return (await factory.connect(signer).deploy(...args)).deployed();
};

// TODO: remove any type from `options`
hre.deployContractWeb3 = async (
contractName: string,
options: {gasPrice?: string; gasLimit?: number; value?: BN},
...args: any[]
): Promise<Web3Contract> => {
const signer = await hre.getEthSignerForContractDeployment();

const contractRaw = hre.artifacts.readArtifactSync(contractName);
const contract = new hre.web3.eth.Contract(contractRaw.abi);
const gasPrice = options.gasPrice || (await hre.web3.eth.getGasPrice());
const value = options.value || 0;

const signerAddress = await signer.getAddress();

const estimatedGas = await contract.deploy({data: contractRaw.bytecode, arguments: args}).estimateGas({
from: signerAddress,
value
});

const gasLimit = options.gasLimit || estimatedGas;

const deployedContract = await contract.deploy({data: contractRaw.bytecode, arguments: args}).send({
from: signerAddress,
gas: gasLimit,
gasPrice,
value
});

deployedContract.options.from = signerAddress;
deployedContract.options.gas = gasLimit;
return deployedContract;
};
});
25 changes: 15 additions & 10 deletions evm_scilla_js_tests/contracts/Precompiles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pragma solidity ^0.8.9;
contract Precompiles {
bytes public idStored;
uint256 public modExpResult;
uint256 public pairingResult;
uint256[2] public ecAddResult;
uint256[2] public ecMulResult;
bytes32[2] public blake2Result;

constructor() {}

Expand Down Expand Up @@ -56,33 +60,38 @@ contract Precompiles {
}
}

function testEcAdd(uint256 a_x, uint256 a_y, uint256 b_x, uint256 b_y) public returns (uint256[2] memory p) {
function testEcAdd(uint256 a_x, uint256 a_y, uint256 b_x, uint256 b_y) public {
uint256[4] memory input;
input[0] = a_x;
input[1] = a_y;
input[2] = b_x;
input[3] = b_y;
uint256[2] memory p;
assembly {
// input size = (256 / 8) * 4 = 0x80
// output size = (256 / 8) * 2 = 0x40
if iszero(call(gas(), 0x06, 0, input, 0x80, p, 0x40)) {
revert(0, 0)
}
}

ecAddResult = p;
}

function testEcMul(uint256 p_x, uint256 p_y, uint256 s) public returns (uint256[2] memory p) {
function testEcMul(uint256 p_x, uint256 p_y, uint256 s) public {
uint256[3] memory input;
input[0] = p_x;
input[1] = p_y;
input[2] = s;
uint256[2] memory p;
assembly {
// input size = (256 / 8) * 3 = 0x60
// output size = (256 / 8) * 2 = 0x40
if iszero(call(gas(), 0x07, 0, input, 0x60, p, 0x40)) {
revert(0, 0)
}
}
ecMulResult = p;
}

function testEcPairing(uint256[] memory pairs) public returns (uint256) {
Expand All @@ -94,16 +103,12 @@ contract Precompiles {
revert(0, 0)
}
}

pairingResult = pairs[0];
return pairs[0];
}

function testBlake2(
uint32 rounds,
bytes32[2] memory h,
bytes32[4] memory m,
bytes8[2] memory t,
bool f
) public returns (bytes32[2] memory) {
function testBlake2(uint32 rounds, bytes32[2] memory h, bytes32[4] memory m, bytes8[2] memory t, bool f) public {
bytes32[2] memory output;

bytes memory args = abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f);
Expand All @@ -114,6 +119,6 @@ contract Precompiles {
}
}

return output;
blake2Result = output;
}
}
20 changes: 0 additions & 20 deletions evm_scilla_js_tests/contracts/openzeppelin/Ownable.sol

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions evm_scilla_js_tests/contracts/openzeppelin/tokens/ERC20.sol

This file was deleted.

2 changes: 0 additions & 2 deletions evm_scilla_js_tests/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "@nomicfoundation/hardhat-toolbox";
import "@nomiclabs/hardhat-web3";
import {HardhatUserConfig} from "hardhat/types";
import "dotenv/config";
import {ENV_VARS} from "./helpers/EnvVarParser";
Expand Down Expand Up @@ -52,7 +51,6 @@ const config: HardhatUserConfig = {
protocolVersion: 0x41,
miningState: false
},

prototestnet: {
url: "https://api.zq2-prototestnet.zilliqa.com",
websocketUrl: "ws://api.zq2-prototestnet.zilliqa.com",
Expand Down
12 changes: 2 additions & 10 deletions evm_scilla_js_tests/helpers/Parallelizer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {getAddressFromPrivateKey} from "@zilliqa-js/crypto";
import BN from "bn.js";
import hre, {ethers as hh_ethers, web3} from "hardhat";
import hre from "hardhat";
import {initZilliqa, ScillaContract, Setup, UserDefinedLibrary} from "hardhat-scilla-plugin";
import {} from "hardhat-scilla-plugin/dist/src/index";

export type DeployOptions = {
gasPrice?: string;
gasLimit?: number;
value?: BN;
};

export class Parallelizer {
constructor() {
const private_keys: string[] = hre.network["config"]["accounts"] as string[];
Expand All @@ -22,7 +14,7 @@ export class Parallelizer {
}

async deployScillaLibrary(libraryName: string): Promise<ScillaContract> {
return hre.deployScillaLibrary(libraryName);
return hre.deployScillaLibrary(libraryName, false);
}

async deployScillaContractWithLibrary(
Expand Down
2 changes: 1 addition & 1 deletion evm_scilla_js_tests/helpers/parallel-tests/SignerPool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {JsonRpcProvider} from "@ethersproject/providers";
import {Account} from "@zilliqa-js/account";
import {Account} from "@zilliqa-js/zilliqa";
import {Wallet} from "ethers";
import {HardhatRuntimeEnvironment} from "hardhat/types";

Expand Down
4 changes: 1 addition & 3 deletions evm_scilla_js_tests/helpers/perf/Account.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {BN, bytes, getAddressFromPrivateKey, units, Zilliqa} from "@zilliqa-js/zilliqa";
import {BN, bytes, getAddressFromPrivateKey, units, Zilliqa, Long} from "@zilliqa-js/zilliqa";
import {ethers} from "ethers";
import Long from "long";

export interface Account {
privateKey: string;
ethAddress: string;
Expand Down
Loading
Loading