Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9e5834f
Init web3-test-utils and realted errors
Spacesai1or Sep 9, 2022
95f4d92
WIP test utils
Spacesai1or Sep 10, 2022
bb45fa7
Remove web3-eth and web3-eth-accounts dep from web3-test-utils
Spacesai1or Sep 13, 2022
56d0609
Add web3-test-utils dep to web3-eth-accounts
Spacesai1or Sep 13, 2022
17193ae
WIP refactors for web3_context.ts
Spacesai1or Sep 13, 2022
71ba344
WIP test utils
Spacesai1or Sep 14, 2022
6e0210e
WIP call.test.ts test-util refactor
Spacesai1or Sep 14, 2022
a29a138
Init web3-eth-transaction-utils
Spacesai1or Sep 14, 2022
548fa33
Init web3-rpc-methods
Spacesai1or Sep 14, 2022
80915f7
Add web3-eth-transaction-utils dependency to web3
Spacesai1or Sep 14, 2022
135570f
Update privateKey parameter type for TransactionBuilder type in web3-…
Spacesai1or Sep 14, 2022
4b23a08
Remove transaction related util methods (replaced with web3-eth-trans…
Spacesai1or Sep 14, 2022
2f4d042
Move eth_execution_api to web3-types
Spacesai1or Sep 14, 2022
68c0552
Move eth_personal_api to web3-types
Spacesai1or Sep 14, 2022
8b44abd
Update imports for decode_signed_transaction
Spacesai1or Sep 14, 2022
37e3c76
Remove old transaction util exports in web3-eth
Spacesai1or Sep 14, 2022
0116706
Replace rpc_methods.ts with web3-rpc-methods in web3-eth
Spacesai1or Sep 14, 2022
85b237b
Update formatTransaction import in web3-eth
Spacesai1or Sep 14, 2022
293e3fd
Add web3-eth-transaction-utils and web3-rpc-methods dependencies to w…
Spacesai1or Sep 14, 2022
90aada4
Update imports in web3-eth-ens
Spacesai1or Sep 14, 2022
32422a2
Remove types export in web3-eth-personal
Spacesai1or Sep 14, 2022
b776fa3
Update imports in web3-eth-personal
Spacesai1or Sep 14, 2022
b4053d5
Remove rpc_methods from web3-eth-personal (replaced via web3-rpc-meth…
Spacesai1or Sep 14, 2022
baaeb13
Update imported methods in web3-eth-personal's rpc_method_wrappers
Spacesai1or Sep 14, 2022
be3aeea
Remove types.ts in web3-eth-personal
Spacesai1or Sep 14, 2022
2d69bb6
Add web3-eth-transaction-utils and web3-rpc-methods dependencies to w…
Spacesai1or Sep 14, 2022
32a8a7c
Remove rpcMethods and Web3NetApi exports in web3-net
Spacesai1or Sep 14, 2022
b46f0fb
Update import in web3-net
Spacesai1or Sep 14, 2022
17be1a6
Add web3-rpc-methods dependency to web3-net
Spacesai1or Sep 14, 2022
2fbc23d
Remove web3_net_api.ts in web3-net
Spacesai1or Sep 14, 2022
4a64608
Add web3-rpc-methods dependency to web3-test-utils
Spacesai1or Sep 14, 2022
0d1c8b1
Move Web3EthExecutionAPI to web3-types
Spacesai1or Sep 14, 2022
4787590
Move Web3NetAPI to web3-types
Spacesai1or Sep 14, 2022
fc0197c
Move eth_execution_api within web3-types package
Spacesai1or Sep 14, 2022
7ff2d90
Update web3-types exports
Spacesai1or Sep 14, 2022
7198140
Init privateKeyToAddress method signature type
Spacesai1or Sep 14, 2022
eb4f2cd
Update import for EthExecutionAPI in web3-types
Spacesai1or Sep 14, 2022
e7943a9
Init web3_eth_schemas.ts in web3-types
Spacesai1or Sep 14, 2022
7aa5797
Remove rpc_methods.ts in web3-net
Spacesai1or Sep 14, 2022
4534bea
Update imports in web3-net
Spacesai1or Sep 14, 2022
c5e3887
Init use of web3-rpc-methods in web3-test-utils
Spacesai1or Sep 14, 2022
69fd64d
Correct types in wait_for_transaction_receipt.ts in web3-eth
Spacesai1or Sep 14, 2022
5b5936b
Update import for getBlockByNumber in web3-eth watch_transaction_for_…
Spacesai1or Sep 14, 2022
833744d
Update imports for rpc_method_wrappers.ts in web3-eth
Spacesai1or Sep 14, 2022
1291e52
Update imports for web3_eth.ts
Spacesai1or Sep 14, 2022
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
1 change: 1 addition & 0 deletions packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class Web3Context<
| SupportedProviders<API>
| Web3ContextInitOptions<API, RegisteredSubs>,
) {
console.log(providerOrContext)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its for local debugging so should be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this PR is still a draft and not ready for review

super();

// If "providerOrContext" is provided as "string" or an objects matching "SupportedProviders" interface
Expand Down
5 changes: 5 additions & 0 deletions packages/web3-errors/src/error_codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,8 @@ export const ERR_INVALID_NIBBLE_WIDTH = 1014;

// Validation error codes
export const ERR_VALIDATION = 1100;

// Test utils error codes
export const ERR_WAIT_FOR_OPEN_CONNECTION_TIMEOUT = 1200;
export const ERR_PROVIDER_CONNECTION_NOT_WAITABLE = 1201;
export const ERR_PROVIDER_CONNECTION_NOT_CLOSEABLE = 1202;
44 changes: 44 additions & 0 deletions packages/web3-errors/src/errors/test_utils_errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
This file is part of web3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

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/>.
*/
/* eslint-disable max-classes-per-file */
import {
ERR_PROVIDER_CONNECTION_NOT_CLOSEABLE,
ERR_PROVIDER_CONNECTION_NOT_WAITABLE,
ERR_WAIT_FOR_OPEN_CONNECTION_TIMEOUT,
} from '../error_codes';
import { Web3Error } from '../web3_error_base';

export class WaitForOpenConnectionTimeoutError extends Web3Error {
public code = ERR_WAIT_FOR_OPEN_CONNECTION_TIMEOUT;
public constructor() {
super('Maximum number of attempts exceeded');
}
}

export class ProviderConnectionNotWaitableError extends Web3Error {
public code = ERR_PROVIDER_CONNECTION_NOT_WAITABLE;
public constructor() {
super('Cannot wait on open connection for provider');
}
}

export class ProviderConnectionNotCloseableError extends Web3Error {
public code = ERR_PROVIDER_CONNECTION_NOT_CLOSEABLE;
public constructor() {
super('Cannot close open connection for provider');
}
}
1 change: 1 addition & 0 deletions packages/web3-errors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export * from './errors/signature_errors';
export * from './errors/transaction_errors';
export * from './errors/utils_errors';
export * from './errors/response_errors';
export * from './errors/test_utils_errors';
3 changes: 2 additions & 1 deletion packages/web3-eth-accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"jest-when": "^3.5.1",
"prettier": "^2.7.1",
"ts-jest": "^28.0.7",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"web3-test-utils": "0.1.0-alpha.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will create cyclic dependency? as testing utils will use accounts pkg for account creation.

},
"dependencies": {
"@ethereumjs/tx": "^3.5.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
/* eslint-disable @typescript-eslint/no-magic-numbers */

import { Web3AccountProvider } from 'web3-types';
import { isBrowser, isElectron, itIf } from '../fixtures/system_test_utils';
import { isBrowser, isElectron, itIf } from 'web3-test-utils';

import { Wallet } from '../../src';
import * as accountProvider from '../../src/account';
import { Web3Account } from '../../dist';
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"typescript": "^4.7.4",
"web3-eth-abi": "^4.0.1-alpha.0",
"web3-eth-accounts": "^4.0.1-alpha.0",
"web3-providers-http": "^4.0.1-alpha.0"
"web3-providers-http": "^4.0.1-alpha.0",
"web3-test-utils": "0.1.0-alpha.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, cyclic dependency question?

},
"dependencies": {
"@ethereumjs/common": "^2.6.5",
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export * from './web3_eth';
export * from './schemas';
export * from './types';
export * from './validation';
// TODO Should export * from './rpc_methods';
export * from './rpc_method_wrappers';
export * from './utils/format_transaction';
export * from './utils/prepare_transaction_for_signing';
Expand Down
16 changes: 16 additions & 0 deletions packages/web3-eth/src/rpc_method_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
DEFAULT_RETURN_FORMAT,
format,
waitWithTimeout,
toChecksumAddress,
} from 'web3-utils';
import { isBlockTag, isBytes, isNullish, isString } from 'web3-validator';
import { TransactionError, TransactionRevertError } from 'web3-errors';
Expand Down Expand Up @@ -184,6 +185,21 @@ export async function getGasPrice<ReturnFormat extends DataFormat>(
return format({ eth: 'uint' }, response as Numbers, returnFormat);
}

/**
* @returns A list of accounts the node controls (addresses are checksummed).
*
* ```ts
* web3.eth.getAccounts().then(console.log);
* > ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf"]
* ```
*/
export async function getAccounts(
web3Context: Web3Context<EthExecutionAPI>
) {
const response = await rpcMethods.getAccounts(web3Context.requestManager);
return response.map(address => toChecksumAddress(address));
}

/**
* @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
Expand Down
5 changes: 2 additions & 3 deletions packages/web3-eth/src/web3_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from 'web3-types';
import { isSupportedProvider, Web3Context, Web3ContextInitOptions } from 'web3-core';
import { TransactionNotFound } from 'web3-errors';
import { toChecksumAddress, DataFormat, DEFAULT_RETURN_FORMAT } from 'web3-utils';
import { DataFormat, DEFAULT_RETURN_FORMAT } from 'web3-utils';
import * as rpcMethods from './rpc_methods';
import * as rpcMethodsWrappers from './rpc_method_wrappers';
import { SendTransactionOptions } from './types';
Expand Down Expand Up @@ -216,8 +216,7 @@ export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscrip
* ```
*/
public async getAccounts() {
const hexAddresses = (await rpcMethods.getAccounts(this.requestManager)) ?? [];
return hexAddresses.map(address => toChecksumAddress(address));
return rpcMethodsWrappers.getAccounts(this);
}

/**
Expand Down
Loading