Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/commands/notarize.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ class Notarise extends Command {
if (!flags.json){
this.log(white().bgBlue(network))
}
// In --json mode use a spinner that swallows its output: the progress text
// would corrupt the JSON, and every spinner.succeed()/.fail() call below is
// unconditional (calling them on a bare `null` threw a TypeError).
const noop = function noop() { return this }
const nullSpinner = { start: noop, succeed: noop, fail: noop, info: noop, warn: noop, stop: noop }
const makeSpinner = (text) => (flags.json ? nullSpinner : ora({ text }).start())
// the data to notarise here, can be a file submitted (path) or a string passed on cli
const spinner = flags.json ? null : ora({ text: 'Notarising Data...\n', }).start()
const spinner = makeSpinner('Notarising Data...\n')
if (args.dataHash) {
const sha256regex = /^\b[A-Fa-f0-9]{64}\b/.test(args.dataHash)
// is the passed data the correct length? should be a sha256 sum hash
Expand Down Expand Up @@ -247,7 +253,7 @@ class Notarise extends Command {
// send the message transaction with the notarise encoding to the node
const message = await Qrlnetwork.api('GetMessageTxn', request)

const spinner3 = ora({ text: 'Signing transaction...' }).start()
const spinner3 = makeSpinner('Signing transaction...')

// Preimage order is QRL core's MessageTransaction.get_data_bytes():
// master_addr || fee || message_hash || addr_to
Expand Down Expand Up @@ -291,7 +297,7 @@ class Notarise extends Command {
this.exit(1)
}
spinner3.succeed(`Node response matches the request. Transaction signed with OTS key ${flags.otsindex}. (nodes will reject this transaction if key reuse is detected)`)
const spinner4 = ora({ text: 'Pushing transaction to node...' }).start()
const spinner4 = makeSpinner('Pushing transaction to node...')
// transaction sig and pub key into buffer
returnedTx.signature = Buffer.from(signature)
returnedTx.public_key = Buffer.from(xmssPK) // eslint-disable-line camelcase
Expand Down
33 changes: 32 additions & 1 deletion test/commands/notarize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,40 @@ describe('notarize #8', () => {
})
})

// --json mode used to throw "TypeError: Cannot read properties of null" on the
// first spinner.succeed() call. It should now run without that crash (here it
// still exits non-0 because the grpc endpoint is deliberately unreachable).
describe('notarize #8b --json does not crash', () => {
let exitCode
let output = ''
before(done => {
const args = [
'notarize',
sha256Hash,
'-w', setup.bobPTWalletLocation,
'-i', '0',
'-j',
'-g', 'https://brooklyn.theqrl.org/nottheapi/',
]
const child = spawn('./bin/run', args, { detached: true, stdio: ['ignore', 'pipe', 'pipe'] })
child.stdout.on('data', d => { output += d.toString() })
child.stderr.on('data', d => { output += d.toString() })
child.on('exit', code => {
exitCode = code
done()
})
})
it('does not throw a TypeError', () => {
assert.ok(!output.includes('TypeError'), output)
})
it('exit code should be non-0 when the node is unreachable', () => {
assert.notStrictEqual(exitCode, 0)
})
})


// //////////////////////////
// pass
// pass
// //////////////////////////

describe('notarize #9 bobs plaintext wallet hexString', () => {
Expand Down