1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 01:36:56 +01:00

fix: update tests to latest AVA API

Signed-off-by: getlarge <ed@getlarge.eu>
This commit is contained in:
getlarge 2021-03-09 10:57:37 +01:00
parent dc7634c9db
commit 736b2adc37
No known key found for this signature in database
GPG Key ID: E4E13243600F9566
8 changed files with 24 additions and 87 deletions

View File

@ -20,14 +20,11 @@ test('HandleResponse does not throw error for response ok', t => {
})
test('baseRequest test query and vsprint', async t => {
const target = {
message: 'HTTP Error: Requested page not reachable',
requestURI: 'https://www.google.com/teapot',
status: '418 I\'m a Teapot',
}
const error = await t.throws(baseRequest('https://%s.com/', {
const error = await t.throwsAsync(baseRequest('https://%s.com/', {
urlTemplateSpec: ['google'],
query: 'teapot'
}))
t.deepEqual(target, error)
}), { instanceOf: Error, message: 'HTTP Error: Requested page not reachable' })
t.is(error.requestURI, 'https://www.google.com/teapot')
t.is(error.status, '418 I\'m a Teapot')
})

View File

@ -22,8 +22,13 @@ test('Payload thrown at incorrect API_PATH', async t => {
status: '404 NOT FOUND',
requestURI: 'http://localhost:9984/api/wrong/transactions/transactionId'
}
const error = await t.throws(connection.getTransaction('transactionId'))
t.deepEqual(target, error)
const error = await t.throwsAsync(connection.getTransaction('transactionId'), {
instanceOf: Error, message: target.message
})
t.is('ResponseError', error.name)
t.is(target.status, error.status)
t.is(target.requestURI, error.requestURI)
})
test('Generate API URLS', t => {
@ -100,7 +105,6 @@ test('Request with custom headers', t => {
t.truthy(testConn.transport.forwardRequest.calledWith(PATH, expectedOptions))
})
test('Get block for a block id', t => {
const expectedPath = 'path'
const blockHeight = 'abc'
@ -115,7 +119,6 @@ test('Get block for a block id', t => {
))
})
test('Get transaction for a transaction id', t => {
const expectedPath = 'path'
const transactionId = 'abc'
@ -130,7 +133,6 @@ test('Get transaction for a transaction id', t => {
))
})
test('Get list of blocks for a transaction id', t => {
const expectedPath = 'path'
const transactionId = 'abc'
@ -149,7 +151,6 @@ test('Get list of blocks for a transaction id', t => {
))
})
test('Get list of transactions for an asset id', t => {
const expectedPath = 'path'
const assetId = 'abc'
@ -170,7 +171,6 @@ test('Get list of transactions for an asset id', t => {
))
})
test('Get outputs for a public key and no spent flag', t => {
const expectedPath = 'path'
const publicKey = 'publicKey'
@ -185,7 +185,6 @@ test('Get outputs for a public key and no spent flag', t => {
))
})
test('Get outputs for a public key and spent=false', t => {
const expectedPath = 'path'
const publicKey = 'publicKey'
@ -201,7 +200,6 @@ test('Get outputs for a public key and spent=false', t => {
))
})
test('Get outputs for a public key and spent=true', t => {
const expectedPath = 'path'
const publicKey = 'publicKey'
@ -217,7 +215,6 @@ test('Get outputs for a public key and spent=true', t => {
))
})
test('Get asset for text', t => {
const expectedPath = 'path'
const search = 'abc'
@ -232,7 +229,6 @@ test('Get asset for text', t => {
))
})
test('Get metadata for text', t => {
const expectedPath = 'path'
const search = 'abc'

View File

@ -17,7 +17,6 @@ import {
delegatedSignTransaction
} from '../constants'
test('Keypair is created', t => {
const keyPair = new Ed25519Keypair()
@ -25,10 +24,6 @@ test('Keypair is created', t => {
t.truthy(keyPair.privateKey)
})
// TODO: The following tests are a bit messy currently, please do:
//
// - tidy up dependency on `pollStatusAndFetchTransaction`
test('Valid CREATE transaction with default node', t => {
const conn = new Connection()
@ -46,7 +41,6 @@ test('Valid CREATE transaction with default node', t => {
})
})
test('Valid CREATE transaction using async', t => {
const conn = new Connection(API_PATH)
@ -62,7 +56,6 @@ test('Valid CREATE transaction using async', t => {
.then(resTx => t.truthy(resTx))
})
test('Valid CREATE transaction using sync', t => {
const conn = new Connection(API_PATH)
@ -78,7 +71,6 @@ test('Valid CREATE transaction using sync', t => {
.then(resTx => t.truthy(resTx))
})
test('Valid TRANSFER transaction with single Ed25519 input', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
@ -108,7 +100,6 @@ test('Valid TRANSFER transaction with single Ed25519 input', t => {
})
})
test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
@ -139,7 +130,6 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
})
})
test('Valid TRANSFER transaction with multiple Ed25519 inputs from different transactions', t => {
const conn = new Connection(API_PATH)
const carol = new Ed25519Keypair()
@ -264,7 +254,6 @@ test('Search for spent and unspent outputs of a given public key', t => {
const trentCondition = Transaction.makeEd25519Condition(trent.publicKey)
const trentOutput = Transaction.makeOutput(trentCondition)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
@ -295,7 +284,6 @@ test('Search for spent and unspent outputs of a given public key', t => {
.then(outputs => t.truthy(outputs.length === 2))
})
test('Search for unspent outputs for a given public key', t => {
const conn = new Connection(API_PATH)
const carol = new Ed25519Keypair()
@ -335,7 +323,6 @@ test('Search for unspent outputs for a given public key', t => {
.then(outputs => t.truthy(outputs.length === 2))
})
test('Search for spent outputs for a given public key', t => {
const conn = new Connection(API_PATH)
const carol = new Ed25519Keypair()
@ -375,7 +362,6 @@ test('Search for spent outputs for a given public key', t => {
.then(outputs => t.truthy(outputs.length === 1))
})
test('Search for an asset', t => {
const conn = new Connection(API_PATH)
@ -398,7 +384,6 @@ test('Search for an asset', t => {
))
})
test('Search for metadata', t => {
const conn = new Connection(API_PATH)
@ -421,7 +406,6 @@ test('Search for metadata', t => {
))
})
test('Search blocks containing a transaction', t => {
const conn = new Connection(API_PATH)
@ -443,7 +427,6 @@ test('Search blocks containing a transaction', t => {
.then(transactions => t.truthy(transactions.length === 1))
})
test('Search transaction containing an asset', t => {
const conn = new Connection(API_PATH)
@ -465,7 +448,8 @@ test('Search transaction containing an asset', t => {
})
})
test('Content-Type cannot be set', t => {
t.throws(() => new Connection(API_PATH, { 'Content-Type': 'application/json' }), Error)
t.throws(() => new Connection(API_PATH, { 'Content-Type': 'application/json' }), {
instanceOf: Error
})
})

View File

@ -5,7 +5,6 @@
import test from 'ava'
import Connection from '../../src/connection'
const conn = new Connection()
test('Ensure that BackoffTimedelta works properly', t => {
@ -18,14 +17,10 @@ test('Ensure that BackoffTimedelta works properly', t => {
test('Ensure that updateBackoffTime throws and error on TimeoutError', async t => {
const req = conn.transport.pickConnection()
const target = {
message: 'TimeoutError'
}
req.connectionError = target
const errorMessage = 'TimeoutError'
req.connectionError = new Error(errorMessage)
const error = t.throws(() => {
t.throws(() => {
req.updateBackoffTime()
})
t.deepEqual(target, error)
}, { instanceOf: Error, message: errorMessage })
})

View File

@ -9,7 +9,6 @@ const sanitize = rewire('../../src/sanitize.js')
const applyFilterOnObject = sanitize.__get__('applyFilterOnObject')
const filterFromObject = sanitize.__get__('filterFromObject')
test('Ensure that null filter returns same object', t => {
const expected = { 'testObj': 'test' }
const actual = applyFilterOnObject({ 'testObj': 'test' }, null)
@ -17,7 +16,6 @@ test('Ensure that null filter returns same object', t => {
t.deepEqual(actual, expected)
})
test('Ensure function filter with isInclusion true works properly', t => {
const testObj = [true, false, undefined, '', 0, null]
const expected = { 0: true }
@ -26,7 +24,6 @@ test('Ensure function filter with isInclusion true works properly', t => {
t.deepEqual(actual, expected)
})
test('Ensure function filter with isInclusion false works properly', t => {
const testObj = [false, true, 1, 10, 'this will be removed as it is truthy']
const expected = { 0: false }
@ -35,7 +32,6 @@ test('Ensure function filter with isInclusion false works properly', t => {
t.deepEqual(actual, expected)
})
test('Ensure array filter with isInclusion true works properly', t => {
const testObj = [true, false, undefined, '', 0, null]
const expected = { 0: true }
@ -44,7 +40,6 @@ test('Ensure array filter with isInclusion true works properly', t => {
t.deepEqual(actual, expected)
})
test('Ensure array filter with isInclusion false works properly', t => {
const testObj = [false, true, 1, 10]
const expected = { 0: false }
@ -53,12 +48,8 @@ test('Ensure array filter with isInclusion false works properly', t => {
t.deepEqual(actual, expected)
})
test('Ensure throws error when given invalid filter', t => {
const error = t.throws(() => {
t.throws(() => {
filterFromObject({}, 'lol')
}, Error)
t.is(error.message, 'The given filter is not an array or function. Filter aborted')
}, { instanceOf: Error, message: 'The given filter is not an array or function. Filter aborted' })
})

View File

@ -41,12 +41,10 @@ test('formatText test type 3', t => {
})
test('formatText test throws', t => {
const error = t.throws(() => {
t.throws(() => {
formatText(
'This will give ${error.}', // eslint-disable-line no-template-curly-in-string
{ error: [{}] }
)
}, SyntaxError)
t.is(error.message, '[formatText] failed to parse named argument key: error.')
}, { instanceOf: SyntaxError, message: '[formatText] failed to parse named argument key: error.' })
})

View File

@ -34,7 +34,6 @@ test('Sha256Condition fulfillment', t => {
t.deepEqual(target, Transaction.makeSha256Condition(preimage))
})
test('Threshold condition encoding', t => {
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
const ed25519 = Transaction.makeEd25519Condition(publicKey, false)
@ -64,7 +63,6 @@ test('Threshold condition encoding', t => {
t.deepEqual(target, output)
})
test('Fulfillment correctly formed', t => {
const alice = new Ed25519Keypair()
const txCreate = Transaction.makeCreateTransaction(
@ -115,23 +113,6 @@ test('Delegated signature is correct', t => {
t.deepEqual(signCreateTransaction, delegatedSignCreateTransaction)
})
test('CryptoConditions JSON load', t => {
const cond = ccJsonLoad({
type: 'threshold-sha-256',
threshold: 1,
subconditions: [{
type: 'ed25519-sha-256',
public_key: 'a'
},
{
hash: 'a'
}],
})
t.truthy(cond.subconditions.length === 2)
})
test('CryptoConditions JSON load', t => {
const cond = ccJsonLoad({
type: 'threshold-sha-256',

View File

@ -15,7 +15,6 @@ import {
transferTx
} from '../constants'
test('Create valid output with default amount', t => {
const condition = {
details: {
@ -32,7 +31,6 @@ test('Create valid output with default amount', t => {
t.deepEqual(res, expected)
})
test('Create valid output with custom amount', t => {
const condition = {
details: {
@ -65,12 +63,10 @@ test('Pass condition not based on public_keys to makeOutput', t => {
t.deepEqual(res, expected)
})
test('makeOutput throws TypeError with incorrect amount type', t => {
t.throws(() => Transaction.makeOutput({}, 1337), TypeError)
t.throws(() => Transaction.makeOutput({}, 1337), { instanceOf: TypeError })
})
test('Create TRANSFER transaction based on CREATE transaction', t => {
sinon.spy(Transaction, 'makeTransaction')
Transaction.makeTransferTransaction(
@ -95,7 +91,6 @@ test('Create TRANSFER transaction based on CREATE transaction', t => {
Transaction.makeTransaction.restore()
})
test('Create TRANSFER transaction based on TRANSFER transaction', t => {
sinon.spy(Transaction, 'makeTransaction')