diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/sra-report/src/index.ts | 15 | ||||
-rw-r--r-- | packages/sra-report/src/postman_environment_factory.ts | 43 |
2 files changed, 33 insertions, 25 deletions
diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index d273d74a4..bd0615480 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -1,6 +1,8 @@ #!/usr/bin/env node +import { ZeroEx } from '0x.js'; import { assert } from '@0xproject/assert'; +import { HttpClient } from '@0xproject/connect'; import { Schema, schemas } from '@0xproject/json-schemas'; import { promisify } from '@0xproject/utils'; import chalk from 'chalk'; @@ -14,7 +16,6 @@ import { postmanEnvironmentFactory } from './postman_environment_factory'; import { utils } from './utils'; const newmanRunAsync = promisify<void>(newman.run); - const DEFAULT_NETWORK_ID = 1; const SUPPORTED_NETWORK_IDS = [1, 42]; @@ -55,14 +56,20 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) { } const mainAsync = async () => { + const httpClient = new HttpClient(args.url); + const orders = await httpClient.getOrdersAsync(); + const firstOrder = _.head(orders); + if (_.isUndefined(firstOrder)) { + throw new Error('Could not get any orders from /orders endpoint'); + } + const orderHash = ZeroEx.getOrderHashHex(firstOrder); const newmanRunOptions = { collection: sraReportCollectionJSON, reporters: 'cli', - globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url), + globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url, orderHash), environment: postmanEnvironmentFactory.createNetworkEnvironment(args.networkId), }; await newmanRunAsync(newmanRunOptions); }; -mainAsync() - .catch(err => utils.log); +mainAsync().catch(utils.log); diff --git a/packages/sra-report/src/postman_environment_factory.ts b/packages/sra-report/src/postman_environment_factory.ts index 697578a2d..b0b69ddad 100644 --- a/packages/sra-report/src/postman_environment_factory.ts +++ b/packages/sra-report/src/postman_environment_factory.ts @@ -12,38 +12,32 @@ interface EnvironmentValue { } export const postmanEnvironmentFactory = { - createGlobalEnvironment(url: string) { - const urlEnvironmentValue = { - key: 'url', - value: url, - enabled: true, - type: 'text', - }; + createGlobalEnvironment(url: string, orderHash: string) { + const urlEnvironmentValue = createEnvironmentValue('url', url); + const orderHashEnvironmentValue = createEnvironmentValue('orderHash', orderHash); const schemas: Schema[] = _.values(schemasByName); const schemaEnvironmentValues = _.compact( _.map(schemas, (schema: Schema) => { if (_.isUndefined(schema.id)) { return undefined; } else { - return { - key: convertSchemaIdToKey(schema.id), - value: JSON.stringify(schema), - enabled: true, - type: 'text', - }; + const schemaKey = convertSchemaIdToKey(schema.id); + const stringifiedSchema = JSON.stringify(schema); + const schemaEnvironmentValue = createEnvironmentValue(schemaKey, stringifiedSchema); + return schemaEnvironmentValue; } }), ); const schemaKeys = _.map(schemaEnvironmentValues, (environmentValue: EnvironmentValue) => { return environmentValue.key; }); - const schemaKeysEnvironmentValue = { - key: 'schemaKeys', - value: JSON.stringify(schemaKeys), - enabled: true, - type: 'text', - }; - const environmentValues = _.concat(schemaEnvironmentValues, urlEnvironmentValue, schemaKeysEnvironmentValue); + const schemaKeysEnvironmentValue = createEnvironmentValue('schemaKeys', JSON.stringify(schemaKeys)); + const environmentValues = _.concat( + schemaEnvironmentValues, + urlEnvironmentValue, + schemaKeysEnvironmentValue, + orderHashEnvironmentValue, + ); const environment = { values: environmentValues, }; @@ -60,7 +54,6 @@ export const postmanEnvironmentFactory = { } }, }; - function convertSchemaIdToKey(schemaId: string) { let result = schemaId; if (_.startsWith(result, '/')) { @@ -69,3 +62,11 @@ function convertSchemaIdToKey(schemaId: string) { result = `${result}Schema`; return result; } +function createEnvironmentValue(key: string, value: string) { + return { + key, + value, + enabled: true, + type: 'text', + }; +} |