Skip to content

Commit 3302b9c

Browse files
authored
Merge pull request #2019 from aeternity/fix-exec-cost
fix(tx-builder): count amount in execution cost when spend to yourself
2 parents 113f28f + 5153649 commit 3302b9c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/tx/execution-cost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function getExecutionCost(
6969
if (isInitiator === false) res -= BigInt(params.responderAmountFinal);
7070
}
7171
if (
72-
((params.tag === Tag.SpendTx && params.senderId !== params.recipientId)
72+
(params.tag === Tag.SpendTx
7373
|| params.tag === Tag.ContractCreateTx || params.tag === Tag.ContractCallTx
7474
|| params.tag === Tag.ChannelDepositTx) && innerTx !== 'fee-payer'
7575
) {

test/integration/~execution-cost.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Execution cost', () => {
3939

4040
it('calculates execution cost for spend tx', async () => {
4141
const { rawTx } = await aeSdk.spend(100, aeSdk.address, { ttl: 0 });
42-
const expectedCost = 16660000000000n;
42+
const expectedCost = 16660000000000n + 100n;
4343
expect(getExecutionCostBySignedTx(rawTx, networkId)).to.equal(expectedCost);
4444
expect(getExecutionCost(buildTx(unpackTx(rawTx, Tag.SignedTx).encodedTx)))
4545
.to.equal(expectedCost);
@@ -86,6 +86,8 @@ describe('Execution cost', () => {
8686
// Can't detect Oracle.respond reward in contract call
8787
if (balanceDiff === -501000n) return;
8888
expect(balanceDiff).to.be.equal(0n);
89+
} else if (params.tag === Tag.SpendTx && params.senderId === params.recipientId) {
90+
expect(balanceDiff).to.be.equal(BigInt(-params.amount));
8991
} else {
9092
expect(balanceDiff).to.be.equal(0n);
9193
}

0 commit comments

Comments
 (0)