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

5634/alex fix inconsistent event emitter geth ipc tests #5822

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/web3-eth-contract/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ const transactionHash = receipt.transactionHash;

### Fixed

- Fix contract defaults (#5756)
- Fixed contract defaults (#5756)
- Fixed getPastEvents Error (#5819)

### Changed

Expand Down
2 changes: 0 additions & 2 deletions packages/web3-providers-ws/test/fixtures/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const createProxy = async (
}, 2000);
ws.on('close', () => {
ws.removeAllListeners();
clearTimeout(timeOut);
resolve(true);
});
ws.terminate();
Expand All @@ -63,7 +62,6 @@ export const createProxy = async (
resolve(true);
}, 2000);
originWs.on('close', () => {
clearTimeout(timeOut);
originWs.removeAllListeners();
resolve(true);
});
Expand Down
160 changes: 3 additions & 157 deletions packages/web3-utils/src/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,7 @@ export const ethUnitMap = {
};

export type EtherUnits = keyof typeof ethUnitMap;
/**
* Convert a value from bytes to Buffer
* @param data - Data to be converted
* @returns - The Buffer representation of the input data
*
* @example
* ```ts
* console.log(web3.utils.bytesToBuffer(new Uint8Array([72, 12])));
* > <Buffer 48 0c>
* ```
*/

export const bytesToBuffer = (data: Bytes): Buffer | never => {
validator.validate(['bytes'], [data]);

Expand Down Expand Up @@ -113,42 +103,16 @@ const bufferToHexString = (data: Buffer) => `0x${data.toString('hex')}`;

/**
* Convert a byte array to a hex string
* @param bytes - Byte array to be converted
* @returns - The hex string representation of the input byte array
*
* @example
* ```ts
* console.log(web3.utils.bytesToHex(new Uint8Array([72, 12])));
* > "0x480c"
*
* console.log(web3.utils.bytesToHex(Buffer.from("0c12", "hex")));
* > "0x0c12"
*/
export const bytesToHex = (bytes: Bytes): HexString => bufferToHexString(bytesToBuffer(bytes));

/**
* Convert a hex string to a byte array
* @param hex - Hex string to be converted
* @returns - The byte array representation of the input hex string
*
* @example
* ```ts
* console.log(web3.utils.hexToBytes('0x74657374'));
* > <Buffer 74 65 73 74>
* ```
*/
export const hexToBytes = (bytes: HexString): Buffer => bytesToBuffer(bytes);

/**
* Converts value to it's number representation
* @param value - Hex string to be converted
* @returns - The number representation of the input value
*
* @example
* ```ts
* conoslle.log(web3.utils.hexToNumber('0xa'));
* > 10
* ```
*/
export const hexToNumber = (value: HexString): bigint | number => {
validator.validate(['hex'], [value]);
Expand All @@ -165,14 +129,6 @@ export const toDecimal = hexToNumber;

/**
* Converts value to it's hex representation
* @param value - Value to be converted
* @returns - The hex representation of the input value
*
* @example
* ```ts
* console.log(web3.utils.numberToHex(10));
* > "0xa"
* ```
*/
export const numberToHex = (value: Numbers): HexString => {
validator.validate(['int'], [value]);
Expand All @@ -183,33 +139,16 @@ export const numberToHex = (value: Numbers): HexString => {
};
/**
* Converts value to it's hex representation @alias `numberToHex`
*
*/
export const fromDecimal = numberToHex;

/**
* Converts value to it's decimal representation in string
* @param value - Hex string to be converted
* @returns - The decimal representation of the input value
*
* @example
* ```ts
* console.log(web3.utils.hexToNumberString('0xa'));
* > "10"
* ```
*/
export const hexToNumberString = (data: HexString): string => hexToNumber(data).toString();

/**
* Should be called to get hex representation (prefixed by 0x) of utf8 string
* @param str - Utf8 string to be converted
* @returns - The hex representation of the input string
*
* @example
* ```ts
* console.log(utf8ToHex('web3.js'));
* > "0x776562332e6a73"
*
*/
export const utf8ToHex = (str: string): HexString => {
validator.validate(['string'], [str]);
Expand All @@ -235,14 +174,6 @@ export const stringToHex = utf8ToHex;

/**
* Should be called to get utf8 from it's hex representation
* @param str - Hex string to be converted
* @returns - Utf8 string
*
* @example
* ```ts
* console.log(web3.utils.hexToUtf8('0x48656c6c6f20576f726c64'));
* > Hello World
* ```
*/
export const hexToUtf8 = (str: HexString): string => bytesToBuffer(str).toString('utf8');

Expand All @@ -258,14 +189,6 @@ export const hexToString = hexToUtf8;

/**
* Should be called to get hex representation (prefixed by 0x) of ascii string
* @param str - String to be converted to hex
* @returns - Hex string
*
* @example
* ```ts
* console.log(web3.utils.asciiToHex('Hello World'));
* > 0x48656c6c6f20576f726c64
* ```
*/
export const asciiToHex = (str: string): HexString => {
validator.validate(['string'], [str]);
Expand All @@ -280,14 +203,6 @@ export const fromAscii = asciiToHex;

/**
* Should be called to get ascii from it's hex representation
* @param str - Hex string to be converted to ascii
* @returns - Ascii string
*
* @example
* ```ts
* console.log(web3.utils.hexToAscii('0x48656c6c6f20576f726c64'));
* > Hello World
* ```
*/
export const hexToAscii = (str: HexString): string => bytesToBuffer(str).toString('ascii');

Expand All @@ -298,17 +213,6 @@ export const toAscii = hexToAscii;

/**
* Auto converts any given value into it's hex representation.
* @param value - Value to be converted to hex
* @param returnType - If true, it will return the type of the value
*
* @example
* ```ts
* console.log(web3.utils.toHex(10));
* > 0xa
*
* console.log(web3.utils.toHex('0x123', true));
* > bytes
*```
*/
export const toHex = (
value: Numbers | Bytes | Address | boolean | object,
Expand Down Expand Up @@ -354,24 +258,8 @@ export const toHex = (
};

/**
* Converts any given value into it's number representation, if possible, else into it's bigint representation.
* @param value - The value to convert
* @returns - Returns the value in number or bigint representation
*
* @example
* ```ts
* console.log(web3.utils.toNumber(1));
* > 1
* console.log(web3.utils.toNumber(Number.MAX_SAFE_INTEGER));
* > 9007199254740991
*
* console.log(web3.utils.toNumber(BigInt(Number.MAX_SAFE_INTEGER)));
* > 9007199254740991
*
* console.log(web3.utils.toNumber(BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1)));
* > 9007199254740992n
*
* ```
* Auto converts any given value into it's hex representation,
* then converts hex to number.
*/
export const toNumber = (value: Numbers): number | bigint => {
if (typeof value === 'number') {
Expand All @@ -397,15 +285,6 @@ export const toNumber = (value: Numbers): number | bigint => {

/**
* Auto converts any given value into it's bigint representation
*
* @param value - The value to convert
* @returns - Returns the value in bigint representation

* @example
* ```ts
* console.log(web3.utils.toBigInt(1));
* > 1n
* ```
*/
export const toBigInt = (value: unknown): bigint => {
if (typeof value === 'number') {
Expand All @@ -426,18 +305,6 @@ export const toBigInt = (value: unknown): bigint => {

/**
* Takes a number of wei and converts it to any other ether unit.
* @param number - The value in wei
* @param unit - The unit to convert to
* @returns - Returns the converted value in the given unit
*
* @example
* ```ts
* console.log(web3.utils.fromWei("1", "ether"));
* > 0.000000000000000001
*
* console.log(web3.utils.fromWei("1", "shannon"));
* > 0.000000001
* ```
*/
export const fromWei = (number: Numbers, unit: EtherUnits): string => {
const denomination = ethUnitMap[unit];
Expand Down Expand Up @@ -485,18 +352,7 @@ export const fromWei = (number: Numbers, unit: EtherUnits): string => {

/**
* Takes a number of a unit and converts it to wei.
*
* @param number - The number to convert.
* @param unit - {@link EtherUnits} The unit of the number passed.
* @returns The number converted to wei.
*
* @example
* ```ts
* console.log(web3.utils.toWei("0.001", "ether"));
* > 1000000000000000 //(wei)
* ```
*/
// todo in 1.x unit defaults to 'ether'
export const toWei = (number: Numbers, unit: EtherUnits): string => {
validator.validate(['number'], [number]);

Expand Down Expand Up @@ -537,16 +393,6 @@ export const toWei = (number: Numbers, unit: EtherUnits): string => {
return updatedValue.toString().padStart(decimals, '0').slice(0, -decimals);
};

/**
* Will convert an upper or lowercase Ethereum address to a checksum address.
* @param address - An address string
* @returns The checksum address
* @example
* ```ts
* web3.utils.toChecksumAddress('0xc1912fee45d61c87cc5ea59dae31190fffff232d');
* > "0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d"
* ```
*/
export const toChecksumAddress = (address: Address): string => {
if (!isAddress(address, false)) {
throw new InvalidAddressError(address);
Expand Down
28 changes: 2 additions & 26 deletions packages/web3-utils/src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ export type FormatType<T, F extends DataFormat> = number extends Extract<T, Numb
}
: T;

/**
* Finds the schema that corresponds to a specific data path within a larger JSON schema.
* It works by iterating over the dataPath array and traversing the JSON schema one step at a time until it reaches the end of the path.
*
* @param schema - represents a JSON schema, which is an object that describes the structure of JSON data
* @param dataPath - represents an array of strings that specifies the path to the data within the JSON schema
* @param oneOfPath - epresents an optional array of two-element tuples that specifies the "oneOf" option to choose, if the schema has oneOf and the data path can match multiple subschemas
* @returns the JSON schema that matches the data path
*
*/
const findSchemaByDataPath = (
schema: JsonSchema,
dataPath: string[],
Expand Down Expand Up @@ -126,13 +116,7 @@ const findSchemaByDataPath = (

return result;
};
/**
* Converts a value depending on the format
* @param value - value to convert
* @param ethType - The type of the value to be parsed
* @param format - The format to be converted to
* @returns - The value converted to the specified format
*/

export const convertScalarValue = (value: unknown, ethType: string, format: DataFormat) => {
try {
const { baseType } = parseBaseType(ethType);
Expand Down Expand Up @@ -172,15 +156,7 @@ export const convertScalarValue = (value: unknown, ethType: string, format: Data

return value;
};
/**
* Converts the data to the specified format
* @param data - data to convert
* @param schema - The JSON schema that describes the structure of the data
* @param dataPath - A string array that specifies the path to the data within the JSON schema
* @param format - The format to be converted to
* @param oneOfPath - An optional array of two-element tuples that specifies the "oneOf" option to choose, if the schema has oneOf and the data path can match multiple subschemas
* @returns - The data converted to the specified format
*/

export const convert = (
data: Record<string, unknown> | unknown[] | unknown,
schema: JsonSchema,
Expand Down
Loading