js-algorand-sdk
js-algorand-sdk copied to clipboard
Cannot sign a transaction from Jest's node environment
Summary
Since the internal bytesToSign function returns a Buffer instead of a Uint8Array, signing a transaction throws an error inside Jest's node testing environment.
Background
Jest's standard node environment contains globals that cause a Buffer instance check against Uint8Array to fail. Therefore, the following statement will print false in a Jest environment but true in a standard node environment.
const u = new Buffer([1, 2, 3, 4]);
console.log(u instanceof Uint8Array)
Scope
Change the bytesToSign implementation so that it returns a Uint8Array instead of a Buffer instance and double check that signing transactions is then possible in the Jest environment.
Urgency
This bug prevents users from testing any transaction signing operations from within the Jest testing framework.