Skip to content

Commit

Permalink
Merge pull request 1inch#76 from 1inch/feature/using_native_coverage_…
Browse files Browse the repository at this point in the history
…env_variable
  • Loading branch information
ZumZoom authored Mar 17, 2023
2 parents 42615ef + 0e6270e commit 43ac5b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/solidity-utils",
"version": "2.2.21",
"version": "2.2.22",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"repository": {
Expand All @@ -12,7 +12,7 @@
"clean": "rimraf artifacts cache coverage contracts/hardhat-dependency-compiler dist typechain-types",
"build": "yarn typechain && cti src -b && tsc -p tsconfig.publish.json",
"prepack": "yarn clean && yarn build",
"coverage": "skip_on_coverage=true hardhat coverage",
"coverage": "hardhat coverage",
"format": "yarn format-ts && yarn format-sol",
"format-ts": "prettier '**/*.ts' --write",
"format-sol": "prettier '**/*.sol' --write",
Expand Down
5 changes: 3 additions & 2 deletions test/contracts/SafestERC20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { constants, ether, expect } from '../../src/prelude';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import { ethers } from 'hardhat';
import hre from 'hardhat';
import { Contract, ContractFactory } from 'ethers';
import { PERMIT2_ADDRESS } from '@uniswap/permit2-sdk';
import { splitSignature } from 'ethers/lib/utils';
Expand Down Expand Up @@ -259,7 +260,7 @@ describe('SafeERC20', function () {
wrapper.deposit({ value: ether('1') }),
);
expect(received).to.be.equal(ether('1'));
if (!process.env.skip_on_coverage) {
if (hre.__SOLIDITY_COVERAGE_RUNNING) {
expect(await countInstructions(ethers.provider, tx.events[0].transactionHash, ['STATICCALL', 'CALL', 'MSTORE', 'MLOAD', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 1, 6, 3, 1, 2,
]);
Expand All @@ -271,7 +272,7 @@ describe('SafeERC20', function () {
const [, tx] = await trackReceivedTokenAndTx(ethers.provider, weth, wrapper.address, () =>
wrapper.deposit(),
);
if (!process.env.skip_on_coverage) {
if (hre.__SOLIDITY_COVERAGE_RUNNING) {
expect(await countInstructions(ethers.provider, tx.transactionHash, ['STATICCALL', 'CALL', 'MSTORE', 'MLOAD', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 0, 1, 1, 0, 1,
]);
Expand Down
11 changes: 6 additions & 5 deletions test/profileEVM.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, ether } from '../src/prelude';
import { profileEVM, gasspectEVM } from '../src/profileEVM';
import { ethers } from 'hardhat';
import hre from 'hardhat';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';

Expand All @@ -25,7 +26,7 @@ describe('trace inspection', function () {
const { usdt } = await loadFixture(deployUSDT);

const txn = await usdt.transfer(signer2.address, ether('1'));
if (!process.env.skip_on_coverage) {
if (hre.__SOLIDITY_COVERAGE_RUNNING) {
expect(await profileEVM(ethers.provider, txn.hash, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 0, 2, 2,
]);
Expand All @@ -36,7 +37,7 @@ describe('trace inspection', function () {
const { usdt } = await loadFixture(deployUSDT);

const txn = await usdt.approve(signer2.address, ether('1'));
if (!process.env.skip_on_coverage) {
if (hre.__SOLIDITY_COVERAGE_RUNNING) {
expect(await profileEVM(ethers.provider, txn.hash, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 0, 1, 0,
]);
Expand All @@ -62,7 +63,7 @@ describe('trace inspection', function () {
const { usdt } = await loadFixture(deployUSDT);

const txn = await usdt.approve(signer2.address, ether('1'));
if (!process.env.skip_on_coverage) {
if (hre.__SOLIDITY_COVERAGE_RUNNING) {
expect(await gasspectEVM(ethers.provider, txn.hash)).to.be.deep.equal(['0-0-SSTORE_I = 22100', '0-0-LOG3 = 1756']);
}
});
Expand All @@ -83,7 +84,7 @@ describe('trace inspection', function () {
const { usdt } = await loadFixture(deployUSDT);

const txn = await usdt.transfer(signer2.address, ether('1'));
if (!process.env.skip_on_coverage) {
if (hre.__SOLIDITY_COVERAGE_RUNNING) {
expect(await gasspectEVM(ethers.provider, txn.hash, { args: true })).to.be.deep.equal([
'0-0-SLOAD(0x723077b8a1b173adc35e5f0e7e3662fd1208212cb629f9c128551ea7168da722) = 2100',
'0-0-SSTORE(0x723077b8a1b173adc35e5f0e7e3662fd1208212cb629f9c128551ea7168da722,0x00000000000000000000000000000000000000000000003627e8f712373c0000) = 2900',
Expand All @@ -98,7 +99,7 @@ describe('trace inspection', function () {
const { usdt } = await loadFixture(deployUSDT);

const txn = await usdt.transfer(signer2.address, ether('1'));
if (!process.env.skip_on_coverage) {
if (hre.__SOLIDITY_COVERAGE_RUNNING) {
expect(await gasspectEVM(ethers.provider, txn.hash, { res: true })).to.be.deep.equal([
'0-0-SLOAD:0x00000000000000000000000000000000000000000000003635c9adc5dea00000 = 2100',
'0-0-SSTORE = 2900',
Expand Down
5 changes: 3 additions & 2 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, ether, time } from '../src/prelude';
import { timeIncreaseTo, fixSignature, signMessage, trackReceivedTokenAndTx, countInstructions } from '../src/utils';
import { ethers } from 'hardhat';
import hre from 'hardhat';
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { arrayify, hexlify, toUtf8Bytes, randomBytes } from 'ethers/lib/utils';
Expand Down Expand Up @@ -146,7 +147,7 @@ describe('utils', function () {
const [, tx] = await trackReceivedTokenAndTx(ethers.provider, usdt, signer2.address, () =>
usdt.transfer(signer2.address, ether('1')),
);
if (!process.env.skip_on_coverage) {
if (hre.__SOLIDITY_COVERAGE_RUNNING) {
expect(await countInstructions(ethers.provider, tx.events[0].transactionHash, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 0, 2, 2,
]);
Expand All @@ -159,7 +160,7 @@ describe('utils', function () {
const [, tx] = await trackReceivedTokenAndTx(ethers.provider, usdt, signer2.address, () =>
usdt.approve(signer2.address, ether('1')),
);
if (!process.env.skip_on_coverage) {
if (hre.__SOLIDITY_COVERAGE_RUNNING) {
expect(await countInstructions(ethers.provider, tx.events[0].transactionHash, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 0, 1, 0,
]);
Expand Down

0 comments on commit 43ac5b6

Please sign in to comment.