-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Detect solc version in config (#359)
## Description Detect solc version from package.json instead. This feels ripe for bugs so it's a WIP ## 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: Will Cory <[email protected]>
- Loading branch information
1 parent
61482fa
commit e24901a
Showing
8 changed files
with
120 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@evmts/config": minor | ||
--- | ||
|
||
Added autodetection of solc version. solcVersion is no longer required |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { getDefaultSolcVersion } from './getDefaultSolcVersion.js' | ||
import { createRequire } from 'module' | ||
import { | ||
type MockedFunction, | ||
beforeEach, | ||
describe, | ||
expect, | ||
it, | ||
vi, | ||
} from 'vitest' | ||
|
||
let version: string | undefined = '0.8.9' | ||
vi.mock('module', () => ({ | ||
createRequire: vi.fn(), | ||
})) | ||
|
||
const mockCreateRequire = createRequire as MockedFunction<typeof createRequire> | ||
const mockRequire = vi.fn() | ||
const consoleErrorSpy = vi.fn() | ||
|
||
beforeEach(() => { | ||
vi.resetAllMocks() | ||
mockRequire.mockReturnValue({ version }) | ||
mockCreateRequire.mockReturnValue(mockRequire as any) | ||
vi.stubGlobal('console', { | ||
error: consoleErrorSpy, | ||
}) | ||
}) | ||
|
||
describe('getDefaultSolcVersion', () => { | ||
it('should return solc version if available', async () => { | ||
expect(getDefaultSolcVersion()).toBe(version) | ||
}) | ||
|
||
it('should log error and return undefined if version is not available', async () => { | ||
version = undefined | ||
mockRequire.mockReturnValue({ version }) | ||
expect(getDefaultSolcVersion()).toBe(undefined) | ||
expect(consoleErrorSpy).toBeCalledWith( | ||
'Failed to get solc version! Please install it or specify a version in your config', | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createRequire } from 'module' | ||
|
||
export const getDefaultSolcVersion = () => { | ||
const moduleRequire = createRequire(import.meta.url ?? __dirname) | ||
const solc = moduleRequire('solc') | ||
const version = solc?.version | ||
if (!version) { | ||
console.error( | ||
'Failed to get solc version! Please install it or specify a version in your config', | ||
) | ||
} | ||
return solc?.version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters