-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5914 from NomicFoundation/config-var-in-http-acco…
…unts Accept Configuration Variables in HTTP networks' `accounts`
- Loading branch information
Showing
31 changed files
with
1,311 additions
and
715 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { network } from "@ignored/hardhat-vnext"; | ||
|
||
const { provider } = await network.connect("opSepolia", "optimism"); | ||
|
||
const accounts = (await provider.request({ | ||
method: "eth_accounts", | ||
})) as string[]; | ||
|
||
console.log("Accounts:", accounts); | ||
|
||
const sender = accounts[0]; | ||
|
||
console.log("Sender:", sender); | ||
|
||
console.log( | ||
"Sender balance: ", | ||
(await provider.request({ | ||
method: "eth_getBalance", | ||
params: [sender, "latest"], | ||
})) as string, | ||
); | ||
|
||
console.log("Sending 1 gwei from", sender, "to", sender); | ||
|
||
const tx = await provider.request({ | ||
method: "eth_sendTransaction", | ||
params: [ | ||
{ | ||
from: sender, | ||
to: sender, | ||
value: "0x1", | ||
}, | ||
], | ||
}); | ||
|
||
console.log("Transaction hash:", tx); | ||
|
||
while (true) { | ||
console.log("Waiting for transaction to be mined..."); | ||
const receipt = await provider.request({ | ||
method: "eth_getTransactionReceipt", | ||
params: [tx], | ||
}); | ||
|
||
if (receipt === null) { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
continue; | ||
} | ||
|
||
console.log("Transaction receipt:", receipt); | ||
break; | ||
} |
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import assert from "node:assert/strict"; | ||
|
||
/** | ||
* We duplicate this to avoid a circular dependency between packages. | ||
*/ | ||
export interface ValidationError { | ||
path: Array<string | number>; | ||
message: string; | ||
} | ||
|
||
/** | ||
* An expected validation error, which is a ValidationError with an optional | ||
* message. If the message is not provided, it's not asserted. | ||
*/ | ||
export interface ExpectedValidationError { | ||
path: Array<string | number>; | ||
message?: string; | ||
} | ||
|
||
/** | ||
* Asserts that the validations results are equal to the expected ones, ignoring | ||
* the order of the errors. | ||
* | ||
* @param validationResult The results of running a validation function. | ||
* @param expectedErrors The expected errors, which can omit the message, and | ||
* don't need to be in the same order. | ||
*/ | ||
export function assertValidationErrors( | ||
validationResult: ValidationError[], | ||
expectedErrors: ExpectedValidationError[], | ||
): void { | ||
const resultsByJsonPath = groupByJsonPath(validationResult); | ||
const expectedErrorsByJsonPath = groupByJsonPath(expectedErrors); | ||
|
||
for (const [jsonPath, expectedErrorsForPath] of expectedErrorsByJsonPath) { | ||
const resultErrors = resultsByJsonPath.get(jsonPath); | ||
|
||
if (resultErrors === undefined) { | ||
assert.fail( | ||
`Expected errors for path ${jsonPath} but none were found. Got these instead ${JSON.stringify(validationResult, undefined, 2)}`, | ||
); | ||
|
||
return; | ||
} | ||
|
||
for (const expectedError of expectedErrorsForPath) { | ||
if (expectedError.message === undefined) { | ||
continue; | ||
} | ||
|
||
const isPresent = resultErrors.some( | ||
(r) => r.message === expectedError.message, | ||
); | ||
|
||
if (!isPresent) { | ||
assert.fail( | ||
`Expected an error for path ${jsonPath} to have message "${expectedError.message}" but found these instead ${JSON.stringify(resultErrors.map((e) => e.message))}`, | ||
); | ||
return; | ||
} | ||
} | ||
|
||
if (expectedErrorsForPath.length !== resultErrors.length) { | ||
assert.fail( | ||
`Expected ${expectedErrorsForPath.length} errors for path ${jsonPath} but found ${resultErrors.length} instead: ${JSON.stringify(resultErrors.map((e) => e.message))}`, | ||
); | ||
} | ||
} | ||
|
||
for (const [jsonPath, resultErrors] of resultsByJsonPath) { | ||
const expectedErrorsForPath = expectedErrorsByJsonPath.get(jsonPath); | ||
|
||
if (expectedErrorsForPath === undefined) { | ||
assert.fail( | ||
`No errors were expected for path ${jsonPath} but found these instead ${JSON.stringify(resultErrors.map((e) => e.message))}`, | ||
); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
function groupByJsonPath< | ||
ErrorT extends ValidationError | ExpectedValidationError, | ||
>(validationErrors: ErrorT[]): Map<string, ErrorT[]> { | ||
const groupedByPath = new Map<string, ErrorT[]>(); | ||
|
||
for (const validationError of validationErrors) { | ||
const jsonPath = JSON.stringify(validationError.path); | ||
const errors = groupedByPath.get(jsonPath) ?? []; | ||
errors.push(validationError); | ||
groupedByPath.set(jsonPath, errors); | ||
} | ||
|
||
return groupedByPath; | ||
} |
This file contains 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.