aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/sra-report/src/index.ts21
-rw-r--r--packages/sra-report/src/postman_environment_factory.ts19
2 files changed, 25 insertions, 15 deletions
diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts
index 4419a3ec8..d292f15e1 100644
--- a/packages/sra-report/src/index.ts
+++ b/packages/sra-report/src/index.ts
@@ -1,6 +1,5 @@
#!/usr/bin/env node
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';
@@ -38,6 +37,13 @@ const args = yargs
type: 'number',
default: DEFAULT_NETWORK_ID,
})
+ .option('environment', {
+ alias: ['env'],
+ describe: 'File path to an environment file for the collection run',
+ type: 'string',
+ normalize: true,
+ demandOption: false,
+ })
.option('export-collection', {
alias: ['ec'],
describe: 'The relative path to write the postman collection file used by the collection run',
@@ -53,7 +59,7 @@ const args = yargs
demandOption: false,
})
.example(
- "$0 --endpoint-url 'http://api.example.com' --out 'path/to/report.json' --network-id 42 --export-environment 'path/to/environment.json' --export-collection 'path/to/collection.json'",
+ "$0 --endpoint-url 'http://api.example.com' --out 'path/to/report.json' --network-id 42 --environment 'path/to/custom/environment.json' --export-collection 'path/to/collection.json' --export-environment 'path/to/environment.json'",
'Full usage example',
).argv;
// perform extra validation on command line arguments
@@ -69,12 +75,6 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) {
process.exit(1);
}
const mainAsync = async () => {
- const httpClient = new HttpClient(args.endpointUrl);
- const orders = await httpClient.getOrdersAsync();
- const firstOrder = _.head(orders);
- if (_.isUndefined(firstOrder)) {
- throw new Error('Could not get any orders from /orders endpoint');
- }
const newmanReporterOptions = !_.isUndefined(args.output)
? {
reporters: 'json',
@@ -87,9 +87,12 @@ const mainAsync = async () => {
: {
reporters: 'cli',
};
+ const environment = !_.isUndefined(args.environment)
+ ? args.environment
+ : await postmanEnvironmentFactory.createPostmanEnvironmentAsync(args.endpointUrl, args.networkId);
const newmanRunOptions = {
collection: sraReportCollectionJSON,
- environment: postmanEnvironmentFactory.createPostmanEnvironment(args.endpointUrl, args.networkId, firstOrder),
+ environment,
exportCollection: args.exportCollection,
exportEnvironment: args.exportEnvironment,
...newmanReporterOptions,
diff --git a/packages/sra-report/src/postman_environment_factory.ts b/packages/sra-report/src/postman_environment_factory.ts
index e4276d4a5..703132c6a 100644
--- a/packages/sra-report/src/postman_environment_factory.ts
+++ b/packages/sra-report/src/postman_environment_factory.ts
@@ -1,4 +1,5 @@
import { SignedOrder, ZeroEx } from '0x.js';
+import { HttpClient } from '@0xproject/connect';
import { Schema, schemas as schemasByName } from '@0xproject/json-schemas';
import * as _ from 'lodash';
@@ -18,7 +19,7 @@ export const postmanEnvironmentFactory = {
* - Contract addresses based on the network id for making specific queries (ex. baseTokenAddress=ZRX_address)
* - Order properties for making specific queries (ex. maker=orderMaker)
*/
- createPostmanEnvironment(url: string, networkId: number, order: SignedOrder) {
+ async createPostmanEnvironmentAsync(url: string, networkId: number) {
const schemas: Schema[] = _.values(schemasByName);
const schemaEnvironmentValues = _.compact(
_.map(schemas, (schema: Schema) => {
@@ -40,16 +41,22 @@ export const postmanEnvironmentFactory = {
const contractAddress = _.get(contractAddresses, key);
return createEnvironmentValue(key, contractAddress);
});
+ const httpClient = new HttpClient(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 allEnvironmentValues = _.concat(
schemaEnvironmentValues,
contractAddressEnvironmentValues,
createEnvironmentValue('schemaKeys', JSON.stringify(schemaKeys)),
createEnvironmentValue('url', url),
- createEnvironmentValue('order', JSON.stringify(order)),
- createEnvironmentValue('orderMaker', order.maker),
- createEnvironmentValue('orderTaker', order.taker),
- createEnvironmentValue('orderFeeRecipient', order.feeRecipient),
- createEnvironmentValue('orderHash', ZeroEx.getOrderHashHex(order)),
+ createEnvironmentValue('order', JSON.stringify(firstOrder)),
+ createEnvironmentValue('orderMaker', firstOrder.maker),
+ createEnvironmentValue('orderTaker', firstOrder.taker),
+ createEnvironmentValue('orderFeeRecipient', firstOrder.feeRecipient),
+ createEnvironmentValue('orderHash', ZeroEx.getOrderHashHex(firstOrder)),
);
const environment = {
values: allEnvironmentValues,