From c99d7f29bf7306af49da4067439de8e8ad35ec6c Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 8 Feb 2023 10:52:37 -0500 Subject: [PATCH 01/22] adding consolelogs --- .../test/integration/contract_deploy.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts index f89008d7b95..f794d0b8878 100644 --- a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts @@ -148,7 +148,7 @@ describe('contract', () => { it('should emit the "confirmation" event', async () => { const confirmationHandler = jest.fn(); - + console.log("first confirmation deploy conract") await contract .deploy(deployOptions) .send(sendOptions) @@ -159,8 +159,9 @@ describe('contract', () => { // Deploy once again to trigger block mining to trigger confirmation // We can send any other transaction as well + console.log("before deploying second contract") await contract.deploy(deployOptions).send(sendOptions); - + console.log("after deploy"); // Wait for some fraction of time to trigger the handler // On http we use polling to get confirmation, so wait a bit longer await sleep(isWs ? 500 : 2000); @@ -171,15 +172,16 @@ describe('contract', () => { it('should emit the "transactionHash" event', async () => { const handler = jest.fn(); - + console.log("before first deploy") const promiEvent = contract .deploy(deployOptions) .send(sendOptions) .on('transactionHash', handler); // Deploy the contract + console.log("before promievent") await promiEvent; - + console.log("after promievent"); expect(handler).toHaveBeenCalled(); }); From 8fb04f4eddb3b3da43aa5e0fe542d1954cff26a4 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 8 Feb 2023 14:12:08 -0500 Subject: [PATCH 02/22] update to debug --- packages/web3-eth-contract/src/contract.ts | 3 ++- .../test/integration/contract_deploy.test.ts | 9 ++++++--- .../integration/local_account/contract_deploy.test.ts | 11 +++++++---- packages/web3-eth/src/rpc_method_wrappers.ts | 3 ++- scripts/geth.sh | 4 ++-- scripts/geth_binary.sh | 4 ++-- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index c7081683107..5766553d3c9 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -1076,9 +1076,10 @@ export class Contract options, contractOptions: modifiedContractOptions, }); - + console.log("transaction contract method deploy send") return sendTransaction(this, tx, DEFAULT_RETURN_FORMAT, { transactionResolver: receipt => { + console.log(tx) if (receipt.status === BigInt(0)) { throw new Web3ContractError("code couldn't be stored", receipt); } diff --git a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts index f794d0b8878..108d467026a 100644 --- a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts @@ -164,8 +164,9 @@ describe('contract', () => { console.log("after deploy"); // Wait for some fraction of time to trigger the handler // On http we use polling to get confirmation, so wait a bit longer + console.log("before sleep"); await sleep(isWs ? 500 : 2000); - + console.log("after sleep"); // eslint-disable-next-line jest/no-standalone-expect expect(confirmationHandler).toHaveBeenCalled(); }); @@ -175,8 +176,10 @@ describe('contract', () => { console.log("before first deploy") const promiEvent = contract .deploy(deployOptions) - .send(sendOptions) - .on('transactionHash', handler); + .send(sendOptions) + .on('transactionHash', handler) + .on('sending', () => { console.log("sending event ")}) + .on('sent', ()=> {console.log("transaction has been sent")}); // Deploy the contract console.log("before promievent") diff --git a/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts b/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts index 5a8cb21c34a..ffeddcb877b 100644 --- a/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts +++ b/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts @@ -118,17 +118,17 @@ describe('contract', () => { it('should emit the "confirmation" event', async () => { const confirmationHandler = jest.fn(); - + console.log("account before deploy"); await contract .deploy(deployOptions) .send(sendOptions) .on('confirmation', confirmationHandler); - // Wait for sometime to allow the transaction to be processed await sleep(500); // Deploy once again to trigger block mining to trigger confirmation // We can send any other transaction as well + console.log("before second deploy") await contract.deploy(deployOptions).send(sendOptions); // Wait for some fraction of time to trigger the handler @@ -141,14 +141,17 @@ describe('contract', () => { it('should emit the "transactionHash" event', async () => { const handler = jest.fn(); - + console.log("account before deploy using promievent") const promiEvent = contract .deploy(deployOptions) .send(sendOptions) - .on('transactionHash', handler); + .on('transactionHash', handler) + .on('sending', () => { console.log("sending event ")}) + .on('sent', ()=> {console.log("transaction has been sent")}); // Deploy the contract await promiEvent; + console.log("after account promievent"); expect(handler).toHaveBeenCalled(); }); diff --git a/packages/web3-eth/src/rpc_method_wrappers.ts b/packages/web3-eth/src/rpc_method_wrappers.ts index 4df1abfccc2..0e130a78dfc 100644 --- a/packages/web3-eth/src/rpc_method_wrappers.ts +++ b/packages/web3-eth/src/rpc_method_wrappers.ts @@ -1111,7 +1111,7 @@ export function sendTransaction< if (promiEvent.listenerCount('sending') > 0) { promiEvent.emit('sending', transactionFormatted); } - + let transactionHash: HexString; let wallet: Web3BaseWalletAccount | undefined; @@ -1143,6 +1143,7 @@ export function sendTransaction< ), ); } + console.log("transaction hash ",transactionHash); const transactionHashFormatted = format( { eth: 'bytes32' }, diff --git a/scripts/geth.sh b/scripts/geth.sh index df7731a57d6..927af8fd748 100755 --- a/scripts/geth.sh +++ b/scripts/geth.sh @@ -13,11 +13,11 @@ start() { then echo "Starting geth..." echo "docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" - docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev + docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine else echo "Starting geth..." echo "docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" - docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev + docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine echo "Waiting for geth..." npx wait-port -t 10000 "$WEB3_SYSTEM_TEST_PORT" echo "Geth started" diff --git a/scripts/geth_binary.sh b/scripts/geth_binary.sh index 33dbdefc373..cf1db2f9d3e 100755 --- a/scripts/geth_binary.sh +++ b/scripts/geth_binary.sh @@ -60,11 +60,11 @@ start() { if [ -z "${ORIGARGS[1]}" ]; then echo "Starting geth..." echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=0 " - ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=0 + ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 else echo "Starting geth..." echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=0 &>/dev/null &" - ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=0 &>/dev/null & + ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 &>/dev/null & echo "Waiting for geth..." npx wait-port "$WEB3_SYSTEM_TEST_PORT" fi From ca05bffee36b2187c3d5afa30431020f64433ca9 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 8 Feb 2023 15:10:45 -0500 Subject: [PATCH 03/22] remove debug logs --- packages/web3-eth-contract/src/contract.ts | 3 +-- .../test/integration/contract_deploy.test.ts | 22 +++++++++---------- .../local_account/contract_deploy.test.ts | 11 ++++------ packages/web3-eth/src/rpc_method_wrappers.ts | 3 +-- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index 5766553d3c9..c7081683107 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -1076,10 +1076,9 @@ export class Contract options, contractOptions: modifiedContractOptions, }); - console.log("transaction contract method deploy send") + return sendTransaction(this, tx, DEFAULT_RETURN_FORMAT, { transactionResolver: receipt => { - console.log(tx) if (receipt.status === BigInt(0)) { throw new Web3ContractError("code couldn't be stored", receipt); } diff --git a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts index 108d467026a..34dc76ca3bf 100644 --- a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts @@ -148,7 +148,7 @@ describe('contract', () => { it('should emit the "confirmation" event', async () => { const confirmationHandler = jest.fn(); - console.log("first confirmation deploy conract") + await contract .deploy(deployOptions) .send(sendOptions) @@ -159,32 +159,30 @@ describe('contract', () => { // Deploy once again to trigger block mining to trigger confirmation // We can send any other transaction as well - console.log("before deploying second contract") + await contract.deploy(deployOptions).send(sendOptions); - console.log("after deploy"); + // Wait for some fraction of time to trigger the handler // On http we use polling to get confirmation, so wait a bit longer - console.log("before sleep"); + await sleep(isWs ? 500 : 2000); - console.log("after sleep"); + // eslint-disable-next-line jest/no-standalone-expect expect(confirmationHandler).toHaveBeenCalled(); }); it('should emit the "transactionHash" event', async () => { const handler = jest.fn(); - console.log("before first deploy") + const promiEvent = contract .deploy(deployOptions) - .send(sendOptions) - .on('transactionHash', handler) - .on('sending', () => { console.log("sending event ")}) - .on('sent', ()=> {console.log("transaction has been sent")}); + .send(sendOptions) + .on('transactionHash', handler); // Deploy the contract - console.log("before promievent") + await promiEvent; - console.log("after promievent"); + expect(handler).toHaveBeenCalled(); }); diff --git a/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts b/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts index ffeddcb877b..c558842998a 100644 --- a/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts +++ b/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts @@ -118,7 +118,7 @@ describe('contract', () => { it('should emit the "confirmation" event', async () => { const confirmationHandler = jest.fn(); - console.log("account before deploy"); + await contract .deploy(deployOptions) .send(sendOptions) @@ -128,7 +128,7 @@ describe('contract', () => { // Deploy once again to trigger block mining to trigger confirmation // We can send any other transaction as well - console.log("before second deploy") + await contract.deploy(deployOptions).send(sendOptions); // Wait for some fraction of time to trigger the handler @@ -141,17 +141,14 @@ describe('contract', () => { it('should emit the "transactionHash" event', async () => { const handler = jest.fn(); - console.log("account before deploy using promievent") + const promiEvent = contract .deploy(deployOptions) .send(sendOptions) - .on('transactionHash', handler) - .on('sending', () => { console.log("sending event ")}) - .on('sent', ()=> {console.log("transaction has been sent")}); + .on('transactionHash', handler); // Deploy the contract await promiEvent; - console.log("after account promievent"); expect(handler).toHaveBeenCalled(); }); diff --git a/packages/web3-eth/src/rpc_method_wrappers.ts b/packages/web3-eth/src/rpc_method_wrappers.ts index 0e130a78dfc..4df1abfccc2 100644 --- a/packages/web3-eth/src/rpc_method_wrappers.ts +++ b/packages/web3-eth/src/rpc_method_wrappers.ts @@ -1111,7 +1111,7 @@ export function sendTransaction< if (promiEvent.listenerCount('sending') > 0) { promiEvent.emit('sending', transactionFormatted); } - + let transactionHash: HexString; let wallet: Web3BaseWalletAccount | undefined; @@ -1143,7 +1143,6 @@ export function sendTransaction< ), ); } - console.log("transaction hash ",transactionHash); const transactionHashFormatted = format( { eth: 'bytes32' }, From 17367771dbecfcf05c2796128757d32ecf9c082f Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 9 Feb 2023 14:20:46 -0500 Subject: [PATCH 04/22] update changelog --- packages/web3-eth-contract/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index 7c165a0eeb5..3d52c0be274 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -218,7 +218,8 @@ const transactionHash = receipt.transactionHash; ### Fixed -- Fix contract defaults (#5756) +- Fixex contract defaults (#5756) +- Fixed getPastEvents Error (#5819) ### Changed From c890db93a00054b5485b97ea2df829eee5ca9b66 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 9 Feb 2023 14:44:45 -0500 Subject: [PATCH 05/22] format and spelling fixes --- packages/web3-eth-contract/CHANGELOG.md | 2 +- .../web3-eth-contract/test/integration/contract_deploy.test.ts | 3 --- .../test/integration/local_account/contract_deploy.test.ts | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index 3d52c0be274..f52e16c39d4 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -218,7 +218,7 @@ const transactionHash = receipt.transactionHash; ### Fixed -- Fixex contract defaults (#5756) +- Fixed contract defaults (#5756) - Fixed getPastEvents Error (#5819) ### Changed diff --git a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts index 34dc76ca3bf..f89008d7b95 100644 --- a/packages/web3-eth-contract/test/integration/contract_deploy.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_deploy.test.ts @@ -159,12 +159,10 @@ describe('contract', () => { // Deploy once again to trigger block mining to trigger confirmation // We can send any other transaction as well - await contract.deploy(deployOptions).send(sendOptions); // Wait for some fraction of time to trigger the handler // On http we use polling to get confirmation, so wait a bit longer - await sleep(isWs ? 500 : 2000); // eslint-disable-next-line jest/no-standalone-expect @@ -180,7 +178,6 @@ describe('contract', () => { .on('transactionHash', handler); // Deploy the contract - await promiEvent; expect(handler).toHaveBeenCalled(); diff --git a/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts b/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts index c558842998a..5a8cb21c34a 100644 --- a/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts +++ b/packages/web3-eth-contract/test/integration/local_account/contract_deploy.test.ts @@ -123,12 +123,12 @@ describe('contract', () => { .deploy(deployOptions) .send(sendOptions) .on('confirmation', confirmationHandler); + // Wait for sometime to allow the transaction to be processed await sleep(500); // Deploy once again to trigger block mining to trigger confirmation // We can send any other transaction as well - await contract.deploy(deployOptions).send(sendOptions); // Wait for some fraction of time to trigger the handler From 59da4f6008e36c02bacee69c9b0feb4c9f5c0344 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 13 Feb 2023 12:42:19 -0500 Subject: [PATCH 06/22] adding mine to echo --- scripts/geth.sh | 4 ++-- scripts/geth_binary.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/geth.sh b/scripts/geth.sh index 927af8fd748..2f810b2e1b2 100755 --- a/scripts/geth.sh +++ b/scripts/geth.sh @@ -12,11 +12,11 @@ start() { if [ -z "${ORIGARGS[1]}" ] then echo "Starting geth..." - echo "docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" + echo "docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine" docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine else echo "Starting geth..." - echo "docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" + echo "docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine" docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine echo "Waiting for geth..." npx wait-port -t 10000 "$WEB3_SYSTEM_TEST_PORT" diff --git a/scripts/geth_binary.sh b/scripts/geth_binary.sh index 1d9117641d7..ca4270ff838 100755 --- a/scripts/geth_binary.sh +++ b/scripts/geth_binary.sh @@ -59,11 +59,11 @@ start() { download if [ -z "${ORIGARGS[1]}" ]; then echo "Starting geth..." - echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=0 " + echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 " ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 else echo "Starting geth..." - echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=0 &>/dev/null &" + echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 &>/dev/null &" ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 &>/dev/null & echo "Waiting for geth..." npx wait-port -t 10000 "$WEB3_SYSTEM_TEST_PORT" From cd726d6e1bf853f2d326a748a7f41e4ab0599dd9 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 21 Feb 2023 09:06:23 -0500 Subject: [PATCH 07/22] remove mine flag --- scripts/geth.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/geth.sh b/scripts/geth.sh index 2f810b2e1b2..df7731a57d6 100755 --- a/scripts/geth.sh +++ b/scripts/geth.sh @@ -12,12 +12,12 @@ start() { if [ -z "${ORIGARGS[1]}" ] then echo "Starting geth..." - echo "docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine" - docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine + echo "docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" + docker run -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev else echo "Starting geth..." - echo "docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine" - docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine + echo "docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev" + docker run -d -p $WEB3_SYSTEM_TEST_PORT:$WEB3_SYSTEM_TEST_PORT ethereum/client-go:stable --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev echo "Waiting for geth..." npx wait-port -t 10000 "$WEB3_SYSTEM_TEST_PORT" echo "Geth started" From 86ee31ed61f65eb81056cfa48df284b5776dfe03 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Wed, 22 Feb 2023 17:40:48 -0500 Subject: [PATCH 08/22] fix disconnect function --- packages/web3-utils/src/socket_provider.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/web3-utils/src/socket_provider.ts b/packages/web3-utils/src/socket_provider.ts index 9e94b7f20ef..643424d6edd 100644 --- a/packages/web3-utils/src/socket_provider.ts +++ b/packages/web3-utils/src/socket_provider.ts @@ -216,11 +216,12 @@ export abstract class SocketProvider< * @param data - The data to be sent to the server */ public disconnect(code?: number, data?: string): void { + const disconnectCode = code ?? 1000; this._removeSocketListeners(); if (this.getStatus() !== 'disconnected') { - this._closeSocketConnection(code, data); + this._closeSocketConnection(disconnectCode, data); } - this._onDisconnect(code, data); + this._onDisconnect(disconnectCode, data); } /** From 8cdb6f7fa73c36c1543432c42e848613e76699c9 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 23 Feb 2023 10:39:01 -0500 Subject: [PATCH 09/22] add link --- packages/web3-utils/src/socket_provider.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/web3-utils/src/socket_provider.ts b/packages/web3-utils/src/socket_provider.ts index 643424d6edd..7c5fcda3287 100644 --- a/packages/web3-utils/src/socket_provider.ts +++ b/packages/web3-utils/src/socket_provider.ts @@ -55,6 +55,8 @@ type ReconnectOptions = { type EventType = 'message' | 'connect' | 'disconnect' | 'chainChanged' | 'accountsChanged' | string; +const NORMAL_CLOSE_CODE = 1000; // https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close + export abstract class SocketProvider< MessageEvent, CloseEvent, @@ -216,7 +218,7 @@ export abstract class SocketProvider< * @param data - The data to be sent to the server */ public disconnect(code?: number, data?: string): void { - const disconnectCode = code ?? 1000; + const disconnectCode = code ?? NORMAL_CLOSE_CODE; this._removeSocketListeners(); if (this.getStatus() !== 'disconnected') { this._closeSocketConnection(disconnectCode, data); From 5fb3c814fe1186cbda4295dccb535019cf642c31 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 23 Feb 2023 11:25:02 -0500 Subject: [PATCH 10/22] test types --- packages/web3-core/src/web3_context.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/web3-core/src/web3_context.ts b/packages/web3-core/src/web3_context.ts index 1c749c06845..f2bbae024bf 100644 --- a/packages/web3-core/src/web3_context.ts +++ b/packages/web3-core/src/web3_context.ts @@ -23,6 +23,7 @@ import { SupportedProviders, HexString, EthExecutionAPI, + Web3BaseProvider, } from 'web3-types'; import { isNullish } from 'web3-utils'; import { ExistingPluginNamespaceError } from 'web3-errors'; @@ -310,8 +311,8 @@ export class Web3Context< * } * ``` */ - public get currentProvider(): SupportedProviders | string | undefined { - return this.requestManager.provider; + public get currentProvider(): Web3BaseProvider | undefined { + return this.requestManager.provider as Web3BaseProvider; } /** From bccda0eb3f470794032918ff549d7c33ec12c431 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 23 Feb 2023 13:33:06 -0500 Subject: [PATCH 11/22] add disconnect function test --- packages/web3-core/src/web3_context.ts | 4 ++-- packages/web3/test/integration/web3.test.ts | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/web3-core/src/web3_context.ts b/packages/web3-core/src/web3_context.ts index f2bbae024bf..1bde6a502bb 100644 --- a/packages/web3-core/src/web3_context.ts +++ b/packages/web3-core/src/web3_context.ts @@ -269,8 +269,8 @@ export class Web3Context< * ``` */ - public get provider(): SupportedProviders | string | undefined { - return this.requestManager.provider; + public get provider(): Web3BaseProvider | undefined { + return this.currentProvider; } /** diff --git a/packages/web3/test/integration/web3.test.ts b/packages/web3/test/integration/web3.test.ts index c831cbd164a..9d89f5a899c 100644 --- a/packages/web3/test/integration/web3.test.ts +++ b/packages/web3/test/integration/web3.test.ts @@ -19,7 +19,7 @@ import { JsonRpcOptionalRequest, Web3BaseProvider, SupportedProviders } from 'we import Contract from 'web3-eth-contract'; import HttpProvider from 'web3-providers-http'; import IpcProvider from 'web3-providers-ipc'; -import WebsocketProvider from 'web3-providers-ws'; +import WebSocketProvider from 'web3-providers-ws'; import Web3 from '../../src/index'; import { BasicAbi } from '../shared_fixtures/Basic'; import { validEncodeParametersData } from '../shared_fixtures/data'; @@ -32,6 +32,7 @@ import { isIpc, isWs, waitForOpenConnection, + isSocket, } from '../shared_fixtures/system_tests_utils'; import { GreeterAbi, GreeterBytecode } from '../shared_fixtures/build/Greeter'; @@ -75,6 +76,18 @@ describe('Web3 instance', () => { expect(() => new Web3()).not.toThrow(); }); + it('check disconnect function', async () => { + const web3Instance = new Web3(clientUrl); + await web3Instance.eth.getBlockNumber(); + expect(typeof web3Instance.provider?.disconnect).toBe('function'); + expect(typeof web3Instance.eth.provider?.disconnect).toBe('function'); + expect(typeof web3Instance.currentProvider?.disconnect).toBe('function'); + expect(typeof web3Instance.eth.currentProvider?.disconnect).toBe('function'); + if (isSocket) { + web3Instance.currentProvider?.disconnect(); + } + }); + it('should be able use "utils" without provider', () => { web3 = new Web3(); @@ -179,7 +192,7 @@ describe('Web3 instance', () => { const res = Web3.providers; expect(Web3.providers.HttpProvider).toBe(HttpProvider); - expect(res.WebsocketProvider).toBe(WebsocketProvider); + expect(res.WebsocketProvider).toBe(WebSocketProvider); expect(res.IpcProvider).toBe(IpcProvider); }); From f55b123bfd2af85d4807ea19e1a3d7436af09f7f Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 23 Feb 2023 14:09:18 -0500 Subject: [PATCH 12/22] fix eth tests --- packages/web3-eth/test/integration/defaults.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/web3-eth/test/integration/defaults.test.ts b/packages/web3-eth/test/integration/defaults.test.ts index 089729c40c8..11fdbc8011b 100644 --- a/packages/web3-eth/test/integration/defaults.test.ts +++ b/packages/web3-eth/test/integration/defaults.test.ts @@ -543,8 +543,7 @@ describe('defaults', () => { // It will cause providers that does not support subscriptions (like http) to throw exception when subscribing. // This case is tested to ensure that even if an error happen at subscription, // polling will still get the data from next blocks. - (tempEth.provider as Web3BaseProvider>).supportsSubscriptions = - () => true; + (tempEth.provider as Web3BaseProvider).supportsSubscriptions = () => true; // Cause the events to take a long time (more than blockHeaderTimeout), // to ensure that polling of new blocks works in such cases. @@ -552,7 +551,7 @@ describe('defaults', () => { // to never return data through listening to new events // eslint-disable-next-line @typescript-eslint/no-misused-promises - (tempEth.provider as Web3BaseProvider>).on = async () => { + (tempEth.provider as Web3BaseProvider).on = async () => { await new Promise(res => { setTimeout(res, 1000000); }); From f96118a57a112e3a254f5a5aa1c39f9d723e7bb5 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 23 Feb 2023 23:31:46 -0500 Subject: [PATCH 13/22] use dev period --- scripts/geth_binary.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/geth_binary.sh b/scripts/geth_binary.sh index ca4270ff838..5c5e67c1959 100755 --- a/scripts/geth_binary.sh +++ b/scripts/geth_binary.sh @@ -60,11 +60,11 @@ start() { if [ -z "${ORIGARGS[1]}" ]; then echo "Starting geth..." echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 " - ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 + ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=100 else echo "Starting geth..." echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 &>/dev/null &" - ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 &>/dev/null & + ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=100 &>/dev/null & echo "Waiting for geth..." npx wait-port -t 10000 "$WEB3_SYSTEM_TEST_PORT" fi From 9a3bed107a780321d9e20c8d05385bd1416caef2 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Fri, 24 Feb 2023 11:25:33 -0500 Subject: [PATCH 14/22] test stuck --- packages/web3-providers-ws/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-providers-ws/package.json b/packages/web3-providers-ws/package.json index 6dc904c0156..5f176747206 100644 --- a/packages/web3-providers-ws/package.json +++ b/packages/web3-providers-ws/package.json @@ -23,7 +23,7 @@ "format": "prettier --write '**/*'", "test": "jest --config=./test/unit/jest.config.js", "test:coverage:unit": "jest --config=./test/unit/jest.config.js --coverage=true --coverage-reporters=text", - "test:coverage:integration": "jest --config=./test/integration/jest.config.js --coverage=true --coverage-reporters=text", + "test:coverage:integration": "jest --config=./test/integration/jest.config.js --coverage=true --coverage-reporters=text --forceExit", "test:ci": "jest --coverage=true --coverage-reporters=json --verbose", "test:watch": "npm test -- --watch", "test:unit": "jest --config=./test/unit/jest.config.js", From 00e6026c23db05d9d4f3e3bb9ccae380ab289dee Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Fri, 24 Feb 2023 11:51:45 -0500 Subject: [PATCH 15/22] trace --- .../test/integration/reconnection.test.ts | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/web3-providers-ws/test/integration/reconnection.test.ts b/packages/web3-providers-ws/test/integration/reconnection.test.ts index 34fd0749039..ec8418e7fc3 100644 --- a/packages/web3-providers-ws/test/integration/reconnection.test.ts +++ b/packages/web3-providers-ws/test/integration/reconnection.test.ts @@ -85,37 +85,42 @@ describeIf(isWs && !isBrowser)('WebSocketProvider - reconnection', () => { expect(!!(await disconnectPromise)).toBe(true); }); it('should connect, disconnect and reconnect', async () => { + // eslint-disable-next-line no-console + console.log('1'); const server = await createProxy(18546, getSystemTestProvider()); + // eslint-disable-next-line no-console + console.log('2'); const web3Provider = new WebSocketProvider(server.path, {}, reconnectionOptions); - + // eslint-disable-next-line no-console + console.log('3'); expect(!!(await waitForEvent(web3Provider, 'connect'))).toBe(true); - - // @ts-expect-error-next-line - // eslint-disable-next-line @typescript-eslint/no-unused-vars - web3Provider._onCloseHandler = (_: CloseEvent) => { - // @ts-expect-error-next-line - web3Provider._onCloseEvent({ code: 1002 }); - }; - // @ts-expect-error-next-line - web3Provider._removeSocketListeners(); - // @ts-expect-error-next-line - web3Provider._addSocketListeners(); + // eslint-disable-next-line no-console + console.log('4'); + web3Provider.disconnect(1002); + // eslint-disable-next-line no-console + console.log('5'); await server.close(); + // eslint-disable-next-line no-console + console.log('6'); const connectEvent = waitForEvent(web3Provider, 'connect'); + // eslint-disable-next-line no-console + console.log('7'); const server2 = await createProxy(18546, getSystemTestProvider()); + // eslint-disable-next-line no-console + console.log('8'); expect(!!(await connectEvent)).toBe(true); - // @ts-expect-error-next-line - web3Provider._onCloseHandler = (event: CloseEvent) => { - // @ts-expect-error-next-line - web3Provider._onCloseEvent(event); - }; - // @ts-expect-error-next-line - web3Provider._removeSocketListeners(); - // @ts-expect-error-next-line - web3Provider._addSocketListeners(); - web3Provider.disconnect(1000, 'test'); + // eslint-disable-next-line no-console + console.log('9'); + + web3Provider.disconnect(); + // eslint-disable-next-line no-console + console.log('10'); await waitForEvent(web3Provider, 'disconnect'); + // eslint-disable-next-line no-console + console.log('11'); await server2.close(); + // eslint-disable-next-line no-console + console.log('12'); }); it('should connect, disconnect, try reconnect and reach max attempts', async () => { const server = await createProxy(18547, getSystemTestProvider()); From fed2aab61339d3e8225db9a4dd5dea9b8ce05e29 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Fri, 24 Feb 2023 12:02:25 -0500 Subject: [PATCH 16/22] fix --- packages/web3-providers-ws/test/fixtures/proxy.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/web3-providers-ws/test/fixtures/proxy.ts b/packages/web3-providers-ws/test/fixtures/proxy.ts index db883eeb6d9..37747506647 100644 --- a/packages/web3-providers-ws/test/fixtures/proxy.ts +++ b/packages/web3-providers-ws/test/fixtures/proxy.ts @@ -48,14 +48,22 @@ export const createProxy = async ( }); closeFunc = async () => { await new Promise(resolve => { + const timeOut = setTimeout(() => { + resolve(true); + }, 2000); ws.on('close', () => { ws.removeAllListeners(); + clearTimeout(timeOut); resolve(true); }); ws.terminate(); }); await new Promise(resolve => { + const timeOut = setTimeout(() => { + resolve(true); + }, 2000); originWs.on('close', () => { + clearTimeout(timeOut); originWs.removeAllListeners(); resolve(true); }); From a5d9e6f45e83a91854fc17b78206bcb96c73bda1 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Fri, 24 Feb 2023 12:03:19 -0500 Subject: [PATCH 17/22] check --- packages/web3-providers-ws/test/fixtures/proxy.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/web3-providers-ws/test/fixtures/proxy.ts b/packages/web3-providers-ws/test/fixtures/proxy.ts index 37747506647..4d68ac7a954 100644 --- a/packages/web3-providers-ws/test/fixtures/proxy.ts +++ b/packages/web3-providers-ws/test/fixtures/proxy.ts @@ -49,6 +49,8 @@ export const createProxy = async ( closeFunc = async () => { await new Promise(resolve => { const timeOut = setTimeout(() => { + // eslint-disable-next-line no-console + console.log('timeout1'); resolve(true); }, 2000); ws.on('close', () => { @@ -60,6 +62,8 @@ export const createProxy = async ( }); await new Promise(resolve => { const timeOut = setTimeout(() => { + // eslint-disable-next-line no-console + console.log('timeout2'); resolve(true); }, 2000); originWs.on('close', () => { From 47131288b5f5db008a9a22275178807fd88f25ad Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Fri, 24 Feb 2023 12:13:42 -0500 Subject: [PATCH 18/22] fix test --- packages/web3-providers-ws/package.json | 2 +- .../test/integration/reconnection.test.ts | 24 ------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/packages/web3-providers-ws/package.json b/packages/web3-providers-ws/package.json index 5f176747206..6dc904c0156 100644 --- a/packages/web3-providers-ws/package.json +++ b/packages/web3-providers-ws/package.json @@ -23,7 +23,7 @@ "format": "prettier --write '**/*'", "test": "jest --config=./test/unit/jest.config.js", "test:coverage:unit": "jest --config=./test/unit/jest.config.js --coverage=true --coverage-reporters=text", - "test:coverage:integration": "jest --config=./test/integration/jest.config.js --coverage=true --coverage-reporters=text --forceExit", + "test:coverage:integration": "jest --config=./test/integration/jest.config.js --coverage=true --coverage-reporters=text", "test:ci": "jest --coverage=true --coverage-reporters=json --verbose", "test:watch": "npm test -- --watch", "test:unit": "jest --config=./test/unit/jest.config.js", diff --git a/packages/web3-providers-ws/test/integration/reconnection.test.ts b/packages/web3-providers-ws/test/integration/reconnection.test.ts index ec8418e7fc3..629e1d1d3dd 100644 --- a/packages/web3-providers-ws/test/integration/reconnection.test.ts +++ b/packages/web3-providers-ws/test/integration/reconnection.test.ts @@ -85,42 +85,18 @@ describeIf(isWs && !isBrowser)('WebSocketProvider - reconnection', () => { expect(!!(await disconnectPromise)).toBe(true); }); it('should connect, disconnect and reconnect', async () => { - // eslint-disable-next-line no-console - console.log('1'); const server = await createProxy(18546, getSystemTestProvider()); - // eslint-disable-next-line no-console - console.log('2'); const web3Provider = new WebSocketProvider(server.path, {}, reconnectionOptions); - // eslint-disable-next-line no-console - console.log('3'); expect(!!(await waitForEvent(web3Provider, 'connect'))).toBe(true); - // eslint-disable-next-line no-console - console.log('4'); web3Provider.disconnect(1002); - // eslint-disable-next-line no-console - console.log('5'); await server.close(); - // eslint-disable-next-line no-console - console.log('6'); const connectEvent = waitForEvent(web3Provider, 'connect'); - // eslint-disable-next-line no-console - console.log('7'); const server2 = await createProxy(18546, getSystemTestProvider()); - // eslint-disable-next-line no-console - console.log('8'); expect(!!(await connectEvent)).toBe(true); - // eslint-disable-next-line no-console - console.log('9'); web3Provider.disconnect(); - // eslint-disable-next-line no-console - console.log('10'); await waitForEvent(web3Provider, 'disconnect'); - // eslint-disable-next-line no-console - console.log('11'); await server2.close(); - // eslint-disable-next-line no-console - console.log('12'); }); it('should connect, disconnect, try reconnect and reach max attempts', async () => { const server = await createProxy(18547, getSystemTestProvider()); From 73134b2f6a03a0ac2cab517fb641a1dc5e791433 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Fri, 24 Feb 2023 13:45:13 -0500 Subject: [PATCH 19/22] add empty disconnect function --- packages/web3-providers-http/src/index.ts | 2 +- packages/web3/test/integration/web3.test.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/web3-providers-http/src/index.ts b/packages/web3-providers-http/src/index.ts index e4d56d471d7..144119944d1 100644 --- a/packages/web3-providers-http/src/index.ts +++ b/packages/web3-providers-http/src/index.ts @@ -112,7 +112,7 @@ export default class HttpProvider< /* eslint-disable class-methods-use-this */ public disconnect() { - throw new MethodNotImplementedError(); + // NO OP } /* eslint-disable class-methods-use-this */ diff --git a/packages/web3/test/integration/web3.test.ts b/packages/web3/test/integration/web3.test.ts index 9d89f5a899c..7a9b2c94105 100644 --- a/packages/web3/test/integration/web3.test.ts +++ b/packages/web3/test/integration/web3.test.ts @@ -32,7 +32,6 @@ import { isIpc, isWs, waitForOpenConnection, - isSocket, } from '../shared_fixtures/system_tests_utils'; import { GreeterAbi, GreeterBytecode } from '../shared_fixtures/build/Greeter'; @@ -83,9 +82,7 @@ describe('Web3 instance', () => { expect(typeof web3Instance.eth.provider?.disconnect).toBe('function'); expect(typeof web3Instance.currentProvider?.disconnect).toBe('function'); expect(typeof web3Instance.eth.currentProvider?.disconnect).toBe('function'); - if (isSocket) { - web3Instance.currentProvider?.disconnect(); - } + web3Instance.currentProvider?.disconnect(); }); it('should be able use "utils" without provider', () => { From 18d1c1f1c9e332edafba6d75dbdafef302b23f0c Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 24 Feb 2023 15:40:48 -0500 Subject: [PATCH 20/22] update mine --- scripts/geth_binary.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/geth_binary.sh b/scripts/geth_binary.sh index 5c5e67c1959..58a9b17739a 100755 --- a/scripts/geth_binary.sh +++ b/scripts/geth_binary.sh @@ -64,7 +64,7 @@ start() { else echo "Starting geth..." echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 &>/dev/null &" - ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=100 &>/dev/null & + ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=100 &>/dev/null & echo "Waiting for geth..." npx wait-port -t 10000 "$WEB3_SYSTEM_TEST_PORT" fi From c93802d133ff5e317baba1588767892e1b1a7a14 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 25 Feb 2023 23:04:30 -0500 Subject: [PATCH 21/22] add back mine --- scripts/geth_binary.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/geth_binary.sh b/scripts/geth_binary.sh index 58a9b17739a..ca4270ff838 100755 --- a/scripts/geth_binary.sh +++ b/scripts/geth_binary.sh @@ -60,11 +60,11 @@ start() { if [ -z "${ORIGARGS[1]}" ]; then echo "Starting geth..." echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 " - ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=100 + ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 else echo "Starting geth..." echo "geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 &>/dev/null &" - ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --dev.period=100 &>/dev/null & + ${TMP_FOLDER}/geth --ipcpath $IPC_PATH --nodiscover --nousb --ws --ws.addr 0.0.0.0 --ws.port $WEB3_SYSTEM_TEST_PORT --http --http.addr 0.0.0.0 --http.port $WEB3_SYSTEM_TEST_PORT --allow-insecure-unlock --http.api personal,web3,eth,admin,debug,txpool,net --ws.api personal,web3,eth,admin,debug,miner,txpool,net --dev --mine --dev.period=0 &>/dev/null & echo "Waiting for geth..." npx wait-port -t 10000 "$WEB3_SYSTEM_TEST_PORT" fi From 3aa5fe31eae9fbc38178466e9b1af577835f07dd Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 26 Feb 2023 23:57:34 -0500 Subject: [PATCH 22/22] Revert "Merge branch 'ok/5864-Disconnect-function-doesn't-exists-in-types-of-currentProvider-' into 5634/alex" This reverts commit b4f9b521a0945c22306d93cb25c14a30b04e19de, reversing changes made to 18d1c1f1c9e332edafba6d75dbdafef302b23f0c. --- packages/web3-core/src/web3_context.ts | 9 +- .../test/integration/defaults.test.ts | 5 +- packages/web3-providers-http/src/index.ts | 2 +- .../web3-providers-ws/test/fixtures/proxy.ts | 2 - .../test/integration/reconnection.test.ts | 25 ++- packages/web3-utils/src/converters.ts | 160 +----------------- packages/web3-utils/src/formatter.ts | 28 +-- packages/web3-utils/src/hash.ts | 67 +------- packages/web3-utils/src/objects.ts | 6 - packages/web3-utils/src/promise_helpers.ts | 30 +--- packages/web3-utils/src/random.ts | 15 -- packages/web3-utils/src/socket_provider.ts | 50 +----- .../web3-utils/src/string_manipulation.ts | 52 ------ packages/web3-utils/src/uuid.ts | 6 - packages/web3-utils/src/validation.ts | 14 +- .../web3-utils/src/web3_deferred_promise.ts | 46 +---- .../web3-utils/src/web3_eip1193_provider.ts | 3 - packages/web3/test/integration/web3.test.ts | 14 +- 18 files changed, 48 insertions(+), 486 deletions(-) diff --git a/packages/web3-core/src/web3_context.ts b/packages/web3-core/src/web3_context.ts index 1bde6a502bb..1c749c06845 100644 --- a/packages/web3-core/src/web3_context.ts +++ b/packages/web3-core/src/web3_context.ts @@ -23,7 +23,6 @@ import { SupportedProviders, HexString, EthExecutionAPI, - Web3BaseProvider, } from 'web3-types'; import { isNullish } from 'web3-utils'; import { ExistingPluginNamespaceError } from 'web3-errors'; @@ -269,8 +268,8 @@ export class Web3Context< * ``` */ - public get provider(): Web3BaseProvider | undefined { - return this.currentProvider; + public get provider(): SupportedProviders | string | undefined { + return this.requestManager.provider; } /** @@ -311,8 +310,8 @@ export class Web3Context< * } * ``` */ - public get currentProvider(): Web3BaseProvider | undefined { - return this.requestManager.provider as Web3BaseProvider; + public get currentProvider(): SupportedProviders | string | undefined { + return this.requestManager.provider; } /** diff --git a/packages/web3-eth/test/integration/defaults.test.ts b/packages/web3-eth/test/integration/defaults.test.ts index 11fdbc8011b..089729c40c8 100644 --- a/packages/web3-eth/test/integration/defaults.test.ts +++ b/packages/web3-eth/test/integration/defaults.test.ts @@ -543,7 +543,8 @@ describe('defaults', () => { // It will cause providers that does not support subscriptions (like http) to throw exception when subscribing. // This case is tested to ensure that even if an error happen at subscription, // polling will still get the data from next blocks. - (tempEth.provider as Web3BaseProvider).supportsSubscriptions = () => true; + (tempEth.provider as Web3BaseProvider>).supportsSubscriptions = + () => true; // Cause the events to take a long time (more than blockHeaderTimeout), // to ensure that polling of new blocks works in such cases. @@ -551,7 +552,7 @@ describe('defaults', () => { // to never return data through listening to new events // eslint-disable-next-line @typescript-eslint/no-misused-promises - (tempEth.provider as Web3BaseProvider).on = async () => { + (tempEth.provider as Web3BaseProvider>).on = async () => { await new Promise(res => { setTimeout(res, 1000000); }); diff --git a/packages/web3-providers-http/src/index.ts b/packages/web3-providers-http/src/index.ts index 144119944d1..e4d56d471d7 100644 --- a/packages/web3-providers-http/src/index.ts +++ b/packages/web3-providers-http/src/index.ts @@ -112,7 +112,7 @@ export default class HttpProvider< /* eslint-disable class-methods-use-this */ public disconnect() { - // NO OP + throw new MethodNotImplementedError(); } /* eslint-disable class-methods-use-this */ diff --git a/packages/web3-providers-ws/test/fixtures/proxy.ts b/packages/web3-providers-ws/test/fixtures/proxy.ts index 37747506647..071fbd9ed02 100644 --- a/packages/web3-providers-ws/test/fixtures/proxy.ts +++ b/packages/web3-providers-ws/test/fixtures/proxy.ts @@ -53,7 +53,6 @@ export const createProxy = async ( }, 2000); ws.on('close', () => { ws.removeAllListeners(); - clearTimeout(timeOut); resolve(true); }); ws.terminate(); @@ -63,7 +62,6 @@ export const createProxy = async ( resolve(true); }, 2000); originWs.on('close', () => { - clearTimeout(timeOut); originWs.removeAllListeners(); resolve(true); }); diff --git a/packages/web3-providers-ws/test/integration/reconnection.test.ts b/packages/web3-providers-ws/test/integration/reconnection.test.ts index 629e1d1d3dd..34fd0749039 100644 --- a/packages/web3-providers-ws/test/integration/reconnection.test.ts +++ b/packages/web3-providers-ws/test/integration/reconnection.test.ts @@ -87,14 +87,33 @@ describeIf(isWs && !isBrowser)('WebSocketProvider - reconnection', () => { it('should connect, disconnect and reconnect', async () => { const server = await createProxy(18546, getSystemTestProvider()); const web3Provider = new WebSocketProvider(server.path, {}, reconnectionOptions); + expect(!!(await waitForEvent(web3Provider, 'connect'))).toBe(true); - web3Provider.disconnect(1002); + + // @ts-expect-error-next-line + // eslint-disable-next-line @typescript-eslint/no-unused-vars + web3Provider._onCloseHandler = (_: CloseEvent) => { + // @ts-expect-error-next-line + web3Provider._onCloseEvent({ code: 1002 }); + }; + // @ts-expect-error-next-line + web3Provider._removeSocketListeners(); + // @ts-expect-error-next-line + web3Provider._addSocketListeners(); await server.close(); const connectEvent = waitForEvent(web3Provider, 'connect'); const server2 = await createProxy(18546, getSystemTestProvider()); expect(!!(await connectEvent)).toBe(true); - - web3Provider.disconnect(); + // @ts-expect-error-next-line + web3Provider._onCloseHandler = (event: CloseEvent) => { + // @ts-expect-error-next-line + web3Provider._onCloseEvent(event); + }; + // @ts-expect-error-next-line + web3Provider._removeSocketListeners(); + // @ts-expect-error-next-line + web3Provider._addSocketListeners(); + web3Provider.disconnect(1000, 'test'); await waitForEvent(web3Provider, 'disconnect'); await server2.close(); }); diff --git a/packages/web3-utils/src/converters.ts b/packages/web3-utils/src/converters.ts index d097022155b..8343db42964 100644 --- a/packages/web3-utils/src/converters.ts +++ b/packages/web3-utils/src/converters.ts @@ -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]))); - * > - * ``` - */ + export const bytesToBuffer = (data: Bytes): Buffer | never => { validator.validate(['bytes'], [data]); @@ -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')); - * > - * ``` */ 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]); @@ -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]); @@ -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]); @@ -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'); @@ -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]); @@ -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'); @@ -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, @@ -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') { @@ -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') { @@ -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]; @@ -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]); @@ -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); diff --git a/packages/web3-utils/src/formatter.ts b/packages/web3-utils/src/formatter.ts index c3d3db2bbc6..8c20cc0e96a 100644 --- a/packages/web3-utils/src/formatter.ts +++ b/packages/web3-utils/src/formatter.ts @@ -72,16 +72,6 @@ export type FormatType = number extends Extract { try { const { baseType } = parseBaseType(ethType); @@ -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 | unknown[] | unknown, schema: JsonSchema, diff --git a/packages/web3-utils/src/hash.ts b/packages/web3-utils/src/hash.ts index 5a00c1d51aa..d3bcf857984 100644 --- a/packages/web3-utils/src/hash.ts +++ b/packages/web3-utils/src/hash.ts @@ -49,17 +49,6 @@ const SHA3_EMPTY_BYTES = '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfa /** * computes the Keccak-256 hash of the input and returns a hexstring - * @param data - the input to hash - * @returns - the Keccak-256 hash of the input - * - * @example - * ```ts - * console.log(web3.utils.sha3('web3.js')); - * > 0x63667efb1961039c9bb0d6ea7a5abdd223a3aca7daa5044ad894226e1f83919a - * - * console.log(web3.utils.sha3('')); - * > undefined - * ``` */ export const sha3 = (data: Bytes): string | undefined => { const updatedData = typeof data === 'string' && isHexStrict(data) ? hexToBytes(data) : data; @@ -71,18 +60,7 @@ export const sha3 = (data: Bytes): string | undefined => { }; /** - * Will calculate the sha3 of the input but does return the hash value instead of null if for example a empty string is passed. - * @param data - the input to hash - * @returns - the Keccak-256 hash of the input - * - * @example - * ```ts - * conosle.log(web3.utils.sha3Raw('web3.js')); - * > 0x63667efb1961039c9bb0d6ea7a5abdd223a3aca7daa5044ad894226e1f83919a - * - * console.log(web3.utils.sha3Raw('')); - * > 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 - * ``` + *Will calculate the sha3 of the input but does return the hash value instead of null if for example a empty string is passed. */ export const sha3Raw = (data: Bytes): string => { const hash = sha3(data); @@ -95,20 +73,6 @@ export const sha3Raw = (data: Bytes): string => { /** * A wrapper for ethereum-cryptography/keccak256 to allow hashing a `string` and a `bigint` in addition to `UInt8Array` - * @param data - the input to hash - * @returns - the Keccak-256 hash of the input - * - * @example - * ```ts - * console.log(web3.utils.keccak256Wrapper('web3.js')); - * > 0x63667efb1961039c9bb0d6ea7a5abdd223a3aca7daa5044ad894226e1f83919a - * - * console.log(web3.utils.keccak256Wrapper(1)); - * > 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6 - * - * console.log(web3.utils.keccak256Wrapper(0xaf12fd)); - * > 0x358640fd4719fa923525d74ab5ae80a594301aba5543e3492b052bf4598b794c - * ``` */ export const keccak256Wrapper = ( data: Bytes | Numbers | string | ReadonlyArray, @@ -129,8 +93,6 @@ export { keccak256Wrapper as keccak256 }; /** * returns type and value - * @param arg - the input to return the type and value - * @returns - the type and value of the input */ const getType = (arg: Sha3Input): [string, EncodingTypes] => { if (Array.isArray(arg)) { @@ -170,8 +132,6 @@ const getType = (arg: Sha3Input): [string, EncodingTypes] => { /** * returns the type with size if uint or int - * @param name - the input to return the type with size - * @returns - the type with size of the input */ const elementaryName = (name: string): string => { if (name.startsWith('int[')) { @@ -199,8 +159,6 @@ const parseTypeN = (value: string, typeLength: number): number => { /** * returns the bit length of the value - * @param value - the input to return the bit length - * @returns - the bit length of the input */ const bitLength = (value: bigint | number): number => { const updatedVal = value.toString(2); @@ -210,8 +168,6 @@ const bitLength = (value: bigint | number): number => { /** * Pads the value based on size and type * returns a string of the padded value - * @param type - the input to pad - * @returns = the padded value */ const solidityPack = (type: string, val: EncodingTypes): string => { const value = val.toString(); @@ -289,8 +245,6 @@ const solidityPack = (type: string, val: EncodingTypes): string => { /** * returns a string of the tightly packed value given based on the type - * @param arg - the input to return the tightly packed value - * @returns - the tightly packed value */ export const processSolidityEncodePackedArgs = (arg: Sha3Input): string => { const [type, val] = getType(arg); @@ -318,15 +272,6 @@ export const encodePacked = (...values: Sha3Input[]): string => { /** * Will tightly pack values given in the same way solidity would then hash. * returns a hash string, or null if input is empty - * @param values - the input to return the tightly packed values - * @returns - the keccack246 of the tightly packed values - * - * @example - * ```ts - * console.log([{ type: 'string', value: '31323334' }]); - * console.log(web3.utils.soliditySha3({ type: "string", value: "31323334" })); - * > 0xf15f8da2ad27e486d632dc37d24912f634398918d6f9913a0a0ff84e388be62b - * ``` */ export const soliditySha3 = (...values: Sha3Input[]): string | undefined => sha3(encodePacked(...values)); @@ -334,14 +279,6 @@ export const soliditySha3 = (...values: Sha3Input[]): string | undefined => /** * Will tightly pack values given in the same way solidity would then hash. * returns a hash string, if input is empty will return `0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470` - * @param values - the input to return the tightly packed values - * @returns - the keccack246 of the tightly packed values - * - * @example - * ```ts - * console.log(web3.utils.soliditySha3Raw({ type: "string", value: "helloworld" })) - * > 0xfa26db7ca85ead399216e7c6316bc50ed24393c3122b582735e7f3b0f91b93f0 - * ``` */ export const soliditySha3Raw = (...values: TypedObject[] | TypedObjectAbbreviated[]): string => sha3Raw(encodePacked(...values)); @@ -349,8 +286,6 @@ export const soliditySha3Raw = (...values: TypedObject[] | TypedObjectAbbreviate /** * Get slot number for storage long string in contract. Basically for getStorage method * returns slotNumber where will data placed - * @param mainSlotNumber - the slot number where will be stored hash of long string - * @returns - the slot number where will be stored long string */ export const getStorageSlotNumForLongString = (mainSlotNumber: number | string) => sha3( diff --git a/packages/web3-utils/src/objects.ts b/packages/web3-utils/src/objects.ts index cc2a5e554e1..2680173c7d7 100644 --- a/packages/web3-utils/src/objects.ts +++ b/packages/web3-utils/src/objects.ts @@ -27,12 +27,6 @@ const isIterable = (item: unknown): item is Record => // The following code is a derivative work of the code from the "LiskHQ/lisk-sdk" project, // which is licensed under Apache version 2. -/** - * Deep merge two objects. - * @param destination - The destination object. - * @param sources - An array of source objects. - * @returns - The merged object. - */ export const mergeDeep = ( destination: Record, ...sources: Record[] diff --git a/packages/web3-utils/src/promise_helpers.ts b/packages/web3-utils/src/promise_helpers.ts index af9adefe840..18cb408ee67 100644 --- a/packages/web3-utils/src/promise_helpers.ts +++ b/packages/web3-utils/src/promise_helpers.ts @@ -45,9 +45,6 @@ export function waitWithTimeout( /** * Wait for a promise but interrupt it if it did not resolve within a given timeout. * If the timeout reached, before the promise code resolve, either throw an error if an error object was provided, or return `undefined`. - * @param awaitable - The promise or function to wait for. - * @param timeout - The timeout in milliseconds. - * @param error - (Optional) The error to throw if the timeout reached. */ export async function waitWithTimeout( awaitable: Promise | AsyncFunction, @@ -69,12 +66,7 @@ export async function waitWithTimeout( } 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. - * @param func - The function to call. - * @param interval - The interval in milliseconds. - */ + export async function pollTillDefined( func: AsyncFunction, interval: number, @@ -111,17 +103,7 @@ export async function pollTillDefined( return polledRes; } -/** - * Enforce a timeout on a promise, so that it can be rejected if it takes too long to complete - * @param timeout - The timeout to enforced in milliseconds. - * @param error - The error to throw if the timeout is reached. - * @returns A tuple of the timeout id and the promise that will be rejected if the timeout is reached. - * - * @example - * ```ts - * const [timerId, promise] = web3.utils.rejectIfTimeout(100, new Error('time out')); - * ``` - */ + export function rejectIfTimeout(timeout: number, error: Error): [NodeJS.Timer, Promise] { let timeoutId: NodeJS.Timer | undefined; const rejectOnTimeout = new Promise((_, reject) => { @@ -131,13 +113,7 @@ export function rejectIfTimeout(timeout: number, error: Error): [NodeJS.Timer, P }); return [timeoutId as unknown as NodeJS.Timer, rejectOnTimeout]; } -/** - * 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 interval - The interval in milliseconds. - * @returns - an array with the interval ID and the Promise. - */ + export function rejectIfConditionAtInterval( cond: AsyncFunction, interval: number, diff --git a/packages/web3-utils/src/random.ts b/packages/web3-utils/src/random.ts index eee5dd8d376..8a71ff5a352 100644 --- a/packages/web3-utils/src/random.ts +++ b/packages/web3-utils/src/random.ts @@ -19,14 +19,6 @@ import { randomBytes as cryptoRandomBytes } from 'crypto'; /** * Returns a random byte array by the given bytes size - * @param byteSize - The size of the random byte array returned - * @returns - random byte array - * - * @example - * ```ts - * console.log(web3.utils.randomBytes(32)); - * > - * ``` */ export const randomBytes = (byteSize: number): Buffer => { const randomValues = @@ -38,12 +30,5 @@ export const randomBytes = (byteSize: number): Buffer => { /** * Returns a random hex string by the given bytes size - * @param byteSize - The size of the random hex string returned - * @returns - random hex string - * - * ```ts - * console.log(web3.utils.randomHex(32)); - * > 0x139f5b88b72a25eab053d3b57fe1f8a9dbc62a526b1cb1774d0d7db1c3e7ce9e - * ``` */ export const randomHex = (byteSize: number): string => `0x${randomBytes(byteSize).toString('hex')}`; diff --git a/packages/web3-utils/src/socket_provider.ts b/packages/web3-utils/src/socket_provider.ts index 7c5fcda3287..451133eb76e 100644 --- a/packages/web3-utils/src/socket_provider.ts +++ b/packages/web3-utils/src/socket_provider.ts @@ -55,8 +55,6 @@ type ReconnectOptions = { type EventType = 'message' | 'connect' | 'disconnect' | 'chainChanged' | 'accountsChanged' | string; -const NORMAL_CLOSE_CODE = 1000; // https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close - export abstract class SocketProvider< MessageEvent, CloseEvent, @@ -80,12 +78,6 @@ export abstract class SocketProvider< protected readonly _onCloseHandler: (event: CloseEvent) => void; protected readonly _onErrorHandler: (event: ErrorEvent) => void; - /** - * This is an abstract class for implementing a socket provider (e.g. WebSocket, IPC). It extends the EIP-1193 provider {@link EIP1193Provider}. - * @param socketPath - The path to the socket (e.g. /ipc/path or ws://localhost:8546) - * @param options - The options for the socket connection - * @param reconnectOptions - The options for the socket reconnection {@link ReconnectOptions} - */ public constructor(socketPath: string, options?: object, reconnectOptions?: object) { super(); this._connectionStatus = 'connecting'; @@ -125,9 +117,6 @@ export abstract class SocketProvider< this._reconnectAttempts = 0; } - /** - * Try to establish a connection to the socket - */ public connect(): void { try { this._openSocketConnection(); @@ -171,38 +160,19 @@ export abstract class SocketProvider< return !!path; } - /** - * - * @returns `true` if the socket supports subscriptions - */ // eslint-disable-next-line class-methods-use-this public supportsSubscriptions(): boolean { return true; } - /** - * Registers a listener for the specified event type. - * @param type - The event type to listen for - * @param callback - The callback to be invoked when the event is emitted - */ public on(type: EventType, callback: Web3ProviderEventCallback): void { this._eventEmitter.on(type, callback); } - /** - * Registers a listener for the specified event type that will be invoked at most once. - * @param type - The event type to listen for - * @param callback - The callback to be invoked when the event is emitted - */ public once(type: EventType, callback: Web3ProviderEventCallback): void { this._eventEmitter.once(type, callback); } - /** - * Removes a listener for the specified event type. - * @param type - The event type to remove the listener for - * @param callback - The callback to be exetuted - */ public removeListener(type: EventType, callback: Web3ProviderEventCallback): void { this._eventEmitter.removeListener(type, callback); } @@ -212,24 +182,14 @@ export abstract class SocketProvider< super._onDisconnect(code, data); } - /** - * Disconnects the socket - * @param code - The code to be sent to the server - * @param data - The data to be sent to the server - */ public disconnect(code?: number, data?: string): void { - const disconnectCode = code ?? NORMAL_CLOSE_CODE; this._removeSocketListeners(); if (this.getStatus() !== 'disconnected') { - this._closeSocketConnection(disconnectCode, data); + this._closeSocketConnection(code, data); } - this._onDisconnect(disconnectCode, data); + this._onDisconnect(code, data); } - /** - * Removes all listeners for the specified event type. - * @param type - The event type to remove the listeners for - */ public removeAllListeners(type: string): void { this._eventEmitter.removeAllListeners(type); } @@ -243,9 +203,6 @@ export abstract class SocketProvider< } } - /** - * Resets the socket, removing all listeners and pending requests - */ public reset(): void { this._sentRequestsQueue.clear(); this._pendingRequestsQueue.clear(); @@ -287,9 +244,6 @@ export abstract class SocketProvider< } } - /** - * Creates a request object to be sent to the server - */ public async request< Method extends Web3APIMethod, ResultType = Web3APIReturnType, diff --git a/packages/web3-utils/src/string_manipulation.ts b/packages/web3-utils/src/string_manipulation.ts index 0e849fd501f..8a251c3b692 100644 --- a/packages/web3-utils/src/string_manipulation.ts +++ b/packages/web3-utils/src/string_manipulation.ts @@ -22,17 +22,6 @@ import { numberToHex, toHex, toNumber } from './converters'; /** * Adds a padding on the left of a string, if value is a integer or bigInt will be converted to a hex string. - * @param value - The value to be padded. - * @param characterAmount - The amount of characters the string should have. - * @param sign - The sign to be added (default is 0). - * @returns The padded string. - * - * @example - * ```ts - * - * console.log(web3.utils.padLeft('0x123', 10)); - * >0x0000000123 - * ``` */ export const padLeft = (value: Numbers, characterAmount: number, sign = '0'): string => { // To avoid duplicate code and circular dependency we will @@ -49,19 +38,6 @@ export const padLeft = (value: Numbers, characterAmount: number, sign = '0'): st /** * Adds a padding on the right of a string, if value is a integer or bigInt will be converted to a hex string. - * @param value - The value to be padded. - * @param characterAmount - The amount of characters the string should have. - * @param sign - The sign to be added (default is 0). - * @returns The padded string. - * - * @example - * ```ts - * console.log(web3.utils.padRight('0x123', 10)); - * > 0x1230000000 - * - * console.log(web3.utils.padRight('0x123', 10, '1')); - * > 0x1231111111 - * ``` */ export const padRight = (value: Numbers, characterAmount: number, sign = '0'): string => { if (typeof value === 'string' && !isHexStrict(value)) { @@ -88,22 +64,6 @@ export const leftPad = padLeft; /** * Converts a negative number into the two’s complement and return a hexstring of 64 nibbles. - * @param value - The value to be converted. - * @param nibbleWidth - The nibble width of the hex string (default is 64). - * - * @returns The hex string of the two’s complement. - * - * @example - * ```ts - * console.log(web3.utils.toTwosComplement(13, 32)); - * > 0x0000000000000000000000000000000d - * - * console.log(web3.utils.toTwosComplement('-0x1', 32)); - * > 0xffffffffffffffffffffffffffffffff - * - * console.log(web3.utils.toTwosComplement(BigInt('9007199254740992'), 32)); - * > 0x00000000000000000020000000000000 - * ``` */ export const toTwosComplement = (value: Numbers, nibbleWidth = 64): string => { validator.validate(['int'], [value]); @@ -125,18 +85,6 @@ export const toTwosComplement = (value: Numbers, nibbleWidth = 64): string => { /** * Converts the twos complement into a decimal number or big int. - * @param value - The value to be converted. - * @param nibbleWidth - The nibble width of the hex string (default is 64). - * @returns The decimal number or big int. - * - * @example - * ```ts - * console.log(web3.utils.fromTwosComplement(''0x0000000000000000000000000000000d', 32')); - * > 13 - * - * console.log(web3.utils.fromTwosComplement('0x00000000000000000020000000000000', 32)); - * > 9007199254740992n - * ``` */ export const fromTwosComplement = (value: Numbers, nibbleWidth = 64): number | bigint => { validator.validate(['int'], [value]); diff --git a/packages/web3-utils/src/uuid.ts b/packages/web3-utils/src/uuid.ts index b016743e077..152ee0d02d9 100644 --- a/packages/web3-utils/src/uuid.ts +++ b/packages/web3-utils/src/uuid.ts @@ -21,12 +21,6 @@ import { randomBytes } from './random'; /** * Generate a version 4 (random) uuid * https://github.com/uuidjs/uuid/blob/main/src/v4.js#L5 - * @returns - A version 4 uuid of the form xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx - * @example - * ```ts - * console.log(web3.utils.uuidV4()); - * > "1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed" - * ``` */ export const uuidV4 = (): string => { const bytes = randomBytes(16); diff --git a/packages/web3-utils/src/validation.ts b/packages/web3-utils/src/validation.ts index 629f82e7539..725e2723494 100644 --- a/packages/web3-utils/src/validation.ts +++ b/packages/web3-utils/src/validation.ts @@ -106,19 +106,7 @@ export const isTopicInBloom = isTopicInBloomValidator; /** * Compares between block A and block B - * @param blockA - Block number or string - * @param blockB - Block number or string - * - * @returns - Returns -1 if a \< b, returns 1 if a \> b and returns 0 if a == b - * - * @example - * ```ts - * console.log(web3.utils.compareBlockNumbers('latest', 'pending')); - * > -1 - * - * console.log(web3.utils.compareBlockNumbers(12, 11)); - * > 1 - * ``` + * Returns -1 if a \< b, returns 1 if a \> b and returns 0 if a == b */ export const compareBlockNumbers = (blockA: BlockNumberOrTag, blockB: BlockNumberOrTag) => { const isABlockTag = typeof blockA === 'string' && isBlockTag(blockA); diff --git a/packages/web3-utils/src/web3_deferred_promise.ts b/packages/web3-utils/src/web3_deferred_promise.ts index 88f4b979ae5..541364f61a0 100644 --- a/packages/web3-utils/src/web3_deferred_promise.ts +++ b/packages/web3-utils/src/web3_deferred_promise.ts @@ -17,11 +17,7 @@ along with web3.js. If not, see . import { OperationTimeoutError } from 'web3-errors'; import { Web3DeferredPromiseInterface } from 'web3-types'; -/** - * The class is a simple implementation of a deferred promise with optional timeout functionality, - * which can be useful when dealing with asynchronous tasks. - * - */ + export class Web3DeferredPromise implements Promise, Web3DeferredPromiseInterface { // public tag to treat object as promise by different libs // eslint-disable-next-line @typescript-eslint/prefer-as-const @@ -35,12 +31,6 @@ export class Web3DeferredPromise implements Promise, Web3DeferredPromiseIn private readonly _timeoutInterval?: number; private readonly _timeoutMessage: string; - /** - * - * @param timeout - (optional) The timeout in milliseconds. - * @param eagerStart - (optional) If true, the timer starts as soon as the promise is created. - * @param timeoutMessage - (optional) The message to include in the timeout erro that is thrown when the promise times out. - */ public constructor( { timeout, @@ -64,30 +54,18 @@ export class Web3DeferredPromise implements Promise, Web3DeferredPromiseIn this.startTimer(); } } - /** - * Returns the current state of the promise. - * @returns 'pending' | 'fulfilled' | 'rejected' - */ + public get state(): 'pending' | 'fulfilled' | 'rejected' { return this._state; } - /** - * - * @param onfulfilled - (optional) The callback to execute when the promise is fulfilled. - * @param onrejected - (optional) The callback to execute when the promise is rejected. - * @returns - */ + public async then( onfulfilled?: (value: T) => TResult1 | PromiseLike, onrejected?: (reason: unknown) => TResult2 | PromiseLike, ): Promise { return this._promise.then(onfulfilled, onrejected); } - /** - * - * @param onrejected - (optional) The callback to execute when the promise is rejected. - * @returns - */ + public async catch( // eslint-disable-next-line @typescript-eslint/no-explicit-any onrejected?: (reason: any) => TResult | PromiseLike, @@ -95,38 +73,22 @@ export class Web3DeferredPromise implements Promise, Web3DeferredPromiseIn return this._promise.catch(onrejected); } - /** - * - * @param onfinally - (optional) The callback to execute when the promise is settled (fulfilled or rejected). - * @returns - */ public async finally(onfinally?: (() => void) | undefined): Promise { return this._promise.finally(onfinally); } - /** - * Resolves the current promise. - * @param value - The value to resolve the promise with. - */ public resolve(value: T | PromiseLike): void { this._resolve(value); this._state = 'fulfilled'; this._clearTimeout(); } - /** - * Rejects the current promise. - * @param reason - The reason to reject the promise with. - */ public reject(reason?: unknown): void { this._reject(reason); this._state = 'rejected'; this._clearTimeout(); } - /** - * Starts the timeout timer for the promise. - */ public startTimer() { if (this._timeoutInterval && this._timeoutInterval > 0) { this._timeoutId = setTimeout(this._checkTimeout.bind(this), this._timeoutInterval); diff --git a/packages/web3-utils/src/web3_eip1193_provider.ts b/packages/web3-utils/src/web3_eip1193_provider.ts index f0155d649ba..74585e7e03a 100644 --- a/packages/web3-utils/src/web3_eip1193_provider.ts +++ b/packages/web3-utils/src/web3_eip1193_provider.ts @@ -25,9 +25,6 @@ import { import { EventEmitter } from 'events'; import { toPayload } from './json_rpc'; -/** - * This is an abstract class, which extends {@link Web3BaseProvider} class. This class is used to implement a provider that adheres to the EIP-1193 standard for Ethereum providers. - */ export abstract class Eip1193Provider< API extends Web3APISpec = EthExecutionAPI, > extends Web3BaseProvider { diff --git a/packages/web3/test/integration/web3.test.ts b/packages/web3/test/integration/web3.test.ts index 7a9b2c94105..c831cbd164a 100644 --- a/packages/web3/test/integration/web3.test.ts +++ b/packages/web3/test/integration/web3.test.ts @@ -19,7 +19,7 @@ import { JsonRpcOptionalRequest, Web3BaseProvider, SupportedProviders } from 'we import Contract from 'web3-eth-contract'; import HttpProvider from 'web3-providers-http'; import IpcProvider from 'web3-providers-ipc'; -import WebSocketProvider from 'web3-providers-ws'; +import WebsocketProvider from 'web3-providers-ws'; import Web3 from '../../src/index'; import { BasicAbi } from '../shared_fixtures/Basic'; import { validEncodeParametersData } from '../shared_fixtures/data'; @@ -75,16 +75,6 @@ describe('Web3 instance', () => { expect(() => new Web3()).not.toThrow(); }); - it('check disconnect function', async () => { - const web3Instance = new Web3(clientUrl); - await web3Instance.eth.getBlockNumber(); - expect(typeof web3Instance.provider?.disconnect).toBe('function'); - expect(typeof web3Instance.eth.provider?.disconnect).toBe('function'); - expect(typeof web3Instance.currentProvider?.disconnect).toBe('function'); - expect(typeof web3Instance.eth.currentProvider?.disconnect).toBe('function'); - web3Instance.currentProvider?.disconnect(); - }); - it('should be able use "utils" without provider', () => { web3 = new Web3(); @@ -189,7 +179,7 @@ describe('Web3 instance', () => { const res = Web3.providers; expect(Web3.providers.HttpProvider).toBe(HttpProvider); - expect(res.WebsocketProvider).toBe(WebSocketProvider); + expect(res.WebsocketProvider).toBe(WebsocketProvider); expect(res.IpcProvider).toBe(IpcProvider); });