Skip to content

BigchainDB outputs endpoint is not giving correct unspent outputs #2552

@future-is-present

Description

@future-is-present

bigchaindb JS driver tests run by Travis are failing.
The js driver is using the master branch of BigchainDB.
How to reproduce:

-a) Run this test: https://github.com/bigchaindb/js-bigchaindb-driver/blob/master/test/integration/test_integration.js#L286

-b) Create and post a CREATE transaction with three different outputs with the same public key. Create and post a TRANSFER transaction that spends the second output of the previous transaction and send it to another different public key. Query for spend outputs for the first public key. You won't find any output spent.

-c) Code snippet to reproduce the error for node.js:

var BigchainDB = require('bigchaindb-driver')
var bip39 = require('bip39')

const alice = new BigchainDB.Ed25519Keypair(bip39.mnemonicToSeed('alice one').slice(0, 32))
const bob = new BigchainDB.Ed25519Keypair(bip39.mnemonicToSeed('bob one').slice(0, 32))

const API_PATH = 'http://127.0.0.1:9984/api/v1/'
const conn = new BigchainDB.Connection(API_PATH, {
     app_id: '',
    app_key: ''
})


const aliceOutput = BigchainDB.Transaction.makeOutput(
    BigchainDB.Transaction.makeEd25519Condition(alice.publicKey))
const bobOutput = BigchainDB.Transaction.makeOutput(
        BigchainDB.Transaction.makeEd25519Condition(bob.publicKey))

Create()
async function Create(){
    const txCreate = BigchainDB.Transaction.makeCreateTransaction(
        // Define the asset to store, in this example it is the current temperature
        // (in Celsius) for the city of Berlin.
        {
            'timestamp': Date.now()
        }, {
            'entity': 'aaa'
        },
        // enemy is the owner
        [aliceOutput, aliceOutput, aliceOutput],
        alice.publicKey
    )
    
    // Sign the transaction with private keys
    const createSigned = BigchainDB.Transaction.signTransaction(txCreate, alice.privateKey)
    
    await conn.postTransactionCommit(createSigned)
        .then(res => {
            console.log('createEnemy function finished. ', res.id, 'accepted')
        })
    
    
    const createTranfer = BigchainDB.Transaction.makeTransferTransaction(
        [{
            tx: createSigned,
            output_index: 1
        }],
        [bobOutput], {
            'timestamp': Date.now()
        }
    
    )
    const signedTransfer = BigchainDB.Transaction.signTransaction(createTranfer, alice.privateKey)
    
    await conn.postTransactionCommit(signedTransfer)
        .then(res => {
            console.log('updateGroup function finished, ', res.id, 'accepted')
        })
    

    const spentOutputs = await conn.listOutputs(alice.publicKey, true)
    console.log('Spent outputs, expected 1', spentOutputs)
    const unspenttOutputs = await conn.listOutputs(alice.publicKey, false)
    console.log('Spent outputs, expected 2', unspenttOutputs)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions