-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from VerusCoin/dev
Dev
- Loading branch information
Showing
364 changed files
with
10,278 additions
and
3,508 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const mocked_results = require('./mocked_results/mocked_results.js') | ||
const DEFAULT_ELECTRUM_SERVER_VERSION = ["ElectrumX"] | ||
|
||
/** | ||
* Mock of the react-native-fetch http call function. If the URL is an electrum string, | ||
* it will parse the electrum data, and use it to return mock electrum data. Possible | ||
* electrum servers follow the format status:<success||fail>-code:<result code>-eproto:<electrum protocol version>-params:<stringified parameter object to pass to mock function> | ||
* @param {String} url The full URL to fetch. Test commands should be included in here | ||
* @param {Object} payload Fetch type, body, headers etc. | ||
*/ | ||
const fetch = function(url, payload) { | ||
|
||
if (url.endsWith('mock.proxy.server')) { | ||
return new Promise((resolve) => (resolve({status: 200}))) | ||
} | ||
|
||
const original_ip_regex = /\/{1}[^\/\n]+?\// | ||
const url_ip = url.match(original_ip_regex)[0].slice(1,-1) | ||
|
||
if (url_ip == 'mock.proxy.server') { | ||
const url_params_regex = /&[^\/\n]+?$/ | ||
const electrum_cmd_regex = /api\/{1}[^\n]+?\?/ | ||
const electrum_cmd = url.match(electrum_cmd_regex)[0].slice(4,-1).replace('/', '_') | ||
const electrum_params = url.match(url_params_regex)[0].slice(1).split('&') | ||
let params_obj = {} | ||
|
||
electrum_params.map((param) => { | ||
const param_split = param.split('=') | ||
params_obj[param_split[0]] = param_split[1] | ||
}) | ||
|
||
return new Promise((resolve) => { | ||
const test_params = JSON.parse(params_obj.ip.replace(/\|/g, ':')) | ||
const mock_function = mocked_results[electrum_cmd] | ||
|
||
if (test_params.success) { | ||
if (test_params.params[electrum_cmd] == null) throw new Error(`No params specified for ${electrum_cmd} command. Please include them when calling mock fetch, or set them to [] to use the commands passed to the function.`) | ||
else if (test_params.params[electrum_cmd].length === 0) { | ||
//If params are left empty, call mock function with default supplied params sorted in alphabetical order by their key names | ||
delete params_obj.ip | ||
delete params_obj.port | ||
delete params_obj.proto | ||
|
||
let supplied_params = Object.keys(params_obj).sort() | ||
supplied_params = supplied_params.map((value_key) => params_obj[value_key]) | ||
|
||
resolve({json: () => {return {msg: 'success', result: mock_function(...supplied_params)}}}) | ||
} else resolve({json: () => {return {msg: 'success', result: mock_function(...test_params.params[electrum_cmd])}}}) | ||
} else { | ||
resolve({json: () => {return {msg: 'error', result: `code ${test_params.code}: ${test_params.error_msg}`}}}) | ||
} | ||
}) | ||
} else { | ||
throw new Error("Test fetch function called with incompatible mock parameters, try using the real fetch function.") | ||
} | ||
} | ||
|
||
module.exports = fetch |
900 changes: 900 additions & 0 deletions
900
__mocks__/react-native-fetch/mocked_results/blockchain_data.js
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
//TODO: Add mock for estimatefee |
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,10 @@ | ||
/** | ||
* This returns a getbalance result based on the supplied confirmed and unconfirmed balances | ||
* @param {Number} confirmed Confirmed balance to return | ||
* @param {Number} unconfirmed Unconfirmed balance to return | ||
*/ | ||
const getbalance_mock = function(confirmed, unconfirmed) { | ||
return {confirmed, unconfirmed} | ||
} | ||
|
||
module.exports = getbalance_mock |
14 changes: 14 additions & 0 deletions
14
__mocks__/react-native-fetch/mocked_results/getblockinfo.js
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,14 @@ | ||
const gotten_blocks = require('./blockchain_data').gotten_blocks | ||
|
||
/** | ||
* The mock for getblockinfo. This function searches through the mock block list, and returns a block info object if it is found. | ||
* @param {Integer} height The blockheight of the block to get. If found in the mock block list, its info will be returned. | ||
*/ | ||
const getblockinfo_mock = function(height) { | ||
if (Number(height) < 0 || Number(height) % 1 != 0) return {"code":1,"message":`${height} should be a non-negative integer`} | ||
if (gotten_blocks.hasOwnProperty(height)) return gotten_blocks[height] | ||
|
||
return {"code":1,"message":`height ${height} out of range`} | ||
} | ||
|
||
module.exports = getblockinfo_mock |
9 changes: 9 additions & 0 deletions
9
__mocks__/react-native-fetch/mocked_results/getcurrentblock.js
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,9 @@ | ||
/** | ||
* This returns a getcurrentblock result based on the supplied height | ||
* @param {Number} height The blockheight you would like returned from the API call | ||
*/ | ||
const getcurrentblock_mock = function(height) { | ||
return height | ||
} | ||
|
||
module.exports = getcurrentblock_mock |
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,15 @@ | ||
const merkle_roots = require('./blockchain_data').merkle_roots | ||
|
||
/** | ||
* The mock for getmerkle. This function searches through the mock merkle root list, and returns a merkle root if it is found. | ||
* @param {Integer} height The blockheight of the utxo to fetch merkle hashes for. | ||
* @param {String} txid The txid string of the transaction to fetch merkle hashes for. | ||
*/ | ||
const getmerkle_mock = function(height, txid) { | ||
if (merkle_roots.hasOwnProperty(`${txid}-${height}`)) return merkle_roots[`${txid}-${height}`] | ||
|
||
return {"code":1,"message":`${txid} should be a transaction hash`} | ||
} | ||
|
||
|
||
module.exports = getmerkle_mock |
13 changes: 13 additions & 0 deletions
13
__mocks__/react-native-fetch/mocked_results/gettransaction.js
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,13 @@ | ||
const gotten_utxos = require('./blockchain_data').gotten_utxos | ||
|
||
/** | ||
* The mock for gettransaction. This function searches through the mock UTXO list, and returns a transaction hash if it is found. | ||
* @param {String} txid The txid string of the transaction to get. If found in the mock UTXO list, its hash will be returned. | ||
*/ | ||
const gettransaction_mock = function(txid) { | ||
if (gotten_utxos.hasOwnProperty(txid)) return gotten_utxos[txid] | ||
|
||
return { status: 'not found' } | ||
} | ||
|
||
module.exports = gettransaction_mock |
17 changes: 17 additions & 0 deletions
17
__mocks__/react-native-fetch/mocked_results/listtransactions.js
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,17 @@ | ||
const transaction_list = require('./blockchain_data').transaction_list | ||
|
||
/** | ||
* Mocks an electrum call to listtransactions, and returns a specified number | ||
* of transactions | ||
* @param {Integer} num_txs The number of txs to return | ||
*/ | ||
const listtransactions_mock = function(num_txs) { | ||
let returned_txs = [] | ||
for (let i = 0; i < num_txs; i++) { | ||
returned_txs.push(transaction_list[Math.round(Math.random() * (transaction_list.length - 1))]) | ||
} | ||
|
||
return returned_txs | ||
} | ||
|
||
module.exports = listtransactions_mock |
17 changes: 17 additions & 0 deletions
17
__mocks__/react-native-fetch/mocked_results/listunspent.js
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,17 @@ | ||
const unspent_utxos = require('./blockchain_data').unspent_utxos | ||
|
||
/** | ||
* Mocks an electrum call to listunspent, and returns a specified number | ||
* of unspent UTXOs | ||
* @param {Integer} num_utxos The number of unspent utxos to return | ||
*/ | ||
const listunspent_mock = function(num_utxos) { | ||
let returned_utxos = [] | ||
for (let i = 0; i < num_utxos; i++) { | ||
returned_utxos.push(unspent_utxos[Math.round(Math.random() * (unspent_utxos.length - 1))]) | ||
} | ||
|
||
return returned_utxos | ||
} | ||
|
||
module.exports = listunspent_mock |
19 changes: 19 additions & 0 deletions
19
__mocks__/react-native-fetch/mocked_results/mocked_results.js
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,19 @@ | ||
const getbalance_mock = require("./getbalance.js") | ||
const getblockinfo_mock = require("./getblockinfo.js") | ||
const getcurrentblock_mock = require("./getcurrentblock.js") | ||
const getmerkle_mock = require("./getmerkle.js") | ||
const gettransaction_mock = require("./gettransaction.js") | ||
const listtransactions_mock = require("./listtransactions.js") | ||
const listunspent_mock = require("./listunspent.js") | ||
const server_version_mock = require("./server_version.js") | ||
|
||
module.exports = { | ||
getbalance: getbalance_mock, | ||
getblockinfo: getblockinfo_mock, | ||
getcurrentblock: getcurrentblock_mock, | ||
getmerkle: getmerkle_mock, | ||
gettransaction: gettransaction_mock, | ||
listtransactions: listtransactions_mock, | ||
listunspent: listunspent_mock, | ||
server_version: server_version_mock | ||
} |
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 @@ | ||
//TODO: Add mock for pushtx |
11 changes: 11 additions & 0 deletions
11
__mocks__/react-native-fetch/mocked_results/server_version.js
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,11 @@ | ||
/** | ||
* Returns a server version object with the specified version passed in | ||
* @param {String} version_string Server version string, traditonally in the format 'ElectrumX x.x.x' | ||
* @param {Number} version_int (Optional) Version integer, in the format x.x. If omitted, return will be 'ElectrumX' | ||
*/ | ||
const server_version_mock = function(version_string, version_int) { | ||
if (version_int == null) return 'ElectrumX' | ||
return [ version_string, version_int.toString() ] | ||
} | ||
|
||
module.exports = server_version_mock |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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
Empty file.
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
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified
0
android/app/bin/src/main/assets/fonts/FontAwesome5_Regular.ttf
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified
0
android/app/bin/src/main/assets/fonts/MaterialCommunityIcons.ttf
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified
0
android/app/bin/src/main/java/com/verusmobile/MainActivity.class
100644 → 100755
Empty file.
Empty file modified
0
android/app/bin/src/main/java/com/verusmobile/MainApplication.class
100644 → 100755
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified
0
android/app/bin/src/main/res/mipmap-hdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified
0
android/app/bin/src/main/res/mipmap-mdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified
0
android/app/bin/src/main/res/mipmap-xhdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified
0
android/app/bin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified
0
android/app/bin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
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
Empty file.
Empty file.
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
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Oops, something went wrong.