Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let { describe, Try } = require('riteway')
let { architect, Network, methods, Neat } = require('../src/index')
describe('filterGenome()', async assert => {
// total nodes length = 200
let neat = new Neat(100, 100, null, {
population_size: 20
})
// This replaces bad networks in a population
const filterGenome = neat.util.filterGenome;
let pickGenome = function(network) { // takes some input and returns a boolean (true / false)
return (network.nodes.length > 100) // avoid overfit
}
let adjustGenome = function(network) { // a function that takes an object and returns a new form of the object
return new Network(4, 4) // spit back a new network, 4 in 4 out 8 total
}
const { bitcoinCoreClientA, bitcoinCoreClientB }: any = bitcoindClients()
const blockHash = lensPath(['anchor', 'blockHash'])
const blockHeight = lensPath(['anchor', 'blockHeight'])
const transactionId = lensPath(['anchor', 'transactionId'])
const getTransactionId = view(transactionId)
const getBlockHash = view(blockHash)
const getBlockHeight = view(blockHeight)
const isNotNil = pipe(isNil, not)
const lengthIsGreaterThan0 = (s: string) => s.length > 0
const hasValidTxId = allPass([is(String), lengthIsGreaterThan0])
describe('Transaction timout will reset the transaction id for the claim', async assert => {
await resetBitcoinServers()
await bitcoinCoreClientB.addNode(bitcoinCoreClientA.host, 'add')
await delayInSeconds(5)
const { db, server, rabbitMQ } = await setUpServerAndDb({ PREFIX, NODE_PORT, blockchainSettings })
// Make sure node A has regtest coins to pay for transactions.
const generatedBlockHeight = 101
await ensureBitcoinBalance(bitcoinCoreClientA, generatedBlockHeight)
await waitForBlockchainsToSync(generatedBlockHeight, [bitcoinCoreClientA, bitcoinCoreClientB])
await bitcoinCoreClientA.setNetworkActive(false)
// Allow everything to finish starting.
await delayInSeconds(5)
import express from 'express';
import request from 'supertest';
import { describe } from 'riteway';
import { createExpressMiddleware } from '../../src/create-express-middleware';
describe('createExpressMiddleware()', async should => {
const { assert } = should();
{
const app = express();
const features = ['posts', 'bar', 'foo'];
const handler = createExpressMiddleware({ features }, 'posts', {
get: (req, res) => {
res.send();
}
});
const path = '/posts';
app.use(path, handler);
request(app)
.get(path)
.end(function(err, res) {
assert({
BATCH_CREATION_INTERVAL_IN_SECONDS: 5,
READ_DIRECTORY_INTERVAL_IN_SECONDS: 5,
UPLOAD_CLAIM_INTERVAL_IN_SECONDS: 5,
}
const { configureSignVerifiableClaim } = getVerifiableClaimSigner()
const createVerifiableClaim = configureCreateVerifiableClaim({ issuer })
const signVerifiableClaim = configureSignVerifiableClaim({ privateKey })
const createClaim = pipeP(
createVerifiableClaim,
signVerifiableClaim,
)
const { bitcoinCoreClientA, bitcoinCoreClientB }: any = bitcoindClients()
describe('A user can successfully submit a claim into the po.et network', async (assert: any) => {
await resetBitcoinServers()
await bitcoinCoreClientB.addNode(bitcoinCoreClientA.host, 'add')
await delay(5 * 1000)
const dbA = await createDatabase(PREFIX_A)
const serverA = await app({
BITCOIN_URL: bitcoinCoreClientA.host,
API_PORT: NODE_A_PORT,
MONGODB_DATABASE: dbA.settings.tempDbName,
MONGODB_USER: dbA.settings.tempDbUser,
MONGODB_PASSWORD: dbA.settings.tempDbPassword,
EXCHANGE_PREFIX: PREFIX_A,
...blockchainSettings,
})
const dbB = await createDatabase(PREFIX_B)
import { getHealth, getMetrics } from '../helpers/endpoints'
import { delay, runtimeId, createDatabase } from '../helpers/utils'
const Client = require('bitcoin-core')
const PREFIX = `test-functional-node-poet-${runtimeId()}`
const NODE_PORT = '28081'
const LOW_WALLET_BALANCE_IN_BITCOIN = 1
const bitcoindClient = new Client({
host: process.env.BITCOIN_URL || 'bitcoind-1',
port: 18443,
network: 'regtest',
password: 'bitcoinrpcpassword',
username: 'bitcoinrpcuser',
})
describe('Health Endpoint Returns the Correct Fields', async (assert: any) => {
const db = await createDatabase(PREFIX)
await resetBitcoinServers()
await delay(5 * 1000)
const server = await app({
BITCOIN_URL: process.env.BITCOIN_URL || 'bitcoind-1',
API_PORT: NODE_PORT,
MONGODB_DATABASE: db.settings.tempDbName,
MONGODB_USER: db.settings.tempDbUser,
MONGODB_PASSWORD: db.settings.tempDbPassword,
EXCHANGE_PREFIX: PREFIX,
LOW_WALLET_BALANCE_IN_BITCOIN,
HEALTH_INTERVAL_IN_SECONDS: 1,
})
given: 'feature is inactive',
should: 'render the inactive component',
actual: $('.help-inactive').length,
expected: 1
});
assert({
given: 'feature is inactive',
should: 'not render the active component',
actual: $('.help-active').length,
expected: 0
});
}
});
describe('withFeatureToggles and configureFeature', async assert => {
{
const FooActive = createTestComponent('foo-active');
const FooInactive = createTestComponent('foo-inactive');
const HelpActive = createTestComponent('help-active');
const HelpInactive = createTestComponent('help-inactive');
const ConfiguredFoo = configureFeature(FooInactive)('foo')(FooActive);
const ConfiguredHelp = configureFeature(HelpInactive)('help')(HelpActive);
const features = ['foo', 'bar'];
const FooPage = withFeatureToggles({ features })(ConfiguredFoo);
const HelpPage = withFeatureToggles({ features })(ConfiguredHelp);
const $ = dom.load(
render(
<div></div>
import fetch from 'isomorphic-fetch'
import { describe } from 'riteway'
import { Graphite } from '../../src/index'
const options = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: '{ hello }' }),
}
describe('Running Graphite', async assert => {
{
const graphite = await Graphite()
const request = await fetch('http://localhost:4000/graphql', options)
const actual = (await request.json()).data.hello
const expected = 'Hello World! 🎉🎉🎉'
assert({
given: 'Graphite Server with any configuration',
should: 'return the default query',
actual,
expected,
})
await graphite.stop()
}
import { describe } from 'riteway';
import dom from 'cheerio';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import createFeature from '../test-fixtures/create-feature';
import { withFeatures, configureFeature } from '../../src';
const render = ReactDOMServer.renderToStaticMarkup;
describe('integration of withFeatures() and configureFeature()', async should => {
const { assert } = should();
{
const initialFeatures = [
createFeature({
name: 'comments',
enabled: false,
dependencies: []
}),
createFeature({
name: 'help',
enabled: true,
dependencies: []
}),
createFeature({
name: 'sorting',
given: 'a feature that is disabled and an incorrect search string',
should: 'have the correct status code for res',
actual: res.statusCode,
expected: 404
});
assert({
given: 'next callback',
should: 'call next after completing',
actual: next.valueOf(),
expected: true
});
}
});
describe('createRouteMiddleware() auto curried', async should => {
const { assert } = should('update the status code correctly');
{
const features = createFeatures();
const req = Request();
const res = Response();
const next = Next();
const middleware = createRouteMiddleware(features)({requiredFeature: 'posts'});
middleware(req, res, next.next);
assert({
given: 'a feature that is enabled',
should: 'have the correct status code for res',
actual: res.statusCode,
expected: 200
import express from 'express';
import request from 'supertest';
import { createRouteMiddleware } from '../create-route-middleware';
import { createFeatures } from '../test-fixtures/create-features';
import { describe } from 'riteway';
describe('createRouteMiddleware()', async should => {
const { assert } = should();
{
const app = express();
const features = createFeatures();
const handler = createRouteMiddleware(features, {
requiredFeature: 'posts',
get: (req, res) => {
res.send();
}
});
const path = '/posts';
app.use(path, handler);
request(app)
.get(path)