Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

feat: functional core tests #33

Merged
merged 6 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exit: true
timeout: 150000
file:
- ./lib/test/bootstrap.js
48 changes: 45 additions & 3 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Usage: test <seed> [options]

DAPI_SEED="$1"

DIR="$( cd -P "$( dirname "$BASH_SOURCE[0]" )" >/dev/null 2>&1 && pwd )"

if [ -z "$DAPI_SEED" ] || [[ $DAPI_SEED == -* ]]
then
echo "Seed is not specified"
Expand Down Expand Up @@ -53,12 +55,52 @@ done

if [ -n "$npm_package_to_install" ]
then
cd .. && npm install "$npm_package_to_install"
cd "$DIR"/.. && npm install "$npm_package_to_install"
fi



if [ -n "$scope" ]
then
cd .. && DAPI_SEED="$DAPI_SEED" FAUCET_PRIVATE_KEY="$faucet_key" npm run test:"$scope"
scope_dirs=""

IFS=', ' read -r -a scopes <<< "$scope"

for scope in "${scopes[@]}"
do
case $scope in
e2e)
scope_dirs="${scope_dirs} test/e2e/**/*.spec.js"
;;
functional)
scope_dirs="${scope_dirs} test/functional/**/*.spec.js"
;;
core)
scope_dirs="${scope_dirs} test/functional/core/**/*.spec.js test/e2e/**/*.spec.js"
;;
platform)
scope_dirs="${scope_dirs} test/functional/platform/**/*.spec.js test/e2e/**/*.spec.js"
;;
e2e:dpns)
scope_dirs="${scope_dirs} test/e2e/dpns.spec.js"
;;
e2e:contacts)
scope_dirs="${scope_dirs} test/e2e/contacts.spec.js"
;;
functional:core)
scope_dirs="${scope_dirs} test/functional/core/**/*.spec.js"
;;
functional:platform)
scope_dirs="${scope_dirs} test/functional/platform/**/*.spec.js"
;;
*)
echo "Unknown scope $scope"
exit 0
;;
esac
done

cd "$DIR"/.. && DAPI_SEED=${DAPI_SEED} FAUCET_PRIVATE_KEY=${faucet_key} NODE_ENV=test node_modules/.bin/mocha ${scope_dirs}
else
cd .. && DAPI_SEED="$DAPI_SEED" FAUCET_PRIVATE_KEY="$faucet_key" npm run test
cd "$DIR"/.. && DAPI_SEED=${DAPI_SEED} FAUCET_PRIVATE_KEY=${faucet_key} npm run test
fi
21 changes: 10 additions & 11 deletions lib/test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const dotenvSafe = require('dotenv-safe');
const { expect, use } = require('chai');
const dirtyChai = require('dirty-chai');
const chaiAsPromised = require('chai-as-promised');
// const Dash = require('dash');
const Dash = require('dash');

use(chaiAsPromised);
use(dirtyChai);
Expand All @@ -16,13 +16,12 @@ dotenvSafe.config({

global.expect = expect;

// TODO: Temporary disable global client
// const seeds = [{ service: process.env.DASHJS_SEED }];
//
// global.dashClient = new Dash.Client({
// seeds,
// });
//
// before(async () => {
// await global.dashClient.isReady();
// });
const seeds = [{ service: process.env.DAPI_SEED }];

global.dashClient = new Dash.Client({
seeds,
});

before(async () => {
await global.dashClient.isReady();
});
41 changes: 41 additions & 0 deletions lib/test/fundAddress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const {
Transaction,
} = require('@dashevo/dashcore-lib');

const wait = require('../wait');

/**
*
* @param {DAPIClient} dapiClient
* @param {Address} faucetAddress
* @param {PrivateKey} faucetPrivateKey
* @param {Address} address
* @param {number} amount
* @return {Promise<string>}
*/
async function fundAddress(dapiClient, faucetAddress, faucetPrivateKey, address, amount) {
const { items: inputs } = await dapiClient.getUTXO(faucetAddress);

const transaction = new Transaction();

transaction.from(inputs.slice(-1)[0])
.to(address, amount)
.change(faucetAddress)
.fee(668)
.sign(faucetPrivateKey);

let { blocks: currentBlockHeight } = await dapiClient.getStatus();

const transactionId = await dapiClient.sendTransaction(transaction.toBuffer());

const desiredBlockHeight = currentBlockHeight + 2;

do {
({ blocks: currentBlockHeight } = await dapiClient.getStatus());
await wait(30000);
} while (currentBlockHeight < desiredBlockHeight);

return transactionId;
}

module.exports = fundAddress;
2 changes: 1 addition & 1 deletion lib/wait.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function wait(ms) {
return new Promise(res => setTimeout(res, ms));
return new Promise((res) => setTimeout(res, ms));
};
Loading