This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
100% Coverage web3-utills #7042
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ebba894
increase unit tests for SocketProvider
Muhammad-Altabba 5dc4390
add a test for SocketProvider
Muhammad-Altabba 9f9d6df
add a test for PromiseHelper
Muhammad-Altabba f0153dc
Merge branch '4.x' into 7031-increase-testing-coverage-web3-utils
Muhammad-Altabba 82a16b3
add unit tests for utils
Muhammad-Altabba ad73c89
remove un visited code branch
Muhammad-Altabba 0d09e92
fix linting issue
Muhammad-Altabba b0e0bb4
point to a pice of code to investigate
Muhammad-Altabba 5b9bb46
fix linting issue
Muhammad-Altabba 8677c30
Merge branch '4.x' into 7031-increase-testing-coverage-web3-utils
1392b05
add coverage to hash
f9559f3
cover json-rpc tests
d61bd1d
cover socket provider file
e8ccfff
add coverage string manipulation
4ad228a
add coverage to formatters.ts
9154389
Merge branch '4.x' into 7031-increase-testing-coverage-web3-utils
3697767
fix failing tests
c24c798
update hash
72e7095
run prettier
12b198b
Merge branch '4.x' into 7031-increase-testing-coverage-web3-utils
b9617ee
remove unintended cases for formatter and convert
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,5 @@ packages/web3/.in3/ | |
benchmark-data.txt | ||
|
||
.eslintcache | ||
|
||
.history |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,8 @@ const findSchemaByDataPath = ( | |
|
||
for (const dataPart of dataPath) { | ||
if (result.oneOf && previousDataPath) { | ||
const path = oneOfPath.find(function (element: [string, number]) { | ||
return (this as unknown as string) === element[0]; | ||
}, previousDataPath ?? ''); | ||
|
||
const currentDataPath = previousDataPath; | ||
const path = oneOfPath.find(([key]) => key === currentDataPath); | ||
if (path && path[0] === previousDataPath) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
result = result.oneOf[path[1]]; | ||
|
@@ -75,10 +73,6 @@ const findSchemaByDataPath = ( | |
} else if (result.items && (result.items as JsonSchema).properties) { | ||
const node = (result.items as JsonSchema).properties as Record<string, JsonSchema>; | ||
|
||
if (!node) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we remove this |
||
return undefined; | ||
} | ||
|
||
result = node[dataPart]; | ||
} else if (result.items && isObject(result.items)) { | ||
result = result.items; | ||
|
@@ -307,7 +301,7 @@ export const convert = ( | |
|
||
// If value is an object, recurse into it | ||
if (isObject(value)) { | ||
convert(value, schema, dataPath, format); | ||
convert(value, schema, dataPath, format, oneOfPath); | ||
dataPath.pop(); | ||
continue; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ import { isNullish } from 'web3-validator'; | |
export type Timer = ReturnType<typeof setInterval>; | ||
export type Timeout = ReturnType<typeof setTimeout>; | ||
|
||
|
||
/** | ||
* An alternative to the node function `isPromise` that exists in `util/types` because it is not available on the browser. | ||
* @param object - to check if it is a `Promise` | ||
|
@@ -74,7 +73,6 @@ export async function waitWithTimeout<T>( | |
return result; | ||
} | ||
|
||
|
||
/** | ||
* Repeatedly calls an async function with a given interval until the result of the function is defined (not undefined or null), | ||
* or until a timeout is reached. It returns promise and intervalId. | ||
|
@@ -85,25 +83,27 @@ export function pollTillDefinedAndReturnIntervalId<T>( | |
func: AsyncFunction<T>, | ||
interval: number, | ||
): [Promise<Exclude<T, undefined>>, Timer] { | ||
|
||
let intervalId: Timer | undefined; | ||
const polledRes = new Promise<Exclude<T, undefined>>((resolve, reject) => { | ||
intervalId = setInterval(function intervalCallbackFunc(){ | ||
(async () => { | ||
try { | ||
const res = await waitWithTimeout(func, interval); | ||
|
||
if (!isNullish(res)) { | ||
intervalId = setInterval( | ||
(function intervalCallbackFunc() { | ||
(async () => { | ||
try { | ||
const res = await waitWithTimeout(func, interval); | ||
|
||
if (!isNullish(res)) { | ||
clearInterval(intervalId); | ||
resolve(res as unknown as Exclude<T, undefined>); | ||
} | ||
} catch (error) { | ||
clearInterval(intervalId); | ||
resolve(res as unknown as Exclude<T, undefined>); | ||
reject(error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this file was changed from prettier |
||
} | ||
} catch (error) { | ||
clearInterval(intervalId); | ||
reject(error); | ||
} | ||
})() as unknown; | ||
return intervalCallbackFunc;}() // this will immediate invoke first call | ||
, interval); | ||
})() as unknown; | ||
return intervalCallbackFunc; | ||
})(), // this will immediate invoke first call | ||
interval, | ||
); | ||
}); | ||
|
||
return [polledRes as unknown as Promise<Exclude<T, undefined>>, intervalId!]; | ||
|
@@ -113,7 +113,7 @@ export function pollTillDefinedAndReturnIntervalId<T>( | |
* Repeatedly calls an async function with a given interval until the result of the function is defined (not undefined or null), | ||
* or until a timeout is reached. | ||
* pollTillDefinedAndReturnIntervalId() function should be used instead of pollTillDefined if you need IntervalId in result. | ||
* This function will be deprecated in next major release so use pollTillDefinedAndReturnIntervalId(). | ||
* This function will be deprecated in next major release so use pollTillDefinedAndReturnIntervalId(). | ||
* @param func - The function to call. | ||
* @param interval - The interval in milliseconds. | ||
*/ | ||
|
@@ -146,7 +146,7 @@ export function rejectIfTimeout(timeout: number, error: Error): [Timer, Promise< | |
/** | ||
* Sets an interval that repeatedly executes the given cond function with the specified interval between each call. | ||
* If the condition is met, the interval is cleared and a Promise that rejects with the returned value is returned. | ||
* @param cond - The function/confition to call. | ||
* @param cond - The function/condition to call. | ||
* @param interval - The interval in milliseconds. | ||
* @returns - an array with the interval ID and the Promise. | ||
*/ | ||
|
@@ -168,4 +168,3 @@ export function rejectIfConditionAtInterval<T>( | |
}); | ||
return [intervalId!, rejectIfCondition]; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed this for readability