From 7571a91bedf9d3c2d6e0d7691f5d47d1343f98c9 Mon Sep 17 00:00:00 2001 From: Denis Date: Sat, 14 Oct 2023 18:43:41 +0300 Subject: [PATCH 1/3] Add method for deploy contract from bytecode --- package.json | 2 +- src/utils.ts | 10 +++++++++- test/utils.test.ts | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f0f0da7b..7cec9d6c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@1inch/solidity-utils", - "version": "3.1.0", + "version": "3.2.0", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", "repository": { diff --git a/src/utils.ts b/src/utils.ts index 9040c7da..59d2b576 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import '@nomicfoundation/hardhat-ethers'; // required to populate the HardhatRuntimeEnvironment with ethers import hre, { ethers } from 'hardhat'; import { time } from '@nomicfoundation/hardhat-network-helpers'; -import { BaseContract, BigNumberish, Contract, ContractTransactionReceipt, ContractTransactionResponse, JsonRpcProvider, Wallet } from 'ethers'; +import { BaseContract, BigNumberish, BytesLike, Contract, ContractTransactionReceipt, ContractTransactionResponse, JsonRpcProvider, Signer, Wallet } from 'ethers'; import { DeployOptions, DeployResult } from 'hardhat-deploy/types'; import { constants } from './prelude'; @@ -81,6 +81,14 @@ export async function deployContract(name: string, parameters: Array = [], signer?: Signer) : Promise { + const ContractFactory = await ethers.getContractFactory(abi, bytecode, signer); + const instance = await ContractFactory.deploy(...parameters); + await instance.waitForDeployment(); + return instance; +} + type Token = { balanceOf: (address: string) => Promise; getAddress: () => Promise; diff --git a/test/utils.test.ts b/test/utils.test.ts index ad752e99..0785015e 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -1,5 +1,5 @@ import { expect, ether, time, constants } from '../src/prelude'; -import { timeIncreaseTo, fixSignature, signMessage, trackReceivedTokenAndTx, countInstructions, deployContract, deployAndGetContract } from '../src/utils'; +import { timeIncreaseTo, fixSignature, signMessage, trackReceivedTokenAndTx, countInstructions, deployContract, deployAndGetContract, deployContractFromBytecode } from '../src/utils'; import hre, { deployments, ethers } from 'hardhat'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; @@ -182,6 +182,22 @@ describe('utils', function () { }); }); + describe('deployContractFromBytecode', function () { + it('should be deploy new contract instance', async function () { + const contractArtifact = await hre.artifacts.readArtifact('TokenMock'); + const token = await deployContractFromBytecode(contractArtifact.abi, contractArtifact.bytecode, ['SomeToken', 'STM']); + expect(await token.getAddress()).to.be.not.eq(constants.ZERO_ADDRESS); + expect(await token.name()).to.be.eq('SomeToken'); + }); + + it('should be using without arguments', async function () { + const contractArtifact = await hre.artifacts.readArtifact('WETH'); + const weth = await deployContractFromBytecode(contractArtifact.abi, contractArtifact.bytecode); + expect(await weth.getAddress()).to.be.not.eq(constants.ZERO_ADDRESS); + expect(await weth.name()).to.be.eq('Wrapped Ether'); + }); + }); + describe('deployAndGetContract', function () { it('should deploy new contract instance', async function () { const tokenName = 'SomeToken'; From 4cd8478f5dd6d10c718be3be3af539a5ccaeecaa Mon Sep 17 00:00:00 2001 From: zZoMROT Date: Tue, 17 Oct 2023 20:36:12 +0300 Subject: [PATCH 2/3] Update test/utils.test.ts Co-authored-by: Xenia <94478708+byshape@users.noreply.github.com> --- test/utils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils.test.ts b/test/utils.test.ts index 0785015e..23e4c482 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -183,7 +183,7 @@ describe('utils', function () { }); describe('deployContractFromBytecode', function () { - it('should be deploy new contract instance', async function () { + it('should deploy new contract instance', async function () { const contractArtifact = await hre.artifacts.readArtifact('TokenMock'); const token = await deployContractFromBytecode(contractArtifact.abi, contractArtifact.bytecode, ['SomeToken', 'STM']); expect(await token.getAddress()).to.be.not.eq(constants.ZERO_ADDRESS); From c2d25af9a40d701f047ed9a0bfe222d43a2d5aa0 Mon Sep 17 00:00:00 2001 From: zZoMROT Date: Tue, 17 Oct 2023 20:36:19 +0300 Subject: [PATCH 3/3] Update test/utils.test.ts Co-authored-by: Xenia <94478708+byshape@users.noreply.github.com> --- test/utils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils.test.ts b/test/utils.test.ts index 23e4c482..0e56dad9 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -190,7 +190,7 @@ describe('utils', function () { expect(await token.name()).to.be.eq('SomeToken'); }); - it('should be using without arguments', async function () { + it('can be used without arguments', async function () { const contractArtifact = await hre.artifacts.readArtifact('WETH'); const weth = await deployContractFromBytecode(contractArtifact.abi, contractArtifact.bytecode); expect(await weth.getAddress()).to.be.not.eq(constants.ZERO_ADDRESS);