Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/null-fallback-parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphprotocol/graph-cli": patch
---

Handle explorer ABIs with null input/output arrays on nameless fallback functions during code generation.
45 changes: 45 additions & 0 deletions packages/cli/src/protocols/ethereum/abi.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os from 'node:os';
import path from 'node:path';
import fs from 'fs-extra';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import ABI from './abi.js';

describe('ABI fallback parameters', () => {
let dir: string;
beforeEach(async () => {
dir = await fs.mkdtemp(path.join(os.tmpdir(), 'graph-abi-'));
});
afterEach(async () => {
await fs.remove(dir);
});

it.each([null, undefined, []])(
'generates a nameless fallback with parameters %s',
async parameters => {
const file = path.join(dir, 'abi.json');
await fs.writeJson(file, [
{
type: 'fallback',
name: '',
inputs: parameters,
outputs: parameters,
stateMutability: 'payable',
},
{
type: 'function',
name: 'withdraw',
inputs: [{ name: 'wad', type: 'uint256' }],
outputs: [],
stateMutability: 'nonpayable',
},
]);
const abi = ABI.load('Contract', file);
expect(() => abi.callFunctionSignatures()).not.toThrow();
const types = await abi.codeGenerator().generateTypes();
const code = types.map(type => type.toString()).join('\n');
expect(code).toContain('class DefaultCall');
expect(code).toContain('class WithdrawCall');
expect(code).toContain('get wad()');
},
);
});
8 changes: 7 additions & 1 deletion packages/cli/src/protocols/ethereum/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ export default class ABI {
throw Error(`No valid ABI in file: ${path.relative(process.cwd(), file)}`);
}

return new ABI(name, file, immutable.fromJS(abi));
// Some explorer ABIs encode the parameterless fallback with null arrays.
const entries = abi.map((entry: any) =>
entry.type === 'fallback'
? { ...entry, inputs: entry.inputs ?? [], outputs: entry.outputs ?? [] }
: entry,
);
return new ABI(name, file, immutable.fromJS(entries));
}
}