1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2025-02-14 21:10:32 +01:00

Add test makeFulfillment

This commit is contained in:
manolodewiner 2017-11-08 15:06:16 +01:00
parent 35be96e31d
commit e48636d075
5 changed files with 60 additions and 9 deletions

View File

@ -1,4 +1,4 @@
export default function createFulfillment(issuers = []) {
export default function makeFulfillment(issuers = []) {
if (issuers.length === 1) {
const fulfillment = {
type: 'ed25519-sha-256',

View File

@ -22,7 +22,7 @@ export default function makeTransaction(operation, asset, metadata = null, outpu
tx.operation = operation
tx.asset = asset
tx.metadata = metadata
tx.inputs = inputs
tx.inputs = realInputs
tx.outputs = outputs
// Hashing must be done after, as the hash is of the Transaction (up to now)
@ -30,6 +30,6 @@ export default function makeTransaction(operation, asset, metadata = null, outpu
input.fulfillment = null
})
tx.id = hashTransaction(tx)
tx.inputs = realInputs
tx.inputs = inputs
return tx
}

View File

@ -42,6 +42,24 @@ test('Valid CREATE transaction', t => {
})
test('Valid CREATE transaction with Threshold input', t => {
const conn = new Connection(API_PATH)
const tx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey,
bob.publicKey
)
const txSigned = Transaction.signTransaction(tx, alice.privateKey, bob.privateKey)
return conn.postTransaction(txSigned)
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
.then(resTx => t.truthy(resTx))
})
test('Valid TRANSFER transaction with single Ed25519 input', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
@ -109,6 +127,39 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
})
})
test('Valid TRANSFER transaction with Threshold input', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey,
bob.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey,
bob.privateKey
)
return conn.postTransaction(createTxSigned)
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
.then(() => {
const transferTx = Transaction.makeTransferTransaction(
createTxSigned,
metaData,
[aliceOutput],
0
)
const transferTxSigned = Transaction.signTransaction(
transferTx,
alice.privateKey
)
return conn.postTransaction(transferTxSigned)
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
.then(resTx => t.truthy(resTx))
})
})
test('Search for spent and unspent outputs of a given public key', t => {
const conn = new Connection(API_PATH)
@ -214,7 +265,6 @@ test('Search for spent outputs for a given public key', t => {
)
const createTxSigned = Transaction.signTransaction(
createTx,
carol.privateKey,
carol.privateKey
)

View File

@ -62,9 +62,7 @@ test('Fulfillment correctly formed', t => {
[0]
)
const txSigned = Transaction.signTransaction(txTransfer, alice.privateKey)
txTransfer.inputs.forEach((input) => {
input.fulfillment = null // OJOOO
})
const msg = Transaction.serializeTransactionIntoCanonicalString(txTransfer)
t.truthy(cc.validateFulfillment(txSigned.inputs[0].fulfillment,
txCreate.outputs[0].condition.uri,

View File

@ -4,6 +4,7 @@ import sinon from 'sinon'
import { Transaction } from '../../src'
import * as makeTransaction from '../../src/transaction/makeTransaction' // eslint-disable-line
import makeInputTemplate from '../../src/transaction/makeInputTemplate'
import makeFulfillment from '../../src/transaction/makeFulfillment'
import {
alice,
@ -85,7 +86,8 @@ test('Create TRANSFER transaction based on CREATE transaction', t => {
[aliceOutput],
[makeInputTemplate(
[alice.publicKey],
{ output_index: 0, transaction_id: createTx.id }
{ output_index: 0, transaction_id: createTx.id },
makeFulfillment([alice.publicKey])
)]
]
@ -113,7 +115,8 @@ test('Create TRANSFER transaction based on TRANSFER transaction', t => {
[aliceOutput],
[makeInputTemplate(
[alice.publicKey],
{ output_index: 0, transaction_id: transferTx.id }
{ output_index: 0, transaction_id: transferTx.id },
makeFulfillment([alice.publicKey])
)]
]