Skip to content

Commit 722e3df

Browse files
committed
test(transactions): Add formatter + fix tests
1 parent a09358d commit 722e3df

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

dist/web3data.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/transaction.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ const {
33
ERROR_MESSAGE_TRANSACTION_NO_HASH: NO_HASH
44
} = require('./constants')
55

6-
const {is, get, onFulfilled, onError, throwIf} = require('./utils')
6+
const {
7+
is,
8+
get,
9+
onFulfilled,
10+
onError,
11+
throwIf,
12+
recordsFormatter
13+
} = require('./utils')
714

815
class Transaction {
916
constructor(web3data) {
@@ -14,7 +21,7 @@ class Transaction {
1421
return get(this.web3data, {
1522
endpoint: ENDPOINT,
1623
filterOptions
17-
}).then(onFulfilled, onError)
24+
}).then(onFulfilled.bind({formatter: recordsFormatter}), onError)
1825
}
1926

2027
getTransaction(hash, filterOptions) {

test/transaction.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ const returnsTxnObject = async (t, { method, params = {} }) => {
5252
returnsTxnObject.title = (providedTitle = '', input) => `Successfully calls ${input.method} and returns valid txn object`
5353

5454
const returnsTxnObjects = async (t, { method }) => {
55-
const { records: transactions } = await t.context.web3data.transaction[method]()
55+
const transactions = await t.context.web3data.transaction[method]()
5656
t.true(transactions[0].hasProp('hash'))
5757
t.true(transactions.length > 0)
5858
}
5959
returnsTxnObjects.title = (providedTitle = '', input) => `Successfully calls ${input.method} and returns array of valid txn objects`
6060

6161
const returnsPendingTxnObjects = async (t, { method }) => {
62-
const { records: [pendingTxn]} = await t.context.web3data.transaction[method]()
62+
const [pendingTxn] = await t.context.web3data.transaction[method]()
6363

6464
t.is(pendingTxn.statusResult.name, 'pending')
6565
}
@@ -73,11 +73,11 @@ test([returnsTxnObjects, returnsPendingTxnObjects], {method:'getPendingTransacti
7373

7474
/*********** Test getTransactions() ***********/
7575
test('Successfully calls getTransactions', async t => {
76-
const {records: [txn]} = await t.context.web3data.transaction.getTransactions()
76+
const [txn] = await t.context.web3data.transaction.getTransactions()
7777
t.true(txn.hasProp('hash'))
7878
})
7979
test('Successfully calls getTransactions - with filters', async t => {
80-
const {records: [pendingTxn]} = await t.context.web3data.transaction.getTransactions({status: 'pending'})
80+
const [pendingTxn] = await t.context.web3data.transaction.getTransactions({status: 'pending'})
8181
t.true(pendingTxn.hasProp('statusResult'))
8282
t.true(pendingTxn.statusResult.hasProp('name'))
8383
t.is(pendingTxn.statusResult.name, 'pending')
@@ -96,7 +96,7 @@ test('Successfully calls getTransaction - with filters', async t => {
9696

9797
/*********** Test getPendingTransactions() ***********/
9898
test('Successfully calls getPendingTransactions', async t => {
99-
const {records: [pendingTxn]} = await t.context.web3data.transaction.getPendingTransactions()
99+
const [pendingTxn] = await t.context.web3data.transaction.getPendingTransactions()
100100
t.true(pendingTxn.hasProp('statusResult'))
101101
t.true(pendingTxn.statusResult.hasProp('name'))
102102
t.is(pendingTxn.statusResult.name, 'pending')

test/web3data.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ test('web3data.eth successfully calls method getTransactions', async t => {
107107
})
108108

109109
test('web3data.eth successfully calls method getPendingTransactions', async t => {
110-
const { records: pendTxns } = await t.context.web3data.eth.getPendingTransactions()
110+
const pendTxns = await t.context.web3data.eth.getPendingTransactions()
111111
t.true(pendTxns.length > 0)
112112
})
113113

0 commit comments

Comments
 (0)