From 647203edf51f2984ae13c35357d76492437a79aa Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Thu, 8 Feb 2024 16:18:17 -0600 Subject: [PATCH] Introduce new environment tests --- constants.js | 4 ++++ tests/fabric.environment.js | 37 +++++++++++++++++++++++++++++++++---- types/service.js | 1 - 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/constants.js b/constants.js index 24783a1bb..e772deb60 100644 --- a/constants.js +++ b/constants.js @@ -18,6 +18,8 @@ const BITCOIN_GENESIS = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b const BITCOIN_GENESIS_ROOT = '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'; const FABRIC_KEY_DERIVATION_PATH = "m/44'/7777'/0'/0/0"; const FIXTURE_SEED = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'; +const FIXTURE_XPUB = 'xpub661MyMwAqRbcF6GygV6Q6XAg8dqhPvDuhYHGniequi6HMbYhNNH5XC13Np3qRANHVD2mmnNGtMGBfDT69s2ovpHLr7q8syoAuyWqtRGEsYQ'; +const FIXTURE_XPRV = 'xprv9s21ZrQH143K2cCWaTZPjPDwac1CzTW4LKMfzLFEMNZJUoDYppxpyPgZXY7CZkjefGJTrTyqKnMrM4RG6nGn7Q9cwjHggCtn3CdFGJahaWY'; // Message Constants const MAGIC_BYTES = 0xC0D3F33D; @@ -126,6 +128,8 @@ module.exports = { FABRIC_KEY_DERIVATION_PATH, FABRIC_USER_AGENT, FIXTURE_SEED, + FIXTURE_XPUB, + FIXTURE_XPRV, HEADER_SIZE, GENERIC_MESSAGE_TYPE, LOG_MESSAGE_TYPE, diff --git a/tests/fabric.environment.js b/tests/fabric.environment.js index 798247966..332d0ed86 100644 --- a/tests/fabric.environment.js +++ b/tests/fabric.environment.js @@ -1,5 +1,12 @@ 'use strict'; +// Constants +const { + FIXTURE_SEED, + FIXTURE_XPUB, + FIXTURE_XPRV +} = require('../constants'); + // Dependencies const assert = require('assert'); @@ -20,6 +27,27 @@ describe('@fabric/core/types/environment', function () { assert.ok(environment); }); + it('can instantiate from a seed', async function () { + const environment = new Environment({ xpub: FIXTURE_SEED }); + await environment.start(); + await environment.stop() + assert.ok(environment); + }); + + it('can instantiate from an xpub', async function () { + const environment = new Environment({ xpub: FIXTURE_XPUB }); + await environment.start(); + await environment.stop() + assert.ok(environment); + }); + + it('can instantiate from an xprv', async function () { + const environment = new Environment({ xprv: FIXTURE_XPRV }); + await environment.start(); + await environment.stop() + assert.ok(environment); + }); + it('can read an environment variable', async function () { const environment = new Environment(); const home = environment.readVariable('HOME'); @@ -44,16 +72,13 @@ describe('@fabric/core/types/environment', function () { }); environment.setWallet(wallet); - assert.ok(environment); - environment.destroyWallet(); }); it('can check for store', async function () { const environment = new Environment(); const exists = environment.storeExists(); - assert.ok(environment); assert.equal(typeof exists, 'boolean'); }); @@ -68,9 +93,13 @@ describe('@fabric/core/types/environment', function () { it('can touch the wallet', async function () { const environment = new Environment(); - environment.touchWallet(); + assert.ok(environment); + }); + it('can load the wallet', async function () { + const environment = new Environment(); + environment.loadWallet(); assert.ok(environment); }); }); diff --git a/types/service.js b/types/service.js index d7573bb81..9f198ba69 100644 --- a/types/service.js +++ b/types/service.js @@ -45,7 +45,6 @@ class Service extends Actor { * @param {Boolean} [settings.networking=true] Whether or not to connect to the network. * @param {Object} [settings.frequency] Interval frequency in hertz. * @param {Object} [settings.state] Initial state to assign. - * @param {Object} [settings.@data] Internal data to assign. */ constructor (settings = {}) { // Initialize Scribe, our logging tool