diff options
Diffstat (limited to 'packages/sra-report')
4 files changed, 99 insertions, 79 deletions
diff --git a/packages/sra-report/postman_configs/collections/sra_report.postman_collection.json b/packages/sra-report/postman_configs/collections/sra_report.postman_collection.json index 04c7bc51f..9a8e8e0fa 100644 --- a/packages/sra-report/postman_configs/collections/sra_report.postman_collection.json +++ b/packages/sra-report/postman_configs/collections/sra_report.postman_collection.json @@ -42,10 +42,10 @@ { "listen": "test", "script": { - "id": "1b61aabb-ef9f-4269-9a0c-cb7559afcbd8", + "id": "0b0712ff-7846-40a3-9253-4bca2551350c", "type": "text/javascript", "exec": [ - "const filterTokenEnvKey = 'WETH_address';", + "const filterTokenEnvKey = 'tokenContractAddress1';", "const filterTokenAddress = pm.environment.get(filterTokenEnvKey);", "const responseJsonData = pm.response.json();", "pm.test('Token pairs are properly filtered', function() {", @@ -66,13 +66,13 @@ "header": [], "body": {}, "url": { - "raw": "{{url}}/token_pairs?tokenA={{WETH_address}}", + "raw": "{{url}}/token_pairs?tokenA={{tokenContractAddress1}}", "host": ["{{url}}"], "path": ["token_pairs"], "query": [ { "key": "tokenA", - "value": "{{WETH_address}}", + "value": "{{tokenContractAddress1}}", "equals": true } ] @@ -87,10 +87,10 @@ { "listen": "test", "script": { - "id": "a5f946b1-fc97-4bcf-ae01-e0f97864a6c1", + "id": "ef0e6be8-06d8-4975-a1c4-2199bc8b5aa6", "type": "text/javascript", "exec": [ - "const filterTokenEnvKey = 'WETH_address';", + "const filterTokenEnvKey = 'tokenContractAddress1';", "const filterTokenAddress = pm.environment.get(filterTokenEnvKey);", "const responseJsonData = pm.response.json();", "pm.test('Token pairs are properly filtered', function() {", @@ -111,13 +111,13 @@ "header": [], "body": {}, "url": { - "raw": "{{url}}/token_pairs?tokenB={{WETH_address}}", + "raw": "{{url}}/token_pairs?tokenB={{tokenContractAddress1}}", "host": ["{{url}}"], "path": ["token_pairs"], "query": [ { "key": "tokenB", - "value": "{{WETH_address}}", + "value": "{{tokenContractAddress1}}", "equals": true } ] @@ -132,11 +132,11 @@ { "listen": "test", "script": { - "id": "bcd06e4f-aa3a-42f8-9f8c-bc902eb7a075", + "id": "9ca4bed3-b8e0-4a90-96ba-42f0da3a7d68", "type": "text/javascript", "exec": [ - "const filterTokenAEnvKey = 'WETH_address';", - "const filterTokenBEnvKey = 'ZRX_address';", + "const filterTokenAEnvKey = 'tokenContractAddress1';", + "const filterTokenBEnvKey = 'tokenContractAddress2';", "const filterTokenAAddress = pm.environment.get(filterTokenAEnvKey);", "const filterTokenBAddress = pm.environment.get(filterTokenBEnvKey);", "const responseJsonData = pm.response.json();", @@ -160,18 +160,19 @@ "header": [], "body": {}, "url": { - "raw": "{{url}}/token_pairs?tokenA={{WETH_address}}&tokenB={{ZRX_address}}", + "raw": + "{{url}}/token_pairs?tokenA={{tokenContractAddress1}}&tokenB={{tokenContractAddress2}}", "host": ["{{url}}"], "path": ["token_pairs"], "query": [ { "key": "tokenA", - "value": "{{WETH_address}}", + "value": "{{tokenContractAddress1}}", "equals": true }, { "key": "tokenB", - "value": "{{ZRX_address}}", + "value": "{{tokenContractAddress2}}", "equals": true } ] @@ -244,10 +245,10 @@ { "listen": "test", "script": { - "id": "e782ae77-66bf-4096-9190-ef9e7501b316", + "id": "374c4b28-5672-400c-8c23-9cb1a3e63117", "type": "text/javascript", "exec": [ - "const exchangeContractEnvKey = 'EXCHANGE_CONTRACT_address';", + "const exchangeContractEnvKey = 'exchangeContractAddress';", "const requestedExchangeContractAddress = pm.environment.get(exchangeContractEnvKey);", "const responseJsonData = pm.response.json();", "pm.test('Orders are properly filtered', function() {", @@ -266,13 +267,13 @@ "header": [], "body": {}, "url": { - "raw": "{{url}}/orders?exchangeContractAddress={{EXCHANGE_CONTRACT_address}}", + "raw": "{{url}}/orders?exchangeContractAddress={{exchangeContractAddress}}", "host": ["{{url}}"], "path": ["orders"], "query": [ { "key": "exchangeContractAddress", - "value": "{{EXCHANGE_CONTRACT_address}}", + "value": "{{exchangeContractAddress}}", "equals": true } ] @@ -288,10 +289,10 @@ { "listen": "test", "script": { - "id": "1144a2d6-6175-40a6-8568-d0d3884492a1", + "id": "e74a9069-18b9-42d3-b2d0-e18580ad73f2", "type": "text/javascript", "exec": [ - "const filterTokenEnvKey = 'ZRX_address';", + "const filterTokenEnvKey = 'tokenContractAddress2';", "const filterTokenAddress = pm.environment.get(filterTokenEnvKey);", "const responseJsonData = pm.response.json();", "pm.test('Orders are properly filtered', function() {", @@ -314,13 +315,13 @@ "header": [], "body": {}, "url": { - "raw": "{{url}}/orders?tokenAddress={{ZRX_address}}", + "raw": "{{url}}/orders?tokenAddress={{tokenContractAddress2}}", "host": ["{{url}}"], "path": ["orders"], "query": [ { "key": "tokenAddress", - "value": "{{ZRX_address}}", + "value": "{{tokenContractAddress2}}", "equals": true } ] @@ -336,10 +337,10 @@ { "listen": "test", "script": { - "id": "01eb5865-edec-4216-8a90-c36d790366fc", + "id": "c539f306-aa03-495d-a90a-0179e1b751aa", "type": "text/javascript", "exec": [ - "const filterTokenEnvKey = 'ZRX_address';", + "const filterTokenEnvKey = 'tokenContractAddress2';", "const filterTokenAddress = pm.environment.get(filterTokenEnvKey);", "const responseJsonData = pm.response.json();", "pm.test('Orders are properly filtered', function() {", @@ -358,13 +359,13 @@ "header": [], "body": {}, "url": { - "raw": "{{url}}/orders?makerTokenAddress={{ZRX_address}}", + "raw": "{{url}}/orders?makerTokenAddress={{tokenContractAddress2}}", "host": ["{{url}}"], "path": ["orders"], "query": [ { "key": "makerTokenAddress", - "value": "{{ZRX_address}}", + "value": "{{tokenContractAddress2}}", "equals": true } ] @@ -380,10 +381,10 @@ { "listen": "test", "script": { - "id": "bbbb6e15-60c7-4666-96be-a0ad56b6058b", + "id": "49b2fcaf-5fe2-471f-ae10-e48a440d4c6d", "type": "text/javascript", "exec": [ - "const filterTokenEnvKey = 'ZRX_address';", + "const filterTokenEnvKey = 'tokenContractAddress2';", "const filterTokenAddress = pm.environment.get(filterTokenEnvKey);", "const responseJsonData = pm.response.json();", "pm.test('Orders are properly filtered', function() {", @@ -402,13 +403,13 @@ "header": [], "body": {}, "url": { - "raw": "{{url}}/orders?takerTokenAddress={{ZRX_address}}", + "raw": "{{url}}/orders?takerTokenAddress={{tokenContractAddress2}}", "host": ["{{url}}"], "path": ["orders"], "query": [ { "key": "takerTokenAddress", - "value": "{{ZRX_address}}", + "value": "{{tokenContractAddress2}}", "equals": true } ] @@ -730,11 +731,11 @@ { "listen": "test", "script": { - "id": "0198622e-9705-4ae1-b1f2-0c40b87de856", + "id": "9ed05327-1a2f-4e50-b4aa-e21f961dbe78", "type": "text/javascript", "exec": [ - "const baseTokenEnvKey = 'ZRX_address';", - "const quoteTokenEnvKey = 'WETH_address';", + "const baseTokenEnvKey = 'tokenContractAddress2';", + "const quoteTokenEnvKey = 'tokenContractAddress1';", "const baseTokenAddress = pm.environment.get(baseTokenEnvKey);", "const quoteTokenAddress = pm.environment.get(quoteTokenEnvKey);", "const responseJsonData = pm.response.json();", @@ -765,18 +766,18 @@ "body": {}, "url": { "raw": - "{{url}}/orderbook?baseTokenAddress={{ZRX_address}}"eTokenAddress={{WETH_address}}", + "{{url}}/orderbook?baseTokenAddress={{tokenContractAddress2}}"eTokenAddress={{tokenContractAddress1}}", "host": ["{{url}}"], "path": ["orderbook"], "query": [ { "key": "baseTokenAddress", - "value": "{{ZRX_address}}", + "value": "{{tokenContractAddress2}}", "equals": true }, { "key": "quoteTokenAddress", - "value": "{{WETH_address}}", + "value": "{{tokenContractAddress1}}", "equals": true } ] 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: |