Skip to content

Codegen fix follow up #2412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Enums being exported twice with codegen

## [4.10.0] - 2024-05-22
### Changed
Expand Down
19 changes: 19 additions & 0 deletions packages/cli/src/controller/codegen-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ describe('Codegen can generate schema', () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await expect(codegen(projectPath, ['project-bad-schema.yaml'])).rejects.toThrow(/is not an valid type/);
});

it('codegen with entities that uses reserved names should throw', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await expect(codegen(projectPath, ['project-bad-entity.yaml'])).rejects.toThrow(
'EntityName: exampleEntityFilter cannot end with reservedKey: filter'
);
});

it('Codegen should be able to generate ABIs from template datasources', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await codegen(projectPath, ['project-templates-abi.yaml']);
Expand All @@ -42,6 +44,7 @@ describe('Codegen can generate schema', () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await expect(codegen(projectPath, ['project-no-assets.yaml'])).resolves.not.toThrow();
});

it('Codegen should be able to generate ABIs from customName datasources', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await codegen(projectPath);
Expand All @@ -58,6 +61,7 @@ describe('Codegen can generate schema', () => {
// should not contain abi directory
await expect(fs.promises.readFile(`${projectPath}/src/types/abi-interfaces/Erc721.ts`, 'utf8')).rejects.toThrow();
});

it('should generate contracts on different glob paths', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await codegen(projectPath, ['typechain-test.yaml']);
Expand All @@ -74,14 +78,29 @@ describe('Codegen can generate schema', () => {
fs.promises.readFile(`${projectPath}/src/types/abi-interfaces/Artifact.ts`, 'utf8')
).resolves.toBeTruthy();
});

it('Should not generate ABI for non evm ds', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await codegen(projectPath, ['non-evm-project.yaml']);
expect(fs.existsSync(`${projectPath}/src/types/abi-interfaces/`)).toBeFalsy();
});

it('Should not generate proto-interfaces if no chaintypes are provided', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await codegen(projectPath, ['project-cosmos.yaml']);
expect(fs.existsSync(`${projectPath}/src/types/proto-interfaces/`)).toBeFalsy();
});

it('Should dedupe enums', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await codegen(projectPath, ['project-duplicate-enum.yaml']);

const fooFile = await fs.promises.readFile(`${projectPath}/src/types/models/foo.ts`, 'utf8');

expect(fooFile).toContain(
`import {
Bar,
} from '../enums';`
);
});
});
10 changes: 10 additions & 0 deletions packages/cli/test/schemaTest/duplicateEnum.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enum Bar {
FOO
BAR
}

type Foo @entity {
id: ID!
a: Bar!
b: Bar!
}
16 changes: 16 additions & 0 deletions packages/cli/test/schemaTest/project-duplicate-enum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
specVersion: '0.0.1'
description: ''
repository: 'https://github.com/subquery/subql-starter'
schema: './duplicateEnum.graphql'

network:
endpoint: 'wss://polkadot.api.onfinality.io/public-ws'

dataSources:
- name: main
kind: substrate/Runtime
startBlock: 1
mapping:
handlers:
- handler: handleBlock
kind: substrate/BlockHandler
Loading