This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a util for explorer functionality + unit tests (#448)
* Add a util for explorer functionality + unit tests t * Print the explorer url for sendMoney * Nit: fix lint errors * Fix dangling inspectResponse reference in call.js * Undo a change to .eslintrc.yml * Tweaks to shell output on near send
- Loading branch information
1 parent
baa62ea
commit 0913ec5
Showing
12 changed files
with
116 additions
and
12 deletions.
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
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,27 @@ | ||
|
||
const explorer = require('../../utils/explorer'); | ||
|
||
describe('generate explorer link', () => { | ||
test('on environment with a known url', async () => { | ||
const config = require('../../config')('development'); | ||
const url = explorer.generateTransactionUrl('61Uc5f7L42SDWFPYHx7goMc2xEN7YN4fgtw9baHA82hY', config); | ||
expect(url).toEqual('https://explorer.testnet.near.org/transactions/61Uc5f7L42SDWFPYHx7goMc2xEN7YN4fgtw9baHA82hY'); | ||
}); | ||
|
||
test('on environment with an unknown url', async () => { | ||
const config = require('../../config')('ci'); | ||
const url = explorer.generateTransactionUrl('61Uc5f7L42SDWFPYHx7goMc2xEN7YN4fgtw9baHA82hY', config); | ||
expect(url).toEqual(null); | ||
}); | ||
|
||
test('unknown txn id', async () => { | ||
const config = require('../../config')('development'); | ||
const url = explorer.generateTransactionUrl(null, config); | ||
expect(url).toEqual(null); | ||
}); | ||
|
||
test('null options', async () => { | ||
const url = explorer.generateTransactionUrl('61Uc5f7L42SDWFPYHx7goMc2xEN7YN4fgtw9baHA82hY', null); | ||
expect(url).toEqual(null); | ||
}); | ||
}); |
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,20 @@ | ||
const inspectResponse = require('../../utils/inspect-response'); | ||
|
||
describe('getTxnId', () => { | ||
test('with expected data format', async () => { | ||
const data = { | ||
transaction: { | ||
hash: 'BF1iyVWTkagisho3JKKUXiPQu2sMuuLsEbvQBDYHHoKE' | ||
} | ||
}; | ||
expect(inspectResponse.getTxnId(data)).toEqual('BF1iyVWTkagisho3JKKUXiPQu2sMuuLsEbvQBDYHHoKE'); | ||
}); | ||
|
||
test('with null response', async () => { | ||
expect(inspectResponse.getTxnId(null)).toEqual(null); | ||
}); | ||
|
||
test('with null transaction inside response', async () => { | ||
expect(inspectResponse.getTxnId({})).toEqual(null); | ||
}); | ||
}); |
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,22 @@ | ||
// Handle functionality related to explorer | ||
|
||
const generateTransactionUrl = (txnId, options) => { | ||
if (!txnId || !options) { | ||
return null; | ||
} | ||
const explorerUrl = options.explorerUrl; | ||
return explorerUrl ? `${explorerUrl}/transactions/${txnId}` : null; | ||
}; | ||
|
||
const printTransactionUrl = (txnId, options) => { | ||
const txnUrl = generateTransactionUrl(txnId, options); | ||
if (txnUrl) { | ||
console.log('To see the transaction in the transaction explorer, please open this url in your browser'); | ||
console.log(txnUrl); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
generateTransactionUrl, | ||
printTransactionUrl, | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,24 @@ | ||
|
||
const util = require('util'); | ||
module.exports = (response) => { | ||
const prettyPrintResponse = (response) => { | ||
return util.inspect(response, { showHidden: true, depth: null, colors: true, maxArrayLength: null }); | ||
}; | ||
|
||
const getTxnId = (response) => { | ||
// Currently supported response format: | ||
//{ | ||
// ... | ||
// transaction: { | ||
// ... | ||
// hash: 'BF1iyVWTkagisho3JKKUXiPQu2sMuuLsEbvQBDYHHoKE' | ||
// }, | ||
if (!response || !response.transaction) { | ||
return null; | ||
} | ||
return response.transaction.hash; | ||
}; | ||
|
||
module.exports = { | ||
prettyPrintResponse, | ||
getTxnId, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.