Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Jan 28, 2025
1 parent c60b560 commit e535d2e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
18 changes: 4 additions & 14 deletions packages/cli/src/controller/codegen-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,54 @@ import {codegen} from './codegen-controller';

jest.setTimeout(30000);

const projectPath = path.join(__dirname, '../../test/schemaTest');

describe('Codegen can generate schema', () => {
afterEach(async () => {
await rimraf(path.join(__dirname, '../../test/schemaTest/src'));
});

it('codegen with correct schema should pass', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await expect(codegen(projectPath)).resolves.not.toThrow();
});

it('codegen with incorrect schema field should fail', async () => {
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']);
await expect(
fs.promises.readFile(`${projectPath}/src/types/abi-interfaces/Erc721.ts`, 'utf8')
).resolves.toBeTruthy();
});

it('Should not fail, if ds does not have any assets', async () => {
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);
await codegen(projectPath, ['project-with-abi.yaml']);
await expect(
fs.promises.readFile(`${projectPath}/src/types/abi-interfaces/Erc721.ts`, 'utf8')
).resolves.toBeTruthy();
});

it('Should clean out existing types directory', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await codegen(projectPath);
await codegen(projectPath, ['project-no-abi.yaml']);

// should not contain abi directory
await expect(fs.promises.readFile(`${projectPath}/src/types/abi-interfaces/Erc721.ts`, 'utf8')).rejects.toThrow();
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']);

await expect(
Expand All @@ -78,19 +72,16 @@ describe('Codegen can generate schema', () => {
});

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');
Expand All @@ -104,7 +95,6 @@ describe('Codegen can generate schema', () => {

// github issue #2211
it('codegen file should import model files with correct case-sensitive names', async () => {
const projectPath = path.join(__dirname, '../../test/schemaTest');
await codegen(projectPath, ['project-case-sensitive-import-entity.yaml']);

const codegenFile = await fs.promises.readFile(`${projectPath}/src/types/models/index.ts`, 'utf8');
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/controller/codegen-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ export async function codegen(projectPath: string, fileNames: string[] = [DEFAUL
datasources as CosmosRuntimeDatasource[]
);
}
// TODO what about custom datasource processors, e.g. FrontierEvmProcessor, EthermintProcessor
const ethManifests = plainManifests.filter((m) => m.networkFamily === NETWORK_FAMILY.ethereum);

// Todo, starknet codegen not supported yet
const starknetManifests = plainManifests.filter((m) => m.networkFamily === NETWORK_FAMILY.starknet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ schema:
file: './schema.graphql'
runner:
node:
name: '@subql/node'
name: '@subql/node-ethereum'
version: '>=3.0.1'
query:
name: '@subql/query'
Expand Down

0 comments on commit e535d2e

Please sign in to comment.