Skip to content

Commit

Permalink
Fix abi validation when DS has no abi specified (#307)
Browse files Browse the repository at this point in the history
* Fix abi validation when DS has no abi specified

* Update changelog
  • Loading branch information
stwiname authored Jun 10, 2024
1 parent 6f27550 commit 0929aeb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/common-ethereum/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
- Abi validatation when DS doesn't specify abi option (#307)

## [3.8.1] - 2024-06-07
### Added
Expand Down
37 changes: 37 additions & 0 deletions packages/common-ethereum/src/codegen/codegen-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,41 @@ describe('Codegen spec', () => {
/Topic: "NotExist\(address a\)" not found in erc20 contract interface/
);
});

it('doesnt validate if datasource has no abi option set', async () => {
const ds: SubqlRuntimeDatasource = {
kind: EthereumDatasourceKind.Runtime,
startBlock: 1,
assets: new Map([['erc20', {file: './abis/erc20.json'}]]),
mapping: {
file: '',
handlers: [
{
handler: 'handleTransaction',
kind: EthereumHandlerKind.Event,
filter: {
topics: ['Transfer(address a,address b,uint256 c)'],
},
},
{
handler: 'handleTransaction',
kind: EthereumHandlerKind.Event,
filter: {
topics: ['Transfer(address a,address b,uint256 c)', 'NotExist(address a)'],
},
},
],
},
};

await expect(
generateAbis(
[ds],
PROJECT_PATH,
(p) => Promise.resolve(),
(v) => v,
() => Promise.resolve()
)
).resolves.not.toThrow();
});
});
4 changes: 4 additions & 0 deletions packages/common-ethereum/src/codegen/codegen-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function validateCustomDsDs(d: {kind: string}): boolean {
function validateAbi(datasources: SubqlRuntimeDatasource[], projectPath: string) {
const issues: string[] = [];
for (const datasource of datasources) {
if (!datasource.options?.abi) {
// No ABI to validate
continue;
}
const abiName = datasource.options.abi;
const topicIssues: string[] = [];
const funcIssues: string[] = [];
Expand Down

0 comments on commit 0929aeb

Please sign in to comment.