Skip to content

Commit

Permalink
4.x Preserve comments when transpiling from ts to js (#5967)
Browse files Browse the repository at this point in the history
* include comments

* remove deprecated method  error

* fix personal tests

---------

Co-authored-by: Nikos Iliakis <nikoulai@users.noreply.github.com>
  • Loading branch information
Alex and nikoulai authored Mar 30, 2023
1 parent 71a1856 commit de5617c
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 42 deletions.
3 changes: 1 addition & 2 deletions packages/web3-eth-accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ import {
bytesToBuffer,
bytesToHex,
hexToBytes,
isHexStrict,
numberToHex,
randomBytes,
sha3Raw,
toChecksumAddress,
utf8ToHex,
uuidV4,
} from 'web3-utils';
import { isBuffer, isNullish, isString, validator } from 'web3-validator';
import { isBuffer, isNullish, isString, validator, isHexStrict } from 'web3-validator';
import { keyStoreSchema } from './schemas';
import { SignatureObject, SignResult, SignTransactionResult, Web3Account } from './types';

Expand Down
3 changes: 1 addition & 2 deletions packages/web3-eth-accounts/test/integration/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.

import defaultImport, * as fullImport from '@ethereumjs/tx';
import { Address } from 'web3-types';
import { isHexStrict } from 'web3-utils';
import { Web3ValidatorError } from 'web3-validator';
import { Web3ValidatorError, isHexStrict } from 'web3-validator';
import {
create,
decrypt,
Expand Down
3 changes: 1 addition & 2 deletions packages/web3-eth-accounts/test/unit/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.

import defaultImport, * as fullImport from '@ethereumjs/tx';
import { Address } from 'web3-types';
import { isHexStrict } from 'web3-utils';
import { Web3ValidatorError } from 'web3-validator';
import { Web3ValidatorError, isHexStrict } from 'web3-validator';
import {
create,
decrypt,
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-eth-ens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"web3-eth-contract": "^4.0.1-rc.0",
"web3-net": "^4.0.1-rc.0",
"web3-types": "^1.0.0-rc.0",
"web3-utils": "^4.0.1-rc.0"
"web3-utils": "^4.0.1-rc.0",
"web3-validator": "1.0.0-rc.0"
}
}
3 changes: 2 additions & 1 deletion packages/web3-eth-ens/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { Contract, NonPayableCallOptions } from 'web3-eth-contract';
import { DataFormat, DEFAULT_RETURN_FORMAT, format, isHexStrict, sha3Raw } from 'web3-utils';
import { DataFormat, DEFAULT_RETURN_FORMAT, format, sha3Raw } from 'web3-utils';
import { isHexStrict } from 'web3-validator';
import { Address } from 'web3-types';
import { Web3ContextObject } from 'web3-core';
import { ENSRegistryAbi } from './abi/ens/ENSRegistry';
Expand Down
10 changes: 2 additions & 8 deletions packages/web3-eth-ens/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import {
sha3,
isHexStrict,
isNullish,
format,
DEFAULT_RETURN_FORMAT,
DataFormat,
} from 'web3-utils';
import { sha3, isNullish, format, DEFAULT_RETURN_FORMAT, DataFormat } from 'web3-utils';
import { Contract, NonPayableCallOptions } from 'web3-eth-contract';
import { ResolverMethodMissingError } from 'web3-errors';
import { isHexStrict } from 'web3-validator';
import { Address } from 'web3-types';
import { interfaceIds, methodsInInterface } from './config';
import { Registry } from './registry';
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-eth-iban/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"dependencies": {
"web3-errors": "^1.0.0-rc.0",
"web3-types": "^1.0.0-rc.0",
"web3-utils": "^4.0.1-rc.0"
"web3-utils": "^4.0.1-rc.0",
"web3-validator": "1.0.0-rc.0"
}
}
3 changes: 2 additions & 1 deletion packages/web3-eth-iban/src/iban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { HexString } from 'web3-types';
import { toChecksumAddress, isAddress, leftPad, hexToNumber } from 'web3-utils';
import { toChecksumAddress, leftPad, hexToNumber } from 'web3-utils';
import { isAddress } from 'web3-validator';
import { InvalidAddressError } from 'web3-errors';
import { IbanOptions } from './types';

Expand Down
4 changes: 2 additions & 2 deletions packages/web3-eth-personal/src/rpc_method_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import { Web3RequestManager } from 'web3-core';
import { ETH_DATA_FORMAT, isHexStrict, toChecksumAddress, utf8ToHex } from 'web3-utils';
import { ETH_DATA_FORMAT, toChecksumAddress, utf8ToHex } from 'web3-utils';
import { formatTransaction } from 'web3-eth';
import { Address, EthPersonalAPI, HexString, Transaction } from 'web3-types';
import { validator } from 'web3-validator';
import { validator, isHexStrict } from 'web3-validator';
import { personalRpcMethods } from 'web3-rpc-methods';

