diff --git a/src/subgraph.js b/src/subgraph.js index 53e402ab..a724f48c 100644 --- a/src/subgraph.js +++ b/src/subgraph.js @@ -391,6 +391,29 @@ More than one data source named '${name}', data source names must be unique.`, }, immutable.List()) } + static validateUniqueDataSources(manifest) { + let data_source_identifiers = immutable.List() + return manifest.get('dataSources').reduce((errors, dataSource, dataSourceIndex) => { + let path = ['dataSources', dataSourceIndex] + let data_source_identifier = dataSource.get('source').merge(dataSource.get('mapping')) + if (data_source_identifiers.includes(data_source_identifier)) { + console.log("duplicate") + errors = errors.push( + immutable.fromJS({ + path, + message: `\ +This data source, '${dataSource.get('name')}', has identical source and mapping to an already declared data source. +They will both listen to the same triggers, process them with the same mappings, and generate the same entity updates.`, + }), + ) + } + + data_source_identifiers = data_source_identifiers.push(data_source_identifier) + return errors + }, immutable.List()) + } + + static validateUniqueTemplateNames(manifest) { let names = [] return manifest @@ -460,7 +483,7 @@ More than one template named '${name}', template names must be unique.`, : immutable.List.of( ...Subgraph.validateRepository(manifest, { resolveFile }), ...Subgraph.validateDescription(manifest, { resolveFile }), - ...Subgraph.validateEthereumContractHandlers(manifest), + ...Subgraph.validateUniqueDataSource(manifest), ) return { diff --git a/tests/cli/validation.test.js b/tests/cli/validation.test.js index f1947cd9..57246f8b 100644 --- a/tests/cli/validation.test.js +++ b/tests/cli/validation.test.js @@ -162,6 +162,15 @@ describe('Validation', () => { }, ) + cliTest( + 'Duplicate data source functionality', + ['codegen', '--skip-migrations'], + 'validation/duplicate-data-source-functionality', + { + exitCode: 0, + }, + ) + cliTest( 'Duplicate template name', ['codegen', '--skip-migrations'], diff --git a/tests/cli/validation/duplicate-data-source-functionality.stderr b/tests/cli/validation/duplicate-data-source-functionality.stderr new file mode 100644 index 00000000..9801c0b7 --- /dev/null +++ b/tests/cli/validation/duplicate-data-source-functionality.stderr @@ -0,0 +1,36 @@ +- Load subgraph from subgraph.yaml +⚠ Warnings while loading subgraph from subgraph.yaml: Warnings in subgraph.yaml: + + Path: dataSources > 1 + This data source, 'ExampleSubgraph1', has identical source and mapping to an already declared data source. + They will both listen to the same triggers, process them with the same mappings, and generate the same entity updates. + +✔ Load subgraph from subgraph.yaml +- Load contract ABIs + Load contract ABI from Abi.json +- Load contract ABIs + Load contract ABI from Abi.json +- Load contract ABIs +✔ Load contract ABIs +- Generate types for contract ABIs + Generate types for contract ABI: ExampleContract (Abi.json) +- Generate types for contract ABIs + Write types to generated/ExampleSubgraph/ExampleContract.ts +- Generate types for contract ABIs + Generate types for contract ABI: ExampleContract (Abi.json) +- Generate types for contract ABIs + Write types to generated/ExampleSubgraph1/ExampleContract.ts +- Generate types for contract ABIs +✔ Generate types for contract ABIs +- Generate types for data source templates +✔ Generate types for data source templates +- Load data source template ABIs +✔ Load data source template ABIs +- Generate types for data source template ABIs +✔ Generate types for data source template ABIs +- Load GraphQL schema from schema.graphql +✔ Load GraphQL schema from schema.graphql +- Generate types for GraphQL schema + Write types to generated/schema.ts +- Generate types for GraphQL schema +✔ Generate types for GraphQL schema diff --git a/tests/cli/validation/duplicate-data-source-functionality/Abi.json b/tests/cli/validation/duplicate-data-source-functionality/Abi.json new file mode 100644 index 00000000..4d05f583 --- /dev/null +++ b/tests/cli/validation/duplicate-data-source-functionality/Abi.json @@ -0,0 +1,7 @@ +[ + { + "type": "event", + "name": "ExampleEvent", + "inputs": [{ "type": "string" }] + } +] diff --git a/tests/cli/validation/duplicate-data-source-functionality/mapping.ts b/tests/cli/validation/duplicate-data-source-functionality/mapping.ts new file mode 100644 index 00000000..e69de29b diff --git a/tests/cli/validation/duplicate-data-source-functionality/schema.graphql b/tests/cli/validation/duplicate-data-source-functionality/schema.graphql new file mode 100644 index 00000000..218c5b9c --- /dev/null +++ b/tests/cli/validation/duplicate-data-source-functionality/schema.graphql @@ -0,0 +1,4 @@ +type MyEntity @entity { + id: ID! + x: BigDecimal! +} diff --git a/tests/cli/validation/duplicate-data-source-functionality/subgraph.yaml b/tests/cli/validation/duplicate-data-source-functionality/subgraph.yaml new file mode 100644 index 00000000..5ebf6dd0 --- /dev/null +++ b/tests/cli/validation/duplicate-data-source-functionality/subgraph.yaml @@ -0,0 +1,40 @@ +specVersion: 0.0.1 +repository: https://github.com/graphprotocol/test-subgraph +description: Test subgraph +schema: + file: ./schema.graphql +dataSources: + - kind: ethereum/contract + name: ExampleSubgraph + source: + abi: ExampleContract + mapping: + kind: ethereum/events + apiVersion: 0.0.1 + language: wasm/assemblyscript + file: ./mapping.ts + entities: + - ExampleEntity + abis: + - name: ExampleContract + file: ./Abi.json + eventHandlers: + - event: ExampleEvent(string) + handler: handleExampleEvent + - kind: ethereum/contract + name: ExampleSubgraph1 + source: + abi: ExampleContract + mapping: + kind: ethereum/events + apiVersion: 0.0.1 + language: wasm/assemblyscript + file: ./mapping.ts + entities: + - ExampleEntity + abis: + - name: ExampleContract + file: ./Abi.json + eventHandlers: + - event: ExampleEvent(string) + handler: handleExampleEvent