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 5 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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
DAPI_SEED=
FAUCET_PRIVATE_KEY=
NETWORK=
DASHJS_SEED=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe, we could reuse DAPI_SEED for setting up DashJS client.

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
52 changes: 47 additions & 5 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ Usage: test <seed> [options]
functional:core
functional:platform"

DAPI_SEED="$1"
DASHJS_SEED="$1"

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

if [ -z "$DASHJS_SEED" ] || [[ $DASHJS_SEED == -* ]]
then
echo "Seed is not specified"
exit 0
Expand All @@ -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"/.. && DASHJS_SEED=${DASHJS_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"/.. && DASHJS_SEED=${DASHJS_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.DASHJS_SEED }];

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

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

/**
*
* @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);

return dapiClient.sendTransaction(transaction.toBuffer());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wait for a few blocks here?

}

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