diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-02-28 06:06:33 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-02-28 06:11:45 +0800 |
commit | e48a3edacba891a18e641e01708e3d73fd6588ac (patch) | |
tree | 5a17b49eafdf114d6f623f99caa2c1525bc6cb84 /packages/sra-report | |
parent | 9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d (diff) | |
download | dexon-0x-contracts-e48a3edacba891a18e641e01708e3d73fd6588ac.tar dexon-0x-contracts-e48a3edacba891a18e641e01708e3d73fd6588ac.tar.gz dexon-0x-contracts-e48a3edacba891a18e641e01708e3d73fd6588ac.tar.bz2 dexon-0x-contracts-e48a3edacba891a18e641e01708e3d73fd6588ac.tar.lz dexon-0x-contracts-e48a3edacba891a18e641e01708e3d73fd6588ac.tar.xz dexon-0x-contracts-e48a3edacba891a18e641e01708e3d73fd6588ac.tar.zst dexon-0x-contracts-e48a3edacba891a18e641e01708e3d73fd6588ac.zip |
Get orderHash via 0x connect
Diffstat (limited to 'packages/sra-report')
-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', + }; +} |