mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2025-02-14 21:10:32 +01:00
Correct mocking of export default
This commit is contained in:
parent
42b400253b
commit
ede11da4c7
@ -21,8 +21,6 @@ import makeTransaction from './makeTransaction'
|
|||||||
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
|
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
|
||||||
* sending it off!
|
* sending it off!
|
||||||
*/
|
*/
|
||||||
// TODO: `outputs` should throw or include output in array if no array was
|
|
||||||
// passed
|
|
||||||
export default function makeCreateTransaction(asset, metadata, outputs, ...issuers) {
|
export default function makeCreateTransaction(asset, metadata, outputs, ...issuers) {
|
||||||
const assetDefinition = {
|
const assetDefinition = {
|
||||||
'data': asset || null,
|
'data': asset || null,
|
||||||
|
@ -2,15 +2,35 @@ import makeInputTemplate from './makeInputTemplate'
|
|||||||
import makeTransaction from './makeTransaction'
|
import makeTransaction from './makeTransaction'
|
||||||
|
|
||||||
|
|
||||||
// TODO: Can we remove `export` here somehow, but still be able to import the
|
/**
|
||||||
// function for tests?
|
* @public
|
||||||
export function _makeTransferTransaction(
|
* Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
|
||||||
|
* the `fulfilledOutputs` of `unspentTransaction`.
|
||||||
|
* @param {object} unspentTransaction Previous Transaction you have control over (i.e. can fulfill
|
||||||
|
* its Output Condition)
|
||||||
|
* @param {object} metadata Metadata for the Transaction
|
||||||
|
* @param {object[]} outputs Array of Output objects to add to the Transaction.
|
||||||
|
* Think of these as the recipients of the asset after the transaction.
|
||||||
|
* For `TRANSFER` Transactions, this should usually just be a list of
|
||||||
|
* Outputs wrapping Ed25519 Conditions generated from the public keys of
|
||||||
|
* the recipients.
|
||||||
|
* @param {...number} OutputIndices Indices of the Outputs in `unspentTransaction` that this
|
||||||
|
* Transaction fulfills.
|
||||||
|
* Note that listed public keys listed must be used (and in
|
||||||
|
* the same order) to sign the Transaction
|
||||||
|
* (`signTransaction()`).
|
||||||
|
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
|
||||||
|
* sending it off!
|
||||||
|
*/
|
||||||
|
// TODO:
|
||||||
|
// - Make `metadata` optional argument
|
||||||
|
export default function makeTransferTransaction(
|
||||||
unspentTransaction,
|
unspentTransaction,
|
||||||
metadata,
|
metadata,
|
||||||
outputs,
|
outputs,
|
||||||
...fulfilledOutputs
|
...outputIndices
|
||||||
) {
|
) {
|
||||||
const inputs = fulfilledOutputs.map((outputIndex) => {
|
const inputs = outputIndices.map((outputIndex) => {
|
||||||
const fulfilledOutput = unspentTransaction.outputs[outputIndex]
|
const fulfilledOutput = unspentTransaction.outputs[outputIndex]
|
||||||
const transactionLink = {
|
const transactionLink = {
|
||||||
'output': outputIndex,
|
'output': outputIndex,
|
||||||
@ -25,35 +45,5 @@ export function _makeTransferTransaction(
|
|||||||
: unspentTransaction.asset.id
|
: unspentTransaction.asset.id
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['TRANSFER', assetLink, metadata, outputs, inputs]
|
return makeTransaction('TRANSFER', assetLink, metadata, outputs, inputs)
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @public
|
|
||||||
* Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
|
|
||||||
* the `fulfilledOutputs` of `unspentTransaction`.
|
|
||||||
* @param {object} unspentTransaction Previous Transaction you have control over (i.e. can fulfill
|
|
||||||
* its Output Condition)
|
|
||||||
* @param {object} metadata Metadata for the Transaction
|
|
||||||
* @param {object[]} outputs Array of Output objects to add to the Transaction.
|
|
||||||
* Think of these as the recipients of the asset after the transaction.
|
|
||||||
* For `TRANSFER` Transactions, this should usually just be a list of
|
|
||||||
* Outputs wrapping Ed25519 Conditions generated from the public keys of
|
|
||||||
* the recipients.
|
|
||||||
* @param {...number} fulfilledOutputs Indices of the Outputs in `unspentTransaction` that this
|
|
||||||
* Transaction fulfills.
|
|
||||||
* Note that the public keys listed in the fulfilled Outputs
|
|
||||||
* must be used (and in the same order) to sign the Transaction
|
|
||||||
* (`signTransaction()`).
|
|
||||||
* @returns {object} Unsigned transaction -- make sure to call signTransaction() on it before
|
|
||||||
* sending it off!
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// - Make `metadata` optional argument
|
|
||||||
// - Rename `fulfilledOutputs`, e.g. inputs
|
|
||||||
// TODO: `outputs` should throw or include output in array if no array was
|
|
||||||
// passed
|
|
||||||
export default function makeTransferTransaction(...args) {
|
|
||||||
return makeTransaction(..._makeTransferTransaction(...args))
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
|
import sinon from 'sinon'
|
||||||
|
|
||||||
import { Transaction, Ed25519Keypair } from '../../src'
|
import { Transaction, Ed25519Keypair } from '../../src'
|
||||||
import { _makeTransferTransaction } from '../../src/transaction/makeTransferTransaction'
|
import * as makeTransaction from '../../src/transaction/makeTransaction' // eslint-disable-line
|
||||||
import makeInputTemplate from '../../src/transaction/makeInputTemplate'
|
import makeInputTemplate from '../../src/transaction/makeInputTemplate'
|
||||||
|
|
||||||
|
|
||||||
@ -78,7 +80,9 @@ test('makeOutput throws TypeError with incorrect amount type', t => {
|
|||||||
|
|
||||||
|
|
||||||
test('Create TRANSFER transaction based on CREATE transaction', t => {
|
test('Create TRANSFER transaction based on CREATE transaction', t => {
|
||||||
const testTx = _makeTransferTransaction(
|
sinon.spy(makeTransaction, 'default')
|
||||||
|
|
||||||
|
Transaction.makeTransferTransaction(
|
||||||
createTx,
|
createTx,
|
||||||
metaDataMessage,
|
metaDataMessage,
|
||||||
[aliceOutput],
|
[aliceOutput],
|
||||||
@ -95,12 +99,18 @@ test('Create TRANSFER transaction based on CREATE transaction', t => {
|
|||||||
)]
|
)]
|
||||||
]
|
]
|
||||||
|
|
||||||
t.deepEqual(testTx, expected)
|
// NOTE: `src/transaction/makeTransaction` is `export default`, hence we
|
||||||
|
// can only mock `makeTransaction.default` with a hack:
|
||||||
|
// See: https://stackoverflow.com/a/33676328/1263876
|
||||||
|
t.truthy(makeTransaction.default.calledWith(...expected))
|
||||||
|
makeTransaction.default.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Create TRANSFER transaction based on TRANSFER transaction', t => {
|
test('Create TRANSFER transaction based on TRANSFER transaction', t => {
|
||||||
const testTx = _makeTransferTransaction(
|
sinon.spy(makeTransaction, 'default')
|
||||||
|
|
||||||
|
Transaction.makeTransferTransaction(
|
||||||
transferTx,
|
transferTx,
|
||||||
metaDataMessage,
|
metaDataMessage,
|
||||||
[aliceOutput],
|
[aliceOutput],
|
||||||
@ -117,5 +127,6 @@ test('Create TRANSFER transaction based on TRANSFER transaction', t => {
|
|||||||
)]
|
)]
|
||||||
]
|
]
|
||||||
|
|
||||||
t.deepEqual(testTx, expected)
|
t.truthy(makeTransaction.default.calledWith(...expected))
|
||||||
|
makeTransaction.default.restore()
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user