Skip to content

Commit

Permalink
🐛 Fix: Change contract import of generated file to import type {Contr…
Browse files Browse the repository at this point in the history
…act} (#1382)

## Description

closes #1343

## Testing

Explain the quality checks that have been done on the code changes

## Additional Information

- [ ] I read the [contributing docs](../docs/contributing.md) (if this
is your first contribution)

Your ENS/address:

---------

Co-authored-by: William Cory <[email protected]>
  • Loading branch information
roninjin10 and William Cory committed Aug 15, 2024
1 parent 35f2d5e commit 7eebe33
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-carpets-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tevm/runtime": patch
---

Changed the import type of Contract in generated files to include an explicit `type` modifier
30 changes: 26 additions & 4 deletions bundler-packages/base-bundler/src/bundler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,13 @@ describe(bundler.name, () => {
"evmVersion": "homestead",
},
},
"code": "import { Contract } from '@tevm/contract'
"code": "import type { Contract } from '@tevm/contract'
const _abiTestContract = [] as const;
const _nameTestContract = "TestContract" as const;
/**
* TestContract Contract
* TestContract 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 TestContract: Contract<typeof _nameTestContract, typeof _abiTestContract, undefined, undefined, undefined, undefined>;",
"modules": {
Expand Down Expand Up @@ -349,11 +351,13 @@ describe(bundler.name, () => {
"evmVersion": "homestead",
},
},
"code": "import { Contract } from '@tevm/contract'
"code": "import type { Contract } from '@tevm/contract'
const _abiTestContract = [] as const;
const _nameTestContract = "TestContract" as const;
/**
* TestContract Contract
* TestContract 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 TestContract: Contract<typeof _nameTestContract, typeof _abiTestContract, undefined, undefined, undefined, undefined>;",
"modules": {
Expand Down Expand Up @@ -438,6 +442,9 @@ describe(bundler.name, () => {
"name": "TestContract",
"humanReadableAbi": []
} as const
/**
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const TestContract = createContract(_TestContract)",
"modules": {
"module1": {
Expand Down Expand Up @@ -521,6 +528,9 @@ describe(bundler.name, () => {
"name": "TestContract",
"humanReadableAbi": []
} as const
/**
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const TestContract = createContract(_TestContract)",
"modules": {
"module1": {
Expand Down Expand Up @@ -604,6 +614,9 @@ describe(bundler.name, () => {
"name": "TestContract",
"humanReadableAbi": []
}
/**
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
module.exports.TestContract = createContract(_TestContract)",
"modules": {
"module1": {
Expand Down Expand Up @@ -687,6 +700,9 @@ describe(bundler.name, () => {
"name": "TestContract",
"humanReadableAbi": []
}
/**
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
module.exports.TestContract = createContract(_TestContract)",
"modules": {
"module1": {
Expand Down Expand Up @@ -770,6 +786,9 @@ describe(bundler.name, () => {
"name": "TestContract",
"humanReadableAbi": []
}
/**
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const TestContract = createContract(_TestContract)",
"modules": {
"module1": {
Expand Down Expand Up @@ -853,6 +872,9 @@ describe(bundler.name, () => {
"name": "TestContract",
"humanReadableAbi": []
}
/**
* @see [contract docs](https://tevm.sh/learn/contracts/) for more documentation
*/
export const TestContract = createContract(_TestContract)",
"modules": {
"module1": {
Expand Down
4 changes: 2 additions & 2 deletions bundler-packages/runtime/src/generateRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { generateTevmBody } from './generateTevmBody.js'
const importsByModuleType = (contractPackage) => ({
contract: {
cjs: `const { createContract } = require('${contractPackage}')`,
dts: `import { Contract } from '${contractPackage}'`,
dts: `import type { Contract } from '${contractPackage}'`,
ts: `import { createContract } from '${contractPackage}'`,
mjs: `import { createContract } from '${contractPackage}'`,
},
script: {
cjs: `const { createContract } = require('${contractPackage}')`,
dts: `import { Contract } from '${contractPackage}'`,
dts: `import type { Contract } from '${contractPackage}'`,
ts: `import { createContract } from '${contractPackage}'`,
mjs: `import { createContract } from '${contractPackage}'`,
},
Expand Down
2 changes: 1 addition & 1 deletion bundler-packages/runtime/src/generateRuntime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('generateRuntime', () => {
it('should handle dts module type', () => {
const result = runSync(generateRuntime(artifacts, 'dts', false, '@tevm/contract'))
expect(result).toMatchInlineSnapshot(`
"import { Contract } from '@tevm/contract'
"import type { Contract } from '@tevm/contract'
const _abiMyContract = ["constructor() payable"] as const;
const _nameMyContract = "MyContract" as const;
/**
Expand Down
2 changes: 1 addition & 1 deletion lsp/ts-plugin/src/decorators/getScriptSnapshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe(getScriptSnapshotDecorator.name, () => {
const fileName = path.join(__dirname, '../test/fixtures/HelloWorld2.sol')
const result = decorator.getScriptSnapshot(fileName)
expect((result as any).text).toMatchInlineSnapshot(`
"import { Contract } from 'tevm/contract'
"import type { Contract } from 'tevm/contract'
const _abiHelloWorld = ["function greet() pure returns (string)"] as const;
const _nameHelloWorld = "HelloWorld" as const;
/**
Expand Down

0 comments on commit 7eebe33

Please sign in to comment.