Skip to content

Commit

Permalink
Merge pull request #2019 from aeternity/fix-exec-cost
Browse files Browse the repository at this point in the history
fix(tx-builder): count amount in execution cost when spend to yourself
  • Loading branch information
davidyuk authored Sep 26, 2024
2 parents 113f28f + 5153649 commit 3302b9c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/tx/execution-cost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
) {
Expand Down
4 changes: 3 additions & 1 deletion test/integration/~execution-cost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 3302b9c

Please sign in to comment.