From a14dbbaebdd33883de5640fa5090886a8d799304 Mon Sep 17 00:00:00 2001 From: tim Date: Fri, 16 Jun 2017 14:12:02 +0200 Subject: [PATCH] Add tests for makeOutput --- test/transaction/test_transaction.js | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/transaction/test_transaction.js diff --git a/test/transaction/test_transaction.js b/test/transaction/test_transaction.js new file mode 100644 index 0000000..f23d110 --- /dev/null +++ b/test/transaction/test_transaction.js @@ -0,0 +1,55 @@ +import test from 'ava' +import { Transaction } from '../../src' + + +test('Create valid output with default amount', t => { + const condition = { + details: { + public_key: 'abc' + } + } + const expected = { + amount: '1', + condition, + public_keys: ['abc'] + } + const res = Transaction.makeOutput(condition) + return t.deepEqual(res, expected) +}) + + +test('Create valid output with custom amount', t => { + const condition = { + details: { + public_key: 'abc' + } + } + const customAmount = '1337' + const expected = { + amount: customAmount, + condition, + public_keys: ['abc'] + } + const res = Transaction.makeOutput(condition, customAmount) + return t.deepEqual(res, expected) +}) + +test('Pass condition not based on public_keys to makeOutput', t => { + const condition = { + details: { + idea: 'just pretend this is e.g. a hashlock' + } + } + const expected = { + amount: '1', + condition, + public_keys: [] + } + const res = Transaction.makeOutput(condition) + return t.deepEqual(res, expected) +}) + + +test('makeOutput throws TypeError with incorrect amount type', t => { + t.throws(() => Transaction.makeOutput({}, 1337), TypeError) +})