aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sra-report/src
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-03-07 07:22:56 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-03-07 07:22:56 +0800
commit1789025da912aee536f0d9c9cbb66a56492251fc (patch)
treeb6cc4919d0a2d115b0d201e3d1ecb833f2826753 /packages/sra-report/src
parent696f49497b98d3069f1e70d07b4c83414d0bbb99 (diff)
downloaddexon-0x-contracts-1789025da912aee536f0d9c9cbb66a56492251fc.tar.gz
dexon-0x-contracts-1789025da912aee536f0d9c9cbb66a56492251fc.tar.zst
dexon-0x-contracts-1789025da912aee536f0d9c9cbb66a56492251fc.zip
Refactor environment factory and generalize token environment keys
Diffstat (limited to 'packages/sra-report/src')
-rw-r--r--packages/sra-report/src/contract_addresses/kovan_addresses.ts7
-rw-r--r--packages/sra-report/src/contract_addresses/mainnet_addresses.ts7
-rw-r--r--packages/sra-report/src/postman_environment_factory.ts91
3 files changed, 62 insertions, 43 deletions
diff --git a/packages/sra-report/src/contract_addresses/kovan_addresses.ts b/packages/sra-report/src/contract_addresses/kovan_addresses.ts
index 4d2b76a51..e06568f52 100644
--- a/packages/sra-report/src/contract_addresses/kovan_addresses.ts
+++ b/packages/sra-report/src/contract_addresses/kovan_addresses.ts
@@ -1,6 +1,5 @@
export const addresses = {
- DAI_address: '0xb18845c260f680d5b9d84649638813e342e4f8c9',
- WETH_address: '0xd0a1e359811322d97991e03f863a0c30c2cf029c',
- ZRX_address: '0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570',
- EXCHANGE_CONTRACT_address: '0x90fe2af704b34e0224bf2299c838e04d4dcf1364',
+ WETH: '0xd0a1e359811322d97991e03f863a0c30c2cf029c',
+ ZRX: '0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570',
+ EXCHANGE: '0x90fe2af704b34e0224bf2299c838e04d4dcf1364',
};
diff --git a/packages/sra-report/src/contract_addresses/mainnet_addresses.ts b/packages/sra-report/src/contract_addresses/mainnet_addresses.ts
index 4ccbdf12d..e9aa0f167 100644
--- a/packages/sra-report/src/contract_addresses/mainnet_addresses.ts
+++ b/packages/sra-report/src/contract_addresses/mainnet_addresses.ts
@@ -1,6 +1,5 @@
export const addresses = {
- DAI_address: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
- WETH_address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
- ZRX_address: '0xe41d2489571d322189246dafa5ebde1f4699f498',
- EXCHANGE_CONTRACT_address: '0x12459c951127e0c374ff9105dda097662a027093',
+ WETH: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
+ ZRX: '0xe41d2489571d322189246dafa5ebde1f4699f498',
+ EXCHANGE: '0x12459c951127e0c374ff9105dda097662a027093',
};
diff --git a/packages/sra-report/src/postman_environment_factory.ts b/packages/sra-report/src/postman_environment_factory.ts
index 703132c6a..91fbb5d2c 100644
--- a/packages/sra-report/src/postman_environment_factory.ts
+++ b/packages/sra-report/src/postman_environment_factory.ts
@@ -20,43 +20,12 @@ export const postmanEnvironmentFactory = {
* - Order properties for making specific queries (ex. maker=orderMaker)
*/
async createPostmanEnvironmentAsync(url: string, networkId: number) {
- const schemas: Schema[] = _.values(schemasByName);
- const schemaEnvironmentValues = _.compact(
- _.map(schemas, (schema: Schema) => {
- if (_.isUndefined(schema.id)) {
- return undefined;
- } else {
- 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 contractAddresses = getContractAddresses(networkId);
- const contractAddressEnvironmentValues = _.map(_.keys(contractAddresses), (key: string) => {
- 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 orderEnvironmentValues = await createOrderEnvironmentValuesAsync(url);
const allEnvironmentValues = _.concat(
- schemaEnvironmentValues,
- contractAddressEnvironmentValues,
- createEnvironmentValue('schemaKeys', JSON.stringify(schemaKeys)),
+ createSchemaEnvironmentValues(),
+ createContractAddressEnvironmentValues(networkId),
+ orderEnvironmentValues,
createEnvironmentValue('url', url),
- 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,
@@ -64,6 +33,58 @@ export const postmanEnvironmentFactory = {
return environment;
},
};
+function createSchemaEnvironmentValues() {
+ const schemas: Schema[] = _.values(schemasByName);
+ const schemaEnvironmentValues = _.compact(
+ _.map(schemas, (schema: Schema) => {
+ if (_.isUndefined(schema.id)) {
+ return undefined;
+ } else {
+ 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 result = _.concat(schemaEnvironmentValues, createEnvironmentValue('schemaKeys', JSON.stringify(schemaKeys)));
+ return result;
+}
+function createContractAddressEnvironmentValues(networkId: number) {
+ const contractAddresses = getContractAddresses(networkId);
+ return [
+ createEnvironmentValue('tokenContractAddress1', contractAddresses.WETH),
+ createEnvironmentValue('tokenContractAddress2', contractAddresses.ZRX),
+ createEnvironmentValue('exchangeContractAddress', contractAddresses.EXCHANGE),
+ ];
+}
+
+async function createOrderEnvironmentValuesAsync(url: string) {
+ const httpClient = new HttpClient(url);
+ const orders = await httpClient.getOrdersAsync();
+ const orderIfExists = _.head(orders);
+ if (!_.isUndefined(orderIfExists)) {
+ return [
+ createEnvironmentValue('order', JSON.stringify(orderIfExists)),
+ createEnvironmentValue('orderMaker', orderIfExists.maker),
+ createEnvironmentValue('orderTaker', orderIfExists.taker),
+ createEnvironmentValue('orderFeeRecipient', orderIfExists.feeRecipient),
+ createEnvironmentValue('orderHash', ZeroEx.getOrderHashHex(orderIfExists)),
+ ];
+ } else {
+ return [
+ createEnvironmentValue('order', ''),
+ createEnvironmentValue('orderMaker', ''),
+ createEnvironmentValue('orderTaker', ''),
+ createEnvironmentValue('orderFeeRecipient', ''),
+ createEnvironmentValue('orderHash', ''),
+ ];
+ }
+}
+
function getContractAddresses(networkId: number) {
switch (networkId) {
case 1: