Skip to content
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

feat: license mock contracts #42

Merged
merged 1 commit into from
Jan 2, 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
1 change: 1 addition & 0 deletions solidity/contracts/ContractTest.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IContractTest, MyContract} from '../interfaces/IContractTest.sol';
Expand Down
1 change: 1 addition & 0 deletions solidity/contracts/Lib.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library Lib {
Expand Down
1 change: 1 addition & 0 deletions solidity/interfaces/IContractTest.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MyContract {}
Expand Down
8 changes: 6 additions & 2 deletions src/smock-foundry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export const generateMockContracts = async (
// Check if the abi and ast exist
if (!ast) return;

// Get the absolute path from the ast
// Get the license from the ast
const license: string = ast.license;

// Get the absolute path
const contractImport: string = ast.absolutePath;
if (!contractImport) return;

Expand All @@ -97,10 +100,11 @@ export const generateMockContracts = async (
if (!contractNode || contractNode.contractKind === 'library') return;

const functions: StateVariablesOptions = getStateVariables(contractNode);
// All data which will be use for create the template

// All data which will be used for creating the template
const data = {
contractName: contractName,
license: license,
contractImport: contractImport,
exportedSymbols: exportedSymbols.join(', '),
import: getImports(ast),
Expand Down
2 changes: 1 addition & 1 deletion src/templates/mockContractTemplate.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: {{#if license}}{{license}}{{else}}UNLICENSED{{/if}}
pragma solidity ^0.8.0;

import {Test} from 'forge-std/Test.sol';
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export interface FunctionDefinitionNode {
}

export interface Ast {
absolutePath: string;
nodeType: 'SourceUnit';
id?: number;
nodeType: string;
src: string;
nodes: AstNode[];
license: string;
absolutePath: string;
exportedSymbols: { [key: string]: number[] };
}

Expand Down
1 change: 1 addition & 0 deletions test/unit/get-imports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('getImports', () => {
exportedSymbols: {},
};
});

it('should return an empty array if there are no import directives', async () => {
const importStatements = getImports(ast);
expect(importStatements).to.be.an('array').that.is.empty;
Expand Down