Skip to content

Commit

Permalink
📝 Feat: Add natspec comments to contract imports
Browse files Browse the repository at this point in the history
  • Loading branch information
William Cory authored and William Cory committed Aug 15, 2024
1 parent 357bc86 commit f06ff2b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-pans-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tevm/runtime": patch
---

Added natspec comments to contract imports linking to documentation
7 changes: 6 additions & 1 deletion bundler-packages/runtime/src/generateRuntime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('generateRuntime', () => {
/**
* MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
module.exports.MyContract = createContract(_MyContract)"
`)
Expand All @@ -66,7 +67,9 @@ describe('generateRuntime', () => {
const _abiMyContract = ["constructor() payable"] as const;
const _nameMyContract = "MyContract" as const;
/**
* MyContract Contract
* MyContract Contract (no bytecode)
* change file name or add file that ends in '.s.sol' extension if you wish to compile the bytecode
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
* @notice MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
*/
Expand All @@ -87,6 +90,7 @@ describe('generateRuntime', () => {
/**
* MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const MyContract = createContract(_MyContract)"
`)
Expand All @@ -105,6 +109,7 @@ describe('generateRuntime', () => {
/**
* MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const MyContract = createContract(_MyContract)"
`)
Expand Down
8 changes: 4 additions & 4 deletions bundler-packages/runtime/src/generateTevmBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export const generateTevmBody = (artifacts, moduleType, includeBytecode) => {
if (userdoc.notice) {
natspec.unshift(` * ${userdoc.notice}`)
}
if (natspec.length) {
natspec.unshift('/**')
natspec.push(' */')
}
natspec.push(` * @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation`)
natspec.unshift('/**')
natspec.push(' */')

if (moduleType === 'cjs') {
return [
`const _${contractName} = ${contract}`,
Expand Down
14 changes: 12 additions & 2 deletions bundler-packages/runtime/src/generateTevmBody.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('generateTevmBody', () => {
/**
* MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
module.exports.MyContract = createContract(_MyContract)
const _AnotherContract = {
Expand All @@ -53,6 +54,7 @@ describe('generateTevmBody', () => {
}
/**
* MyContract
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
module.exports.AnotherContract = createContract(_AnotherContract)"
`)
Expand All @@ -68,6 +70,7 @@ describe('generateTevmBody', () => {
/**
* MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const MyContract = createContract(_MyContract)
const _AnotherContract = {
Expand All @@ -76,6 +79,7 @@ describe('generateTevmBody', () => {
}
/**
* MyContract
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const AnotherContract = createContract(_AnotherContract)"
`)
Expand All @@ -91,6 +95,7 @@ describe('generateTevmBody', () => {
/**
* MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const MyContract = createContract(_MyContract)
const _AnotherContract = {
Expand All @@ -99,6 +104,7 @@ describe('generateTevmBody', () => {
} as const
/**
* MyContract
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const AnotherContract = createContract(_AnotherContract)"
`)
Expand All @@ -110,15 +116,19 @@ describe('generateTevmBody', () => {
"const _abiMyContract = [] as const;
const _nameMyContract = "MyContract" as const;
/**
* MyContract Contract
* MyContract Contract (no bytecode)
* change file name or add file that ends in '.s.sol' extension if you wish to compile the bytecode
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
* @notice MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
*/
export const MyContract: Contract<typeof _nameMyContract, typeof _abiMyContract, undefined, undefined, undefined, undefined>;
const _abiAnotherContract = [] as const;
const _nameAnotherContract = "AnotherContract" as const;
/**
* AnotherContract Contract
* AnotherContract Contract (no bytecode)
* change file name or add file that ends in '.s.sol' extension if you wish to compile the bytecode
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
* @notice MyContract
*/
export const AnotherContract: Contract<typeof _nameAnotherContract, typeof _abiAnotherContract, undefined, undefined, undefined, undefined>;"
Expand Down
11 changes: 5 additions & 6 deletions bundler-packages/runtime/src/generateTevmBodyDts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ export const generateDtsBody = (artifacts, includeBytecode) => {
return [
`const _name${contractName} = ${JSON.stringify(contractName, null, 2)} as const;`,
`const _abi${contractName} = ${JSON.stringify(contract.humanReadableAbi, null, 2)} as const;`,
'// type _Address = undefined',
'// type _Bytecode = `0x${string}`',
'// type _DeployedBytecode = `0x${string}`',
'// type _Code = undefined',
'/**',
` * ${contractName} Contract+Script`,
` * ${contractName} Contract (with bytecode)`,
...natspec,
` * @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation`,
' */',
`export const ${contractName}: Contract<`,
` typeof _name${contractName},`,
Expand All @@ -46,7 +43,9 @@ export const generateDtsBody = (artifacts, includeBytecode) => {
`const _abi${contractName} = ${JSON.stringify(contract.humanReadableAbi)} as const;`,
`const _name${contractName} = ${JSON.stringify(contractName)} as const;`,
'/**',
` * ${contractName} Contract`,
` * ${contractName} Contract (no bytecode)`,
` * change file name or add file that ends in '.s.sol' extension if you wish to compile the bytecode`,
` * @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation`,
...natspec,
' */',
`export const ${contractName}: Contract<typeof _name${contractName}, typeof _abi${contractName}, undefined, undefined, undefined, undefined>;`,
Expand Down
12 changes: 9 additions & 3 deletions bundler-packages/runtime/src/generateTevmBodyDts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,28 @@ describe('generateDtsBody', () => {
"const _abiMyContract = ["constructor() payable"] as const;
const _nameMyContract = "MyContract" as const;
/**
* MyContract Contract
* MyContract Contract (no bytecode)
* change file name or add file that ends in '.s.sol' extension if you wish to compile the bytecode
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
* @notice MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
*/
export const MyContract: Contract<typeof _nameMyContract, typeof _abiMyContract, undefined, undefined, undefined, undefined>;
const _abiAnotherContract = [] as const;
const _nameAnotherContract = "AnotherContract" as const;
/**
* AnotherContract Contract
* AnotherContract Contract (no bytecode)
* change file name or add file that ends in '.s.sol' extension if you wish to compile the bytecode
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
* @notice MyContract
*/
export const AnotherContract: Contract<typeof _nameAnotherContract, typeof _abiAnotherContract, undefined, undefined, undefined, undefined>;
const _abiMissingContract = [] as const;
const _nameMissingContract = "MissingContract" as const;
/**
* MissingContract Contract
* MissingContract Contract (no bytecode)
* change file name or add file that ends in '.s.sol' extension if you wish to compile the bytecode
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
* @notice MyContract
* @property balanceOf(address) Returns the amount of tokens owned by account
*/
Expand Down
8 changes: 6 additions & 2 deletions lsp/ts-plugin/src/decorators/getScriptSnapshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ describe(getScriptSnapshotDecorator.name, () => {
const _abiHelloWorld = ["function greet() pure returns (string)"] as const;
const _nameHelloWorld = "HelloWorld" as const;
/**
* HelloWorld Contract
* HelloWorld Contract (no bytecode)
* change file name or add file that ends in '.s.sol' extension if you wish to compile the bytecode
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const HelloWorld: Contract<typeof _nameHelloWorld, typeof _abiHelloWorld, undefined, undefined, undefined, undefined>;
const _abiHelloWorld2 = ["function greet2() pure returns (string)"] as const;
const _nameHelloWorld2 = "HelloWorld2" as const;
/**
* HelloWorld2 Contract
* HelloWorld2 Contract (no bytecode)
* change file name or add file that ends in '.s.sol' extension if you wish to compile the bytecode
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const HelloWorld2: Contract<typeof _nameHelloWorld2, typeof _abiHelloWorld2, undefined, undefined, undefined, undefined>;"
`)
Expand Down

0 comments on commit f06ff2b

Please sign in to comment.