|
1 | 1 | import assert from "assert"; |
2 | 2 | import {Apis} from "bitsharesjs-ws"; |
3 | | -import {TransactionBuilder} from "../../lib"; |
| 3 | +import {TransactionBuilder, ops} from "../../lib"; |
4 | 4 |
|
5 | 5 | describe("TransactionBuilder", () => { |
6 | 6 | // Connect once for all tests |
@@ -226,7 +226,56 @@ describe("TransactionBuilder", () => { |
226 | 226 | }); |
227 | 227 | }); |
228 | 228 |
|
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", () => { |
230 | 279 | return new Promise((resolve, reject) => { |
231 | 280 | let tr = new TransactionBuilder(); |
232 | 281 |
|
@@ -256,43 +305,34 @@ describe("TransactionBuilder", () => { |
256 | 305 | fee_paying_account: "1.2.1", |
257 | 306 | fee: { |
258 | 307 | amount: 0, |
259 | | - asset_id: "1.3.121" |
| 308 | + asset_id: "1.3.0" |
260 | 309 | } |
261 | 310 | }); |
262 | 311 |
|
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 | | - // |
273 | 312 | tr |
274 | 313 | .set_required_fees() |
275 | 314 | .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 | + |
282 | 317 | /* |
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 | + */ |
288 | 324 | tr.operations[0][1].proposed_ops.forEach((prop, index) => { |
289 | 325 | if (index === 1) |
| 326 | + // asset "1.3.125 with insufficient fee pool balance" |
290 | 327 | assert.equal(prop.op[1].fee.asset_id, "1.3.0"); |
291 | | - else |
| 328 | + else { |
292 | 329 | assert.equal( |
293 | 330 | prop.op[1].fee.asset_id, |
294 | 331 | proposal_fee_assets[index] |
295 | 332 | ); |
| 333 | + } |
| 334 | + /* All ops should have a non-zero fee assigned */ |
| 335 | + assert(prop.op[1].fee.amount > 0); |
296 | 336 | }); |
297 | 337 | resolve(); |
298 | 338 | }) |
|
0 commit comments