This repository has been archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
waitForTransactionReceipt fix #6464
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
eb32595
added pollTillDefinedAndReturnIntervalId
jdevcs d640df1
waitForTransactionReceipt updated interval calls
jdevcs fd7037e
tests pollTillDefinedAndReturnIntervalId
jdevcs 81a7274
reusing func for lib size optmz
jdevcs 2dbbc8a
lint
jdevcs 284b81b
test fix
jdevcs b74be69
waitWithTimeout
jdevcs d20f6a9
unit test
jdevcs 0aade03
Merge branch '4.x' into junaid/4xtxwaitfix
jdevcs 9323849
formatting
jdevcs 62d037e
lint fix
jdevcs 7369e7c
waitForTransactionReceipt unit tests
jdevcs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
packages/web3-eth/test/unit/utils/wait_for_transaction_receipt.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
This file is part of web3.js. | ||
|
||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import { Web3Context } from 'web3-core'; | ||
import { DEFAULT_RETURN_FORMAT, Web3EthExecutionAPI } from 'web3-types'; | ||
import { TransactionBlockTimeoutError } from 'web3-errors'; | ||
import { waitForTransactionReceipt } from '../../../src/utils/wait_for_transaction_receipt'; | ||
|
||
describe('waitForTransactionReceipt unit test', () => { | ||
let web3Context: Web3Context<Web3EthExecutionAPI>; | ||
|
||
it(`waitForTransactionReceipt should throw error after block timeout`, async () => { | ||
let blockNum = 1; | ||
|
||
web3Context = new Web3Context( | ||
{ | ||
request: async (payload: any) => { | ||
let response: { jsonrpc: string; id: any; result: string } | undefined; | ||
|
||
switch (payload.method) { | ||
case 'eth_blockNumber': | ||
blockNum += 50; | ||
response = { | ||
jsonrpc: '2.0', | ||
id: payload.id, | ||
result: `0x${blockNum.toString(16)}`, | ||
}; | ||
break; | ||
|
||
case 'eth_getTransactionReceipt': | ||
response = undefined; | ||
break; | ||
|
||
default: | ||
throw new Error(`Unknown payload ${payload}`); | ||
} | ||
|
||
return new Promise(resolve => { | ||
resolve(response as any); | ||
}); | ||
}, | ||
supportsSubscriptions: () => false, | ||
}, | ||
); | ||
|
||
await expect(async () => | ||
waitForTransactionReceipt( | ||
web3Context, | ||
'0x0430b701e657e634a9d5480eae0387a473913ef29af8e60c38a3cee24494ed54', | ||
DEFAULT_RETURN_FORMAT | ||
) | ||
).rejects.toThrow(TransactionBlockTimeoutError); | ||
|
||
}); | ||
|
||
it(`waitForTransactionReceipt should resolve immediatly if receipt is avalible`, async () => { | ||
let blockNum = 1; | ||
const txHash = '0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5'; | ||
const blockHash = '0xa957d47df264a31badc3ae823e10ac1d444b098d9b73d204c40426e57f47e8c3'; | ||
|
||
web3Context = new Web3Context( | ||
{ | ||
request: async (payload: any) => { | ||
const response = { | ||
jsonrpc: '2.0', | ||
id: payload.id, | ||
result: {}, | ||
}; | ||
|
||
switch (payload.method) { | ||
case 'eth_blockNumber': | ||
blockNum += 10; | ||
response.result = `0x${blockNum.toString(16)}`; | ||
break; | ||
|
||
case 'eth_getTransactionReceipt': | ||
response.result = { | ||
blockHash, | ||
blockNumber: `0x1`, | ||
cumulativeGasUsed: '0xa12515', | ||
from: payload.from, | ||
gasUsed: payload.gasLimit, | ||
status: '0x1', | ||
to: payload.to, | ||
transactionHash: txHash, | ||
transactionIndex: '0x66', | ||
|
||
}; | ||
break; | ||
|
||
default: | ||
throw new Error(`Unknown payload ${payload}`); | ||
} | ||
|
||
return new Promise(resolve => { | ||
resolve(response as any); | ||
}); | ||
}, | ||
supportsSubscriptions: () => false, | ||
}, | ||
); | ||
|
||
const res = await waitForTransactionReceipt( | ||
web3Context, | ||
'0x0430b701e657e634a9d5480eae0387a473913ef29af8e60c38a3cee24494ed54', | ||
DEFAULT_RETURN_FORMAT | ||
); | ||
|
||
expect(res).toBeDefined(); | ||
expect(res.transactionHash).toStrictEqual(txHash); | ||
expect(res.blockHash).toStrictEqual(blockHash); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keeping
pollTillDefined
so we dnt break API as its exported function from utils.