Merge branch 'master' into greenkeeper/webpack-3.0.0

This commit is contained in:
Matthias Kretschmann 2017-06-21 15:53:26 +02:00 committed by GitHub
commit 8cd04d647c
10 changed files with 717 additions and 51 deletions

View File

@ -1,2 +1,3 @@
dist
node_modules
node_modules
coverage

3
.gitignore vendored
View File

@ -14,3 +14,6 @@
node_modules
dist
package-lock.json
coverage
coverage.lcov
.nyc_output

View File

@ -18,8 +18,9 @@ before_install:
-e BIGCHAINDB_KEYPAIR_PRIVATE=5C5Cknco7YxBRP9AgB1cbUVTL4FAcooxErLygw1DeG2D
-e BIGCHAINDB_DATABASE_BACKEND=mongodb
-e BIGCHAINDB_DATABASE_HOST=172.17.0.1
bigchaindb/bigchaindb:0.10.2
bigchaindb/bigchaindb:master
start
- npm install -g codecov
script: yarn test

46
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,46 @@
# Contributor Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, sexual identity and orientation, or species—no picking on Wrigley for being a buffalo!
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at conduct@bigchaindb.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View File

@ -3,6 +3,7 @@
> Official JavaScript driver for [BigchainDB](https://github.com/bigchaindb/bigchaindb) with some naive helpers to get you on your way making transactions in Node.js and the browser.
[![npm](https://img.shields.io/npm/v/bigchaindb-driver.svg)](https://www.npmjs.com/package/bigchaindb-driver)
[![codecov](https://codecov.io/gh/bigchaindb/js-bigchaindb-driver/branch/master/graph/badge.svg)](https://codecov.io/gh/bigchaindb/js-bigchaindb-driver)
[![js ascribe](https://img.shields.io/badge/js-ascribe-39BA91.svg)](https://github.com/ascribe/javascript)
[![Build Status](https://travis-ci.org/bigchaindb/js-bigchaindb-driver.svg?branch=master)](https://travis-ci.org/bigchaindb/js-bigchaindb-driver)
[![Greenkeeper badge](https://badges.greenkeeper.io/bigchaindb/js-bigchaindb-driver.svg)](https://greenkeeper.io/)

View File

@ -19,12 +19,16 @@
"build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node",
"build:dist": "cross-env NODE_ENV=production webpack -p",
"clean": "rimraf dist/bundle dist/node",
"test": "npm run lint && ava",
"test": "npm run lint && nyc ava test/ && npm run report-coverage",
"release": "./node_modules/release-it/bin/release.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"release-minor": "./node_modules/release-it/bin/release.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"release-major": "./node_modules/release-it/bin/release.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"prepublishOnly": "npm update && npm run build",
"precommit": "npm run lint"
"precommit": "lint-staged",
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov"
},
"lint-staged": {
"*.js": ["eslint"]
},
"devDependencies": {
"ava": "^0.19.1",
@ -42,11 +46,14 @@
"babel-runtime": "^6.22.0",
"cross-env": "^5.0.1",
"eslint": "^3.14.1",
"eslint-config-ascribe": "^3.0.1",
"eslint-config-ascribe": "^3.0.4",
"eslint-plugin-import": "^2.2.0",
"husky": "^0.13.4",
"lint-staged": "^4.0.0",
"nyc": "^11.0.2",
"release-it": "^2.7.3",
"rimraf": "^2.5.4",
"sinon": "^2.3.4",
"webpack": "^3.0.0"
},
"dependencies": {
@ -65,7 +72,8 @@
"json-stable-stringify": "^1.0.1",
"query-string": "^4.3.4",
"sprintf-js": "^1.0.3",
"tweetnacl": "^1.0.0"
"tweetnacl": "^1.0.0",
"yarn": "^0.24.5"
},
"keywords": [
"bigchaindb",

View File

@ -3,10 +3,13 @@
* Create an Output from a Condition.
* Note: Assumes the given Condition was generated from a single public key (e.g. a Ed25519 Condition)
* @param {object} condition Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
* @param {number} amount Amount of the output
* @param {string} amount Amount of the output
* @returns {object} An Output usable in a Transaction
*/
export default function makeOutput(condition, amount = 1) {
export default function makeOutput(condition, amount = '1') {
if (typeof amount !== 'string') {
throw new TypeError('`amount` must be of type string')
}
return {
'amount': amount,
condition,

View File

@ -14,25 +14,27 @@ import makeTransaction from './makeTransaction'
* 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
* @param {...number} OutputIndices 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
* 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,
metadata,
outputs,
...fulfilledOutputs
...outputIndices
) {
const inputs = fulfilledOutputs.map((outputIndex) => {
const inputs = outputIndices.map((outputIndex) => {
const fulfilledOutput = unspentTransaction.outputs[outputIndex]
const transactionLink = {
'output': outputIndex,
'txid': unspentTransaction.id,
'transaction_id': unspentTransaction.id,
}
return makeInputTemplate(fulfilledOutput.public_keys, transactionLink)

View File

@ -0,0 +1,132 @@
import test from 'ava'
import sinon from 'sinon'
import { Transaction, Ed25519Keypair } from '../../src'
import * as makeTransaction from '../../src/transaction/makeTransaction' // eslint-disable-line
import makeInputTemplate from '../../src/transaction/makeInputTemplate'
// TODO: Find out if ava has something like conftest, if so put this there.
const alice = new Ed25519Keypair()
const aliceCondition = Transaction.makeEd25519Condition(alice.publicKey)
const aliceOutput = Transaction.makeOutput(aliceCondition)
const assetMessage = { assetMessage: 'assetMessage' }
const metaDataMessage = { metaDataMessage: 'metaDataMessage' }
const createTx = Transaction.makeCreateTransaction(
assetMessage,
metaDataMessage,
[aliceOutput],
alice.publicKey
)
const transferTx = Transaction.makeTransferTransaction(
createTx,
metaDataMessage,
[aliceOutput],
0
)
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)
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)
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)
t.deepEqual(res, expected)
})
test('makeOutput throws TypeError with incorrect amount type', t => {
t.throws(() => Transaction.makeOutput({}, 1337), TypeError)
})
test('Create TRANSFER transaction based on CREATE transaction', t => {
sinon.spy(makeTransaction, 'default')
Transaction.makeTransferTransaction(
createTx,
metaDataMessage,
[aliceOutput],
0
)
const expected = [
'TRANSFER',
{ id: createTx.id },
metaDataMessage,
[aliceOutput],
[makeInputTemplate(
[alice.publicKey],
{ output: 0, transaction_id: createTx.id }
)]
]
// 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 => {
sinon.spy(makeTransaction, 'default')
Transaction.makeTransferTransaction(
transferTx,
metaDataMessage,
[aliceOutput],
0
)
const expected = [
'TRANSFER',
{ id: transferTx.asset.id },
metaDataMessage,
[aliceOutput],
[makeInputTemplate(
[alice.publicKey],
{ output: 0, transaction_id: transferTx.id }
)]
]
t.truthy(makeTransaction.default.calledWith(...expected))
makeTransaction.default.restore()
})

543
yarn.lock

File diff suppressed because it is too large Load Diff