export const getAccounts = async (requestManager: Web3RequestManager<EthPersonalAPI>) => {
Expand Down
23 changes: 11 additions & 12 deletions packages/web3-eth-personal/test/unit/eth_personal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,24 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { ETH_DATA_FORMAT } from 'web3-utils';
import * as utils from 'web3-utils';
import * as eth from 'web3-eth';
import { validator } from 'web3-validator';
import * as validator from 'web3-validator';
import { Personal } from '../../src/index';

jest.mock('web3-utils');
jest.mock('web3-eth');

jest.mock('web3-validator');
describe('Personal', () => {
let personal: Personal;
let sendSpy: jest.SpyInstance;
let validateSpy: jest.SpyInstance;

beforeEach(() => {
personal = new Personal('http://localhost:8545');

sendSpy = jest.spyOn(personal.requestManager, 'send').mockImplementation(async () => {
return Promise.resolve('0x0');
});

validateSpy = jest.spyOn(validator, 'validate').mockReturnValue(undefined);
validateSpy = jest.spyOn(validator.validator, 'validate').mockReturnValue(undefined);

jest.resetAllMocks();
});
Expand Down Expand Up @@ -224,7 +223,7 @@ describe('Personal', () => {
it('should call the correct method for request manager', async () => {
const data = '0x1234';

jest.spyOn(utils, 'isHexStrict').mockReturnValue(true);
jest.spyOn(validator, 'isHexStrict').mockReturnValue(true);

await personal.sign(data, '0x528ABBBa47c33600245066398072799A9b7e2d9E', 'password');

Expand All @@ -237,7 +236,7 @@ describe('Personal', () => {
it('should convert input if not hex', async () => {
const data = '0x1234';

jest.spyOn(utils, 'isHexStrict').mockReturnValue(false);
jest.spyOn(validator, 'isHexStrict').mockReturnValue(false);
jest.spyOn(utils, 'utf8ToHex').mockReturnValue(data);

await personal.sign(data, '0x528ABBBa47c33600245066398072799A9b7e2d9E', 'password');
Expand All @@ -249,7 +248,7 @@ describe('Personal', () => {
it('should not convert input if data is already hex', async () => {
const data = '0x1234';

jest.spyOn(utils, 'isHexStrict').mockReturnValue(true);
jest.spyOn(validator, 'isHexStrict').mockReturnValue(true);

await personal.sign(data, '0x528ABBBa47c33600245066398072799A9b7e2d9E', 'password');

Expand All @@ -259,7 +258,7 @@ describe('Personal', () => {
it('should validate user input', async () => {
const data = '0x1234';

jest.spyOn(utils, 'isHexStrict').mockReturnValue(true);
jest.spyOn(validator, 'isHexStrict').mockReturnValue(true);

await personal.sign(data, '0x528ABBBa47c33600245066398072799A9b7e2d9E', 'password');

Expand All @@ -275,7 +274,7 @@ describe('Personal', () => {
it('should call the correct method for request manager', async () => {
const data = '0x1234';

jest.spyOn(utils, 'isHexStrict').mockReturnValue(true);
jest.spyOn(validator, 'isHexStrict').mockReturnValue(true);

await personal.ecRecover(data, '0x000000');

Expand All @@ -288,7 +287,7 @@ describe('Personal', () => {
it('should convert input if not hex', async () => {
const data = '0x1234';

jest.spyOn(utils, 'isHexStrict').mockReturnValue(false);
jest.spyOn(validator, 'isHexStrict').mockReturnValue(false);
jest.spyOn(utils, 'utf8ToHex').mockReturnValue(data);

await personal.ecRecover(data, 'password');
Expand All @@ -300,7 +299,7 @@ describe('Personal', () => {
it('should not convert input if data is already hex', async () => {
const data = '0x1234';

jest.spyOn(utils, 'isHexStrict').mockReturnValue(true);
jest.spyOn(validator, 'isHexStrict').mockReturnValue(true);

await personal.ecRecover(data, 'password');

Expand All @@ -310,7 +309,7 @@ describe('Personal', () => {
it('should validate user input', async () => {
const data = '0x1234';

jest.spyOn(utils, 'isHexStrict').mockReturnValue(true);
jest.spyOn(validator, 'isHexStrict').mockReturnValue(true);

await personal.ecRecover(data, 'password');

Expand Down
11 changes: 2 additions & 9 deletions packages/web3-eth/src/utils/transaction_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import {
DEFAULT_RETURN_FORMAT,
ETH_DATA_FORMAT,
FormatType,
format,
DataFormat,
isAddress,
} from 'web3-utils';
import { DEFAULT_RETURN_FORMAT, ETH_DATA_FORMAT, FormatType, format, DataFormat } from 'web3-utils';
import {
EthExecutionAPI,
Address,
Expand All @@ -40,7 +33,7 @@ import {
import { Web3Context } from 'web3-core';
import { privateKeyToAddress } from 'web3-eth-accounts';
import { getId } from 'web3-net';
import { isNullish, isNumber, isHexStrict } from 'web3-validator';
import { isNullish, isNumber, isHexStrict, isAddress } from 'web3-validator';
import {
InvalidTransactionWithSender,
InvalidTransactionWithReceiver,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"pretty": true,
"removeComments": true,
"removeComments": false,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
Expand Down

0 comments on commit de5617c

Please sign in to comment.