From c2b107728590f7f7a6735e9fdfa79085ae621a07 Mon Sep 17 00:00:00 2001 From: Justin Tormey Date: Fri, 20 Oct 2017 14:23:48 -0400 Subject: [PATCH] feat(Condition): add testnet condition --- src/conditions/index.js | 5 +++++ tests/conditions/index.spec.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/conditions/index.js b/src/conditions/index.js index dfb3c56ec..23c60b5ee 100644 --- a/src/conditions/index.js +++ b/src/conditions/index.js @@ -55,3 +55,8 @@ exports.isInCountryBlacklist = (feature) => Condition.of((env) => { return passedWithReason(passed, 'in_country_blacklist') }) + +exports.isUsingTestnet = Condition.of((env) => { + let options = env.get(Env.WALLET_OPTIONS) + return passedWithReason(options.network === 'testnet', 'using_testnet') +}) diff --git a/tests/conditions/index.spec.js b/tests/conditions/index.spec.js index af5978695..9a35c51a1 100644 --- a/tests/conditions/index.spec.js +++ b/tests/conditions/index.spec.js @@ -102,6 +102,22 @@ describe('conditions', () => { }) }) + describe('.isUsingTestnet', () => { + it('should pass when the user is using testnet', () => { + let env = makeEnv(null, { network: 'testnet' }, null) + let result = conditions.isUsingTestnet.test(env) + expect(result.passed).toEqual(true) + expect(result.reason).toEqual(['using_testnet']) + }) + + it('should fail when the user is using mainnet', () => { + let env = makeEnv(null, { network: 'bitcoin' }, null) + let result = conditions.isUsingTestnet.test(env) + expect(result.passed).toEqual(false) + expect(result.reason).toEqual(['not_using_testnet']) + }) + }) + describe('composite', () => { let makeAccountInfo = (countryCodeGuess, stateCodeGuess) => ({ countryCodeGuess, stateCodeGuess })