From 515364920942e6eaa242e41d439fc6d6a9eaf89e Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Fri, 13 Sep 2024 18:47:58 +1000 Subject: [PATCH] fix(tx-builder): count amount in execution cost when spend to yourself Anyway the amount needs to be on balance to mine such transaction. --- src/tx/execution-cost.ts | 2 +- test/integration/~execution-cost.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tx/execution-cost.ts b/src/tx/execution-cost.ts index 2b49b50d30..af53a6d2ee 100644 --- a/src/tx/execution-cost.ts +++ b/src/tx/execution-cost.ts @@ -69,7 +69,7 @@ export function getExecutionCost( if (isInitiator === false) res -= BigInt(params.responderAmountFinal); } if ( - ((params.tag === Tag.SpendTx && params.senderId !== params.recipientId) + (params.tag === Tag.SpendTx || params.tag === Tag.ContractCreateTx || params.tag === Tag.ContractCallTx || params.tag === Tag.ChannelDepositTx) && innerTx !== 'fee-payer' ) { diff --git a/test/integration/~execution-cost.ts b/test/integration/~execution-cost.ts index 6522137c85..3c66c78956 100644 --- a/test/integration/~execution-cost.ts +++ b/test/integration/~execution-cost.ts @@ -39,7 +39,7 @@ describe('Execution cost', () => { it('calculates execution cost for spend tx', async () => { const { rawTx } = await aeSdk.spend(100, aeSdk.address, { ttl: 0 }); - const expectedCost = 16660000000000n; + const expectedCost = 16660000000000n + 100n; expect(getExecutionCostBySignedTx(rawTx, networkId)).to.equal(expectedCost); expect(getExecutionCost(buildTx(unpackTx(rawTx, Tag.SignedTx).encodedTx))) .to.equal(expectedCost); @@ -86,6 +86,8 @@ describe('Execution cost', () => { // Can't detect Oracle.respond reward in contract call if (balanceDiff === -501000n) return; expect(balanceDiff).to.be.equal(0n); + } else if (params.tag === Tag.SpendTx && params.senderId === params.recipientId) { + expect(balanceDiff).to.be.equal(BigInt(-params.amount)); } else { expect(balanceDiff).to.be.equal(0n); }