Skip to content

Commit 0e1c734

Browse files
committed
Fix #34: assign proposed operations fee amounts
1 parent 500dee8 commit 0e1c734

2 files changed

Lines changed: 67 additions & 26 deletions

File tree

lib/chain/src/TransactionBuilder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ class TransactionBuilder {
391391
*/
392392
if (isProposal(op)) {
393393
op[1].proposed_ops.forEach(proposal => {
394-
// console.log("proposed op", proposal.op[1].fee);
395394
proposed_ops.push(proposal);
396395
if (
397396
proposalFeeAssets.indexOf(
@@ -647,6 +646,8 @@ class TransactionBuilder {
647646
for (let y = 0; y < operation.proposed_ops.length; y++) {
648647
operation.proposed_ops[y].op[1].fee.asset_id =
649648
finalProposalFees[opIndex][y].asset_id;
649+
operation.proposed_ops[y].op[1].fee.amount =
650+
finalProposalFees[opIndex][y].amount;
650651
}
651652

652653
return result;

test/chain/TransactionBuilder.js

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "assert";
22
import {Apis} from "bitsharesjs-ws";
3-
import {TransactionBuilder} from "../../lib";
3+
import {TransactionBuilder, ops} from "../../lib";
44

55
describe("TransactionBuilder", () => {
66
// Connect once for all tests
@@ -226,7 +226,56 @@ describe("TransactionBuilder", () => {
226226
});
227227
});
228228

229-
it("Resolves fees for proposed operations", () => {
229+
it("Sets non-zero fee for proposed operations", () => {
230+
return new Promise((resolve, reject) => {
231+
let tr = new TransactionBuilder();
232+
233+
let proposal = {
234+
op: tr.get_type_operation("transfer", {
235+
fee: {
236+
amount: 0,
237+
asset_id: "1.3.0"
238+
},
239+
from: "1.2.1057595",
240+
to: "1.2.802379",
241+
amount: {amount: 100000, asset_id: "1.3.0"},
242+
memo: {
243+
from: "BTS1111111111111111111111111111111114T1Anm",
244+
to: "BTS1111111111111111111111111111111114T1Anm",
245+
nonce: 0,
246+
message: ""
247+
}
248+
})
249+
};
250+
251+
let proposed_ops = [proposal];
252+
253+
tr.add_type_operation("proposal_create", {
254+
proposed_ops,
255+
fee_paying_account: "1.2.1",
256+
fee: {
257+
amount: 0,
258+
asset_id: "1.3.0"
259+
}
260+
});
261+
262+
tr
263+
.set_required_fees()
264+
.then(() => {
265+
assert.equal(
266+
tr.operations[0][1].proposed_ops[0].op[1].fee.asset_id,
267+
"1.3.0"
268+
);
269+
assert(
270+
tr.operations[0][1].proposed_ops[0].op[1].fee.amount > 0
271+
);
272+
resolve();
273+
})
274+
.catch(reject);
275+
});
276+
});
277+
278+
it("Resolves fees for multiple proposed operations", () => {
230279
return new Promise((resolve, reject) => {
231280
let tr = new TransactionBuilder();
232281

@@ -256,43 +305,34 @@ describe("TransactionBuilder", () => {
256305
fee_paying_account: "1.2.1",
257306
fee: {
258307
amount: 0,
259-
asset_id: "1.3.121"
308+
asset_id: "1.3.0"
260309
}
261310
});
262311

263-
tr.add_type_operation("account_upgrade", {
264-
fee: {
265-
amount: 0,
266-
asset_id: "1.3.113"
267-
},
268-
account_to_upgrade: "1.2.1",
269-
upgrade_to_lifetime_member: true
270-
});
271-
272-
//
273312
tr
274313
.set_required_fees()
275314
.then(() => {
276-
assert.equal(tr.operations[0][1].fee.asset_id, "1.3.121");
277-
assert.equal(tr.operations[1][1].fee.asset_id, "1.3.113");
278-
assert(
279-
tr.operations[0][1].fee.amount <
280-
tr.operations[1][1].fee.amount
281-
);
315+
assert.equal(tr.operations[0][1].fee.asset_id, "1.3.0");
316+
282317
/*
283-
* This test might break as fee pools are replenished, check and
284-
* update assets used if necessary. At least one asset should
285-
* have an insufficient pool balance, and one should have a
286-
* sufficient pool balance
287-
*/
318+
* This test might break as fee pools are replenished, check and
319+
* update assets used if necessary. At least one asset should
320+
* have an insufficient pool balance, and one should have a
321+
* sufficient pool balance. The current iteration assumes the
322+
* asset 1.3.125 has an insufficient fee pool balance
323+
*/
288324
tr.operations[0][1].proposed_ops.forEach((prop, index) => {
289325
if (index === 1)
326+
// asset "1.3.125 with insufficient fee pool balance"
290327
assert.equal(prop.op[1].fee.asset_id, "1.3.0");
291-
else
328+
else {
292329
assert.equal(
293330
prop.op[1].fee.asset_id,
294331
proposal_fee_assets[index]
295332
);
333+
}
334+
/* All ops should have a non-zero fee assigned */
335+
assert(prop.op[1].fee.amount > 0);
296336
});
297337
resolve();
298338
})

0 commit comments

Comments
 (0)