Closed pph7 closed 5 years ago
Hi @pph7 , thank you for finding this issue. I pull requested a fix in #306.
For now I didn't modify the type of spamTransfers
argument yet, because we should explore possibility of promoting with regular transfers as well. Most likely we will create an auto-promotion/reattachment function which emits transaction trytes to be attached.
I am glad if I can help
Bug description
When calling
promoteTransaction()
without specifying atransfer
array it throws an error. I am aware that in the documentation, the transfer array is not optional. However, there is one example in the documentation that does not use the transfer array:https://github.com/iotaledger/iota.js/tree/next/packages/core#module_core.isPromotable
Also, in the source code, a default value is provided:
https://github.com/iotaledger/iota.js/blob/2ad21079c655f7c7527ad392d896b85e257f9f34/packages/core/src/createPromoteTransaction.ts#L21-L28
This is because
Array(n).map(spammer)
does not return an array of spammer objects. Instead it returns an array of uninitialized arrays. This can be easily verified:
new Array(1).map(1)
will produce
[empty]
and not the expected array
[1]
.Possibile solutions: use
new Array(1).fill().map()
BTW, it seems that
generateSpam()
is alway only called with default value of 1 so this could besimplifyed
.Steps To Reproduce
Use
promotTransaction()
without value fortransfers
, e.g.iota.promoteTransaction(tail, depth, minWeightMagnitude)
Expected behaviour
´transfers
should be initialized with a default spam
transfer` array of length 1.Actual behavior
An error is thrown.
Errors