Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Handling receipt with status and gas correctly #701

Merged
merged 1 commit into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/caver-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ const checkForNormalTx = (mutableConfirmationPack, receipt, sub) => {
if (
receipt &&
!receipt.outOfGas &&
(!gasProvided || gasProvided !== receipt.gasUsed) &&
(!gasProvided || utils.toBN(gasProvided).cmp(utils.toBN(receipt.gasUsed)) >= 0) &&
(receipt.status === true || receipt.status === '0x1' || typeof receipt.status === 'undefined')
) {
// Happy case: transaction is processed well. A.K.A 'well-done receipt'.
Expand Down
22 changes: 22 additions & 0 deletions test/getTransactionReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ before(() => {

caver.klay.accounts.wallet.add(senderPrvKey)
caver.klay.accounts.wallet.add(payerPrvKey)
caver.wallet.add(caver.wallet.keyring.createFromPrivateKey(senderPrvKey))
caver.wallet.add(caver.wallet.keyring.createFromPrivateKey(payerPrvKey))

const sender = caver.klay.accounts.privateKeyToAccount(senderPrvKey)
senderAddress = sender.address
Expand Down Expand Up @@ -126,3 +128,23 @@ describe('get transaction receipt by senderTxHash', () => {
}
}).timeout(10000)
})

describe('Return correct result with method receipt handling logic', () => {
it('CAVERJS-UNIT-TX-732: When if transaction status is true, then should not return an error', async () => {
const txobj = {
from: senderAddress,
to: receiver.address,
value: 1,
}
const estimatedGas = await caver.rpc.klay.estimateGas(txobj)
const tx = caver.transaction.legacyTransaction.create({
from: senderAddress,
to: receiver.address,
value: 1,
gas: estimatedGas,
})
await caver.wallet.sign(senderAddress, tx)

await expect(caver.rpc.klay.sendRawTransaction(tx)).not.to.be.rejected
}).timeout(10000)
})