2017-06-16 11:12:56 +02:00
|
|
|
import test from 'ava'
|
2017-06-16 11:22:23 +02:00
|
|
|
import { Ed25519Keypair, Transaction, Connection } from '../src'
|
2017-06-08 14:09:23 +02:00
|
|
|
|
2017-06-16 11:22:23 +02:00
|
|
|
const API_PATH = 'http://localhost:9984/api/v1/'
|
|
|
|
|
|
|
|
test('Keypair is created', t => {
|
|
|
|
const keyPair = new Ed25519Keypair()
|
|
|
|
|
|
|
|
t.truthy(keyPair.publicKey)
|
|
|
|
t.truthy(keyPair.privateKey)
|
2017-06-16 11:12:56 +02:00
|
|
|
})
|
2017-06-08 14:09:23 +02:00
|
|
|
|
2017-06-16 11:22:23 +02:00
|
|
|
test('Valid CREATE transaction is evaluated by BigchainDB', t => {
|
|
|
|
const alice = new Ed25519Keypair()
|
|
|
|
const asset = { name: 'Shmui', type: 'cat' }
|
|
|
|
const metadata = { dayOfTheWeek: 'Caturday' }
|
2017-06-08 14:09:23 +02:00
|
|
|
|
2017-06-16 11:22:23 +02:00
|
|
|
const tx = Transaction.makeCreateTransaction(
|
|
|
|
asset,
|
|
|
|
metadata,
|
|
|
|
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
|
|
|
|
alice.publicKey
|
|
|
|
)
|
|
|
|
|
|
|
|
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
|
|
|
|
const conn = new Connection(API_PATH)
|
|
|
|
return conn.postTransaction(txSigned)
|
|
|
|
.then(resTx => t.truthy(resTx))
|
2017-06-16 11:12:56 +02:00
|
|
|
})
|
2017-06-16 11:22:23 +02:00
|
|
|
|