Skip to content

Commit

Permalink
feat(abstract): add support for abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuuGan committed May 17, 2020
1 parent 8754c6d commit 555ffaf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/exportsAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ExportType } from './types';
const error = Debug('sol-merger:error');

export interface ExportsAnalyzerResult {
abstact: boolean;
type: ExportType;
name: string;
is: string;
Expand All @@ -30,6 +31,7 @@ export class ExportsAnalyzer {
const visitor = new SolidityExportVisitor(this.contents);
visitor.visit((e) => {
results.push({
abstact: e.abstract,
type: e.type,
name: e.name,
body: this.contents.substring(e.body.start, e.body.end + 1).trim(),
Expand Down
4 changes: 3 additions & 1 deletion lib/fileAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class FileAnalyzer {
}
});
}
return `${e.type} ${newName || e.name} ${is}${e.body}`;

const abstract = e.abstact ? 'abstract ' : '';
return `${abstract}${e.type} ${newName || e.name} ${is}${e.body}`;
}
/**
* Filename to read to get contract data
Expand Down
10 changes: 10 additions & 0 deletions test/compiled/AbstractContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.6.0;


abstract contract Feline {
function utterance() public virtual returns (bytes32);
}

contract Cat is Feline {
function utterance() public override returns (bytes32) { return "miaow"; }
}
9 changes: 9 additions & 0 deletions test/contracts/AbstractContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pragma solidity ^0.6.0;

abstract contract Feline {
function utterance() public virtual returns (bytes32);
}

contract Cat is Feline {
function utterance() public override returns (bytes32) { return "miaow"; }
}
9 changes: 8 additions & 1 deletion test/exportsAnalyzer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,37 @@ describe('ExportsAnalyzer', () => {
const exports = exportsAnalyzer.analyzeExports();

assert.deepEqual(exports, [
{ type: 'contract', name: 'A', is: '', body: '{ }' },
{ abstact: false, type: 'contract', name: 'A', is: '', body: '{ }' },
{
abstact: false,
type: 'contract',
name: 'B',
is: 'is A ',
body: '{\n // some body here...\n }',
},
{
abstact: false,
type: 'library',
name: 'L',
is: '',
body: '{\n // l...\n }',
},
{
abstact: false,
type: 'interface',
name: 'B',
is: '',
body: '{\n // i...\n }',
},
{
abstact: false,
body: '{\n uint weight;\n bool voted;\n }',
is: '',
name: 'S',
type: 'struct',
},
{
abstact: false,
body:
'{\n Created,\n Locked,\n Inactive\n }',
is: '',
Expand All @@ -78,12 +83,14 @@ describe('ExportsAnalyzer', () => {

assert.deepEqual(exports, [
{
abstact: false,
body: '// Some contracts without exports',
is: '',
name: 'Comment#9',
type: 'comment',
},
{
abstact: false,
body: '// Some contract text that is not required here',
is: '',
name: 'Comment#52',
Expand Down
4 changes: 4 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ describe('Solidity Merger', () => {
await testFile('GlobalComments');
});

it('should compile abstract contracts', async () => {
await testFile('AbstractContract');
});

it('should compile file without imports and exports (empty content)', async () => {
const merger = new Merger();
const file = path.join(__dirname, `/contracts/EmptyFile.sol`);
Expand Down

0 comments on commit 555ffaf

Please sign in to comment.