-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated data models for 1.0 #35
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0ed3aa3
fulfills.txid ==> fulfills.transaction_id
27d8dab
Stringify output.amount
a14dbba
Add tests for makeOutput
b824158
fulfills.txid => fulfills.transaction_id + tests
ed18384
Bump ascribe-eslint-config
9183205
Use rest params in fn definition
3389726
Test against BDB:master
ac0a124
Remove unnecessary returns
42b4002
Add sinon.js (mocks) to package.json
ede11da
Correct mocking of export default
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use output of respective functions as strings/dicts here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created an issue: #45 |
||
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() | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing we want to change this to 1.0.0rc1 at some point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup