Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
ZumZoom committed Dec 18, 2023
1 parent cd0079c commit 1bf71c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions test/contracts/SafestERC20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { constants, ether, expect } from '../../src/prelude';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import hre, { ethers } from 'hardhat';
import { Signature, TypedDataDomain } from 'ethers';
import { Signature, TypedDataDomain, ContractTransactionReceipt } from 'ethers';
import { PERMIT2_ADDRESS } from '@uniswap/permit2-sdk';
import { countInstructions, trackReceivedTokenAndTx } from '../../src/utils';
import {
Expand Down Expand Up @@ -297,7 +297,7 @@ describe('SafeERC20', function () {
const { weth, wrapper } = await loadFixture(deployWrapperWETH);
const [received, tx] = await trackReceivedTokenAndTx(ethers.provider, weth, await wrapper.getAddress(), () =>
wrapper.deposit({ value: ether('1') }),
);
) as [bigint, ContractTransactionReceipt];
expect(received).to.be.equal(ether('1'));
if (hre.__SOLIDITY_COVERAGE_RUNNING === undefined) {
expect(await countInstructions(ethers.provider, tx.logs[0].transactionHash, ['STATICCALL', 'CALL', 'MSTORE', 'MLOAD', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
Expand All @@ -308,9 +308,9 @@ describe('SafeERC20', function () {

it('should be cheap on deposit 0 tokens', async function () {
const { weth, wrapper } = await loadFixture(deployWrapperWETH);
const [, tx] = await trackReceivedTokenAndTx(ethers.provider, weth, await wrapper.getAddress(), () =>
const tx = (await trackReceivedTokenAndTx(ethers.provider, weth, await wrapper.getAddress(), () =>
wrapper.deposit(),
);
))[1] as ContractTransactionReceipt;
if (hre.__SOLIDITY_COVERAGE_RUNNING === undefined) {
expect(await countInstructions(ethers.provider, tx.hash, ['STATICCALL', 'CALL', 'MSTORE', 'MLOAD', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 0, 1, 0, 0, 1,
Expand All @@ -331,7 +331,7 @@ describe('SafeERC20', function () {
const spenderBalanceBefore = await ethers.provider.getBalance(spender);
const [received, tx] = await trackReceivedTokenAndTx(ethers.provider, weth, await wrapper.getAddress(), () =>
wrapper.withdrawTo(ether('0.5'), spender),
);
) as [bigint, ContractTransactionReceipt];
expect(received).to.be.equal(-ether('0.5'));
expect(await ethers.provider.getBalance(spender)).to.be.equal(spenderBalanceBefore + ether('0.5'));
if (hre.__SOLIDITY_COVERAGE_RUNNING === undefined) {
Expand All @@ -343,9 +343,9 @@ describe('SafeERC20', function () {

it('should be cheap on withdrawTo to self', async function () {
const { weth, wrapper } = await loadFixture(deployWrapperWETHAndDeposit);
const [, tx] = await trackReceivedTokenAndTx(ethers.provider, weth, await wrapper.getAddress(), () =>
const tx = (await trackReceivedTokenAndTx(ethers.provider, weth, await wrapper.getAddress(), () =>
wrapper.withdrawTo(ether('0.5'), wrapper),
);
))[1] as ContractTransactionReceipt;
if (hre.__SOLIDITY_COVERAGE_RUNNING === undefined) {
expect(await countInstructions(ethers.provider, tx.hash, ['STATICCALL', 'CALL'])).to.be.deep.equal([
0, 2,
Expand Down
14 changes: 7 additions & 7 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { timeIncreaseTo, fixSignature, signMessage, trackReceivedTokenAndTx, cou
import hre, { deployments, ethers } from 'hardhat';
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import { getBytes, hexlify, randomBytes, toUtf8Bytes, EventLog } from 'ethers';
import { getBytes, hexlify, randomBytes, toUtf8Bytes, EventLog, ContractTransactionReceipt } from 'ethers';
import { TokenMock, WETH } from '../typechain-types';

describe('timeIncreaseTo', function () {
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('utils', function () {

const [received, tx] = await trackReceivedTokenAndTx(ethers.provider, usdt, signer2.address, () =>
usdt.transfer(signer2, ether('1')),
);
) as [bigint, ContractTransactionReceipt];
expect(received).to.be.equal(ether('1'));
expect(tx.from).equal(signer1.address);
expect(tx.to).equal(await usdt.getAddress());
Expand All @@ -110,7 +110,7 @@ describe('utils', function () {

const [received, tx] = await trackReceivedTokenAndTx(ethers.provider, usdt, signer2.address, () =>
usdt.approve(signer2, ether('1')),
);
) as [bigint, ContractTransactionReceipt];
expect(received).to.be.equal('0');
expect(tx.from).equal(signer1.address);
expect(tx.to).equal(await usdt.getAddress());
Expand Down Expand Up @@ -144,9 +144,9 @@ describe('utils', function () {
it('should be counted ERC20 Transfer', async function () {
const { usdt } = await loadFixture(deployUSDT);

const [, tx] = await trackReceivedTokenAndTx(ethers.provider, usdt, signer2.address, () =>
const tx = (await trackReceivedTokenAndTx(ethers.provider, usdt, signer2.address, () =>
usdt.transfer(signer2, ether('1')),
);
))[1] as ContractTransactionReceipt;
if (hre.__SOLIDITY_COVERAGE_RUNNING === undefined) {
expect(await countInstructions(ethers.provider, tx.logs[0].transactionHash, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 0, 2, 2,
Expand All @@ -157,9 +157,9 @@ describe('utils', function () {
it('should be counted ERC20 Approve', async function () {
const { usdt } = await loadFixture(deployUSDT);

const [, tx] = await trackReceivedTokenAndTx(ethers.provider, usdt, signer2.address, () =>
const tx = (await trackReceivedTokenAndTx(ethers.provider, usdt, signer2.address, () =>
usdt.approve(signer2, ether('1')),
);
))[1] as ContractTransactionReceipt;
if (hre.__SOLIDITY_COVERAGE_RUNNING === undefined) {
expect(await countInstructions(ethers.provider, tx.logs[0].transactionHash, ['STATICCALL', 'CALL', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 0, 1, 0,
Expand Down

0 comments on commit 1bf71c7

Please sign in to comment.