From 28dc631d3d8af1eda9ae2ff50f3a4f37816048d3 Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Fri, 17 Mar 2023 14:36:29 -0400 Subject: [PATCH 1/7] test: failing case --- packages/cli/tests/cli/init.test.ts | 217 ++++++++++-------- .../cli/init/ethereum/abis/Airdropped.json | 27 +++ .../from-contract-with-lists-in-abi.stdout | 12 + 3 files changed, 160 insertions(+), 96 deletions(-) create mode 100644 packages/cli/tests/cli/init/ethereum/abis/Airdropped.json create mode 100644 packages/cli/tests/cli/init/ethereum/from-contract-with-lists-in-abi.stdout diff --git a/packages/cli/tests/cli/init.test.ts b/packages/cli/tests/cli/init.test.ts index d54de4419..24fcb7073 100644 --- a/packages/cli/tests/cli/init.test.ts +++ b/packages/cli/tests/cli/init.test.ts @@ -4,105 +4,105 @@ import { cliTest } from './util'; describe('Init', () => { const baseDir = path.join(__dirname, 'init'); - describe('Ethereum', () => { + describe.only('Ethereum', () => { const ethereumBaseDir = path.join(baseDir, 'ethereum'); - cliTest( - 'From example', - [ - 'init', - '--protocol', - 'ethereum', - '--studio', - '--from-example', - 'ethereum/gravatar', - 'user/example-subgraph', - path.join(ethereumBaseDir, 'from-example'), - ], - path.join('init', 'ethereum', 'from-example'), - { - exitCode: 0, - timeout: 100_000, - cwd: ethereumBaseDir, - deleteDir: true, - }, - ); + // cliTest( + // 'From example', + // [ + // 'init', + // '--protocol', + // 'ethereum', + // '--studio', + // '--from-example', + // 'ethereum/gravatar', + // 'user/example-subgraph', + // path.join(ethereumBaseDir, 'from-example'), + // ], + // path.join('init', 'ethereum', 'from-example'), + // { + // exitCode: 0, + // timeout: 100_000, + // cwd: ethereumBaseDir, + // deleteDir: true, + // }, + // ); - cliTest( - 'From contract', - [ - 'init', - '--protocol', - 'ethereum', - '--studio', - '--from-contract', - '0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d', - '--network', - 'mainnet', - 'user/subgraph-from-contract', - path.join(ethereumBaseDir, 'from-contract'), - ], - path.join('init', 'ethereum', 'from-contract'), - { - exitCode: 0, - timeout: 100_000, - cwd: ethereumBaseDir, - deleteDir: true, - }, - ); + // cliTest( + // 'From contract', + // [ + // 'init', + // '--protocol', + // 'ethereum', + // '--studio', + // '--from-contract', + // '0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d', + // '--network', + // 'mainnet', + // 'user/subgraph-from-contract', + // path.join(ethereumBaseDir, 'from-contract'), + // ], + // path.join('init', 'ethereum', 'from-contract'), + // { + // exitCode: 0, + // timeout: 100_000, + // cwd: ethereumBaseDir, + // deleteDir: true, + // }, + // ); - cliTest( - 'From contract with abi', - [ - 'init', - '--protocol', - 'ethereum', - '--studio', - '--from-contract', - '0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d', - '--abi', - path.join(ethereumBaseDir, 'abis', 'Marketplace.json'), - '--network', - 'mainnet', - 'user/subgraph-from-contract-with-abi', - path.join(ethereumBaseDir, 'from-contract-with-abi'), - ], - path.join('init', 'ethereum', 'from-contract-with-abi'), - { - exitCode: 0, - timeout: 100_000, - cwd: ethereumBaseDir, - deleteDir: true, - }, - ); + // cliTest( + // 'From contract with abi', + // [ + // 'init', + // '--protocol', + // 'ethereum', + // '--studio', + // '--from-contract', + // '0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d', + // '--abi', + // path.join(ethereumBaseDir, 'abis', 'Marketplace.json'), + // '--network', + // 'mainnet', + // 'user/subgraph-from-contract-with-abi', + // path.join(ethereumBaseDir, 'from-contract-with-abi'), + // ], + // path.join('init', 'ethereum', 'from-contract-with-abi'), + // { + // exitCode: 0, + // timeout: 100_000, + // cwd: ethereumBaseDir, + // deleteDir: true, + // }, + // ); - cliTest( - 'From contract with abi and structs', - [ - 'init', - '--protocol', - 'ethereum', - '--studio', - '--from-contract', - '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', - '--abi', - path.join(ethereumBaseDir, 'abis', 'SoloMargin.json'), - '--network', - 'mainnet', - 'user/subgraph-from-contract-with-abi-and-structs', - path.join(ethereumBaseDir, 'from-contract-with-abi-and-structs'), - ], - path.join('init', 'ethereum', 'from-contract-with-abi-and-structs'), - { - exitCode: 0, - timeout: 100_000, - cwd: ethereumBaseDir, - deleteDir: true, - }, - ); + // cliTest( + // 'From contract with abi and structs', + // [ + // 'init', + // '--protocol', + // 'ethereum', + // '--studio', + // '--from-contract', + // '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', + // '--abi', + // path.join(ethereumBaseDir, 'abis', 'SoloMargin.json'), + // '--network', + // 'mainnet', + // 'user/subgraph-from-contract-with-abi-and-structs', + // path.join(ethereumBaseDir, 'from-contract-with-abi-and-structs'), + // ], + // path.join('init', 'ethereum', 'from-contract-with-abi-and-structs'), + // { + // exitCode: 0, + // timeout: 100_000, + // cwd: ethereumBaseDir, + // deleteDir: true, + // }, + // ); cliTest( - 'From contract with overloaded elements', + 'From contract with list items in abi', [ 'init', '--protocol', @@ -111,13 +111,13 @@ describe('Init', () => { '--from-contract', '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', '--abi', - path.join(ethereumBaseDir, 'abis', 'OverloadedElements.json'), + path.join(ethereumBaseDir, 'abis', 'Airdropped.json'), '--network', 'mainnet', - 'user/subgraph-from-contract-with-overloaded-elements', - path.join(ethereumBaseDir, 'from-contract-with-overloaded-elements'), + 'user/subgraph-from-contract-with-lists-in-abi', + path.join(ethereumBaseDir, 'from-contract-with-lists-in-abi'), ], - path.join('init', 'ethereum', 'from-contract-with-overloaded-elements'), + path.join('init', 'ethereum', 'from-contract-with-lists-in-abi'), { exitCode: 0, timeout: 100_000, @@ -125,6 +125,31 @@ describe('Init', () => { deleteDir: true, }, ); + + // cliTest( + // 'From contract with overloaded elements', + // [ + // 'init', + // '--protocol', + // 'ethereum', + // '--studio', + // '--from-contract', + // '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', + // '--abi', + // path.join(ethereumBaseDir, 'abis', 'OverloadedElements.json'), + // '--network', + // 'mainnet', + // 'user/subgraph-from-contract-with-overloaded-elements', + // path.join(ethereumBaseDir, 'from-contract-with-overloaded-elements'), + // ], + // path.join('init', 'ethereum', 'from-contract-with-overloaded-elements'), + // { + // exitCode: 0, + // timeout: 100_000, + // cwd: ethereumBaseDir, + // deleteDir: true, + // }, + // ); }); describe('NEAR', () => { diff --git a/packages/cli/tests/cli/init/ethereum/abis/Airdropped.json b/packages/cli/tests/cli/init/ethereum/abis/Airdropped.json new file mode 100644 index 000000000..da8a6f550 --- /dev/null +++ b/packages/cli/tests/cli/init/ethereum/abis/Airdropped.json @@ -0,0 +1,27 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address[]", + "name": "to", + "type": "address[]" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "quantity", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "fromTokenId", + "type": "uint256" + } + ], + "name": "Airdropped", + "type": "event" + } +] diff --git a/packages/cli/tests/cli/init/ethereum/from-contract-with-lists-in-abi.stdout b/packages/cli/tests/cli/init/ethereum/from-contract-with-lists-in-abi.stdout new file mode 100644 index 000000000..dda50d6d5 --- /dev/null +++ b/packages/cli/tests/cli/init/ethereum/from-contract-with-lists-in-abi.stdout @@ -0,0 +1,12 @@ + +Subgraph user/subgraph-from-contract-with-lists-in-abi created in from-contract-with-lists-in-abi + +Next steps: + + 1. Run `graph auth` to authenticate with your deploy key. + + 2. Type `cd from-contract-with-lists-in-abi` to enter the subgraph. + + 3. Run `yarn deploy` to deploy the subgraph. + +Make sure to visit the documentation on https://thegraph.com/docs/ for further information. From d068c134b0d270a463f90592687ecb455b3bf03e Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Mon, 20 Mar 2023 14:24:59 -0400 Subject: [PATCH 2/7] make it work --- packages/cli/src/scaffold/schema.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/scaffold/schema.ts b/packages/cli/src/scaffold/schema.ts index ab5c08485..ec1a2cc39 100644 --- a/packages/cli/src/scaffold/schema.ts +++ b/packages/cli/src/scaffold/schema.ts @@ -4,19 +4,26 @@ import * as util from '../codegen/util'; import Protocol from '../protocols'; export function abiEvents(abi: { data: immutable.Collection }) { - return util.disambiguateNames({ + return (util.disambiguateNames({ // @ts-expect-error improve typings of disambiguateNames to handle iterables values: abi.data.filter(item => item.get('type') === 'event'), // @ts-expect-error improve typings of disambiguateNames to handle iterables getName: event => event.get('name'), // @ts-expect-error improve typings of disambiguateNames to handle iterables setName: (event, name) => event.set('_alias', name), - }) as unknown as immutable.List; + }) as unknown) as immutable.List; } export const protocolTypeToGraphQL = (protocol: string, name: string) => { const ascType = ascTypeForProtocol(protocol, name); - return valueTypeForAsc(ascType); + // TODO: we need to figure out how to improve types + // but for now this always is returning a string + const convertedType = valueTypeForAsc(ascType) as string; + + // TODO: this is a hack to make array type non-nullable + // We should refactor the way we convert the Values from ASC to GraphQL + // For arrays we always want non-nullable children + return convertedType.endsWith(']') ? convertedType.replace(']', '!]') : convertedType; }; export const generateField = ({ From db9e6f8c76cd9fc812a316791ab7f9bc23f4f36f Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Mon, 20 Mar 2023 14:26:08 -0400 Subject: [PATCH 3/7] uncomment tests --- packages/cli/tests/cli/init.test.ts | 230 ++++++++++++++-------------- 1 file changed, 115 insertions(+), 115 deletions(-) diff --git a/packages/cli/tests/cli/init.test.ts b/packages/cli/tests/cli/init.test.ts index 24fcb7073..c3e7a2d3b 100644 --- a/packages/cli/tests/cli/init.test.ts +++ b/packages/cli/tests/cli/init.test.ts @@ -4,102 +4,102 @@ import { cliTest } from './util'; describe('Init', () => { const baseDir = path.join(__dirname, 'init'); - describe.only('Ethereum', () => { + describe('Ethereum', () => { const ethereumBaseDir = path.join(baseDir, 'ethereum'); - // cliTest( - // 'From example', - // [ - // 'init', - // '--protocol', - // 'ethereum', - // '--studio', - // '--from-example', - // 'ethereum/gravatar', - // 'user/example-subgraph', - // path.join(ethereumBaseDir, 'from-example'), - // ], - // path.join('init', 'ethereum', 'from-example'), - // { - // exitCode: 0, - // timeout: 100_000, - // cwd: ethereumBaseDir, - // deleteDir: true, - // }, - // ); + cliTest( + 'From example', + [ + 'init', + '--protocol', + 'ethereum', + '--studio', + '--from-example', + 'ethereum/gravatar', + 'user/example-subgraph', + path.join(ethereumBaseDir, 'from-example'), + ], + path.join('init', 'ethereum', 'from-example'), + { + exitCode: 0, + timeout: 100_000, + cwd: ethereumBaseDir, + deleteDir: true, + }, + ); - // cliTest( - // 'From contract', - // [ - // 'init', - // '--protocol', - // 'ethereum', - // '--studio', - // '--from-contract', - // '0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d', - // '--network', - // 'mainnet', - // 'user/subgraph-from-contract', - // path.join(ethereumBaseDir, 'from-contract'), - // ], - // path.join('init', 'ethereum', 'from-contract'), - // { - // exitCode: 0, - // timeout: 100_000, - // cwd: ethereumBaseDir, - // deleteDir: true, - // }, - // ); + cliTest( + 'From contract', + [ + 'init', + '--protocol', + 'ethereum', + '--studio', + '--from-contract', + '0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d', + '--network', + 'mainnet', + 'user/subgraph-from-contract', + path.join(ethereumBaseDir, 'from-contract'), + ], + path.join('init', 'ethereum', 'from-contract'), + { + exitCode: 0, + timeout: 100_000, + cwd: ethereumBaseDir, + deleteDir: true, + }, + ); - // cliTest( - // 'From contract with abi', - // [ - // 'init', - // '--protocol', - // 'ethereum', - // '--studio', - // '--from-contract', - // '0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d', - // '--abi', - // path.join(ethereumBaseDir, 'abis', 'Marketplace.json'), - // '--network', - // 'mainnet', - // 'user/subgraph-from-contract-with-abi', - // path.join(ethereumBaseDir, 'from-contract-with-abi'), - // ], - // path.join('init', 'ethereum', 'from-contract-with-abi'), - // { - // exitCode: 0, - // timeout: 100_000, - // cwd: ethereumBaseDir, - // deleteDir: true, - // }, - // ); + cliTest( + 'From contract with abi', + [ + 'init', + '--protocol', + 'ethereum', + '--studio', + '--from-contract', + '0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d', + '--abi', + path.join(ethereumBaseDir, 'abis', 'Marketplace.json'), + '--network', + 'mainnet', + 'user/subgraph-from-contract-with-abi', + path.join(ethereumBaseDir, 'from-contract-with-abi'), + ], + path.join('init', 'ethereum', 'from-contract-with-abi'), + { + exitCode: 0, + timeout: 100_000, + cwd: ethereumBaseDir, + deleteDir: true, + }, + ); - // cliTest( - // 'From contract with abi and structs', - // [ - // 'init', - // '--protocol', - // 'ethereum', - // '--studio', - // '--from-contract', - // '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', - // '--abi', - // path.join(ethereumBaseDir, 'abis', 'SoloMargin.json'), - // '--network', - // 'mainnet', - // 'user/subgraph-from-contract-with-abi-and-structs', - // path.join(ethereumBaseDir, 'from-contract-with-abi-and-structs'), - // ], - // path.join('init', 'ethereum', 'from-contract-with-abi-and-structs'), - // { - // exitCode: 0, - // timeout: 100_000, - // cwd: ethereumBaseDir, - // deleteDir: true, - // }, - // ); + cliTest( + 'From contract with abi and structs', + [ + 'init', + '--protocol', + 'ethereum', + '--studio', + '--from-contract', + '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', + '--abi', + path.join(ethereumBaseDir, 'abis', 'SoloMargin.json'), + '--network', + 'mainnet', + 'user/subgraph-from-contract-with-abi-and-structs', + path.join(ethereumBaseDir, 'from-contract-with-abi-and-structs'), + ], + path.join('init', 'ethereum', 'from-contract-with-abi-and-structs'), + { + exitCode: 0, + timeout: 100_000, + cwd: ethereumBaseDir, + deleteDir: true, + }, + ); cliTest( 'From contract with list items in abi', @@ -126,30 +126,30 @@ describe('Init', () => { }, ); - // cliTest( - // 'From contract with overloaded elements', - // [ - // 'init', - // '--protocol', - // 'ethereum', - // '--studio', - // '--from-contract', - // '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', - // '--abi', - // path.join(ethereumBaseDir, 'abis', 'OverloadedElements.json'), - // '--network', - // 'mainnet', - // 'user/subgraph-from-contract-with-overloaded-elements', - // path.join(ethereumBaseDir, 'from-contract-with-overloaded-elements'), - // ], - // path.join('init', 'ethereum', 'from-contract-with-overloaded-elements'), - // { - // exitCode: 0, - // timeout: 100_000, - // cwd: ethereumBaseDir, - // deleteDir: true, - // }, - // ); + cliTest( + 'From contract with overloaded elements', + [ + 'init', + '--protocol', + 'ethereum', + '--studio', + '--from-contract', + '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', + '--abi', + path.join(ethereumBaseDir, 'abis', 'OverloadedElements.json'), + '--network', + 'mainnet', + 'user/subgraph-from-contract-with-overloaded-elements', + path.join(ethereumBaseDir, 'from-contract-with-overloaded-elements'), + ], + path.join('init', 'ethereum', 'from-contract-with-overloaded-elements'), + { + exitCode: 0, + timeout: 100_000, + cwd: ethereumBaseDir, + deleteDir: true, + }, + ); }); describe('NEAR', () => { From 3d019ebb0e2b5e920d033b72f2c582fd6bd2a171 Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Mon, 20 Mar 2023 14:37:49 -0400 Subject: [PATCH 4/7] prettier --- packages/cli/src/scaffold/schema.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/scaffold/schema.ts b/packages/cli/src/scaffold/schema.ts index ec1a2cc39..cb4b2773a 100644 --- a/packages/cli/src/scaffold/schema.ts +++ b/packages/cli/src/scaffold/schema.ts @@ -4,14 +4,14 @@ import * as util from '../codegen/util'; import Protocol from '../protocols'; export function abiEvents(abi: { data: immutable.Collection }) { - return (util.disambiguateNames({ + return util.disambiguateNames({ // @ts-expect-error improve typings of disambiguateNames to handle iterables values: abi.data.filter(item => item.get('type') === 'event'), // @ts-expect-error improve typings of disambiguateNames to handle iterables getName: event => event.get('name'), // @ts-expect-error improve typings of disambiguateNames to handle iterables setName: (event, name) => event.set('_alias', name), - }) as unknown) as immutable.List; + }) as unknown as immutable.List; } export const protocolTypeToGraphQL = (protocol: string, name: string) => { From de852df94df7bab814aa15b3e506b9b636d2c9b2 Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Mon, 20 Mar 2023 14:39:48 -0400 Subject: [PATCH 5/7] changeset --- .changeset/small-foxes-fix.md | 5 +++++ .vscode/settings.json | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/small-foxes-fix.md diff --git a/.changeset/small-foxes-fix.md b/.changeset/small-foxes-fix.md new file mode 100644 index 000000000..02d5b5436 --- /dev/null +++ b/.changeset/small-foxes-fix.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +make generated list children non-nullable diff --git a/.vscode/settings.json b/.vscode/settings.json index a5b038331..7ab9c2173 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "editor.formatOnSave": true, "yaml.schemas": { "https://json.schemastore.org/github-issue-config.json": ".github/ISSUE_TEMPLATE/config.yml" } From 2c2c882f6195bf55bc53cfcf39312fcbe15a9df7 Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Mon, 20 Mar 2023 14:40:21 -0400 Subject: [PATCH 6/7] undo vscode chnage --- .vscode/settings.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7ab9c2173..a5b038331 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,4 @@ { - "editor.formatOnSave": true, "yaml.schemas": { "https://json.schemastore.org/github-issue-config.json": ".github/ISSUE_TEMPLATE/config.yml" } From 480841a5577d9c5db3201a21d58a9dd70d7fcc0e Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Mon, 20 Mar 2023 23:32:23 -0400 Subject: [PATCH 7/7] fix a test --- packages/cli/src/scaffold/ethereum.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/scaffold/ethereum.test.ts b/packages/cli/src/scaffold/ethereum.test.ts index 2827331e1..5af1a8331 100644 --- a/packages/cli/src/scaffold/ethereum.test.ts +++ b/packages/cli/src/scaffold/ethereum.test.ts @@ -117,7 +117,7 @@ type ExampleEntity @entity { id: Bytes! count: BigInt! a: BigInt! # uint256 - b: [Bytes]! # bytes[4] + b: [Bytes!]! # bytes[4] } `); }); @@ -127,7 +127,7 @@ type ExampleEntity @entity { type ExampleEvent @entity(immutable: true) { id: Bytes! a: BigInt! # uint256 - b: [Bytes]! # bytes[4] + b: [Bytes!]! # bytes[4] param2: String! # string c_c1: BigInt! # uint256 c_value1: Bytes! # bytes32