-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance the solidity test artifacts discovery
- Loading branch information
Showing
6 changed files
with
258 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
98 changes: 98 additions & 0 deletions
98
v-next/hardhat/test/internal/builtin-plugins/solidity-test/helpers.ts
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,98 @@ | ||
import type { Artifact } from "@ignored/edr"; | ||
|
||
import assert from "node:assert/strict"; | ||
import { describe, it } from "node:test"; | ||
|
||
import { isTestArtifact } from "../../../../src/internal/builtin-plugins/solidity-test/helpers.js"; | ||
|
||
const testCases = [ | ||
{ | ||
contract: "Abstract", | ||
expected: false, | ||
}, | ||
{ | ||
contract: "NoTest", | ||
expected: false, | ||
}, | ||
{ | ||
contract: "PublicTest", | ||
expected: true, | ||
}, | ||
{ | ||
contract: "ExternalTest", | ||
expected: true, | ||
}, | ||
{ | ||
contract: "PrivateTest", | ||
expected: false, | ||
}, | ||
{ | ||
contract: "InternalTest", | ||
expected: false, | ||
}, | ||
{ | ||
contract: "PublicInvariant", | ||
expected: true, | ||
}, | ||
{ | ||
contract: "ExternalInvariant", | ||
expected: true, | ||
}, | ||
{ | ||
contract: "PrivateInvariant", | ||
expected: false, | ||
}, | ||
{ | ||
contract: "InternalInvariant", | ||
expected: false, | ||
}, | ||
]; | ||
|
||
describe.only("isTestArtifact", () => { | ||
for (const { contract, expected } of testCases) { | ||
it(`should return ${expected} for the ${contract} contract`, async () => { | ||
const artifact: Artifact = { | ||
id: { | ||
name: contract, | ||
source: `test-fixtures/Test.t.sol`, | ||
solcVersion: "0.8.20", | ||
}, | ||
contract: { | ||
abi: "", | ||
}, | ||
}; | ||
const actual = await isTestArtifact(import.meta.dirname, artifact); | ||
assert.equal(actual, expected); | ||
}); | ||
} | ||
|
||
it("should return false if a file does not exist", async () => { | ||
const artifact: Artifact = { | ||
id: { | ||
name: "Contract", | ||
source: `test-fixtures/NonExistent.t.sol`, | ||
solcVersion: "0.8.20", | ||
}, | ||
contract: { | ||
abi: "", | ||
}, | ||
}; | ||
const actual = await isTestArtifact(import.meta.dirname, artifact); | ||
assert.equal(actual, false); | ||
}); | ||
|
||
it("should return false if the file has the wrong extension", async () => { | ||
const artifact: Artifact = { | ||
id: { | ||
name: "Contract", | ||
source: `test-fixtures/WrongExtension.sol`, | ||
solcVersion: "0.8.20", | ||
}, | ||
contract: { | ||
abi: "", | ||
}, | ||
}; | ||
const actual = await isTestArtifact(import.meta.dirname, artifact); | ||
assert.equal(actual, false); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
v-next/hardhat/test/internal/builtin-plugins/solidity-test/test-fixtures/Test.t.sol
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 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.20; | ||
|
||
abstract contract Abstract { | ||
function testPublic() public {} | ||
function testExternal() external {} | ||
function invariantPublic() public {} | ||
function invariantExternal() external {} | ||
} | ||
|
||
contract NoTest {} | ||
|
||
contract PublicTest { | ||
function test() public {} | ||
} | ||
|
||
contract ExternalTest { | ||
function test() external {} | ||
} | ||
|
||
contract PrivateTest { | ||
function test() private {} | ||
} | ||
|
||
contract InternalTest { | ||
function test() internal {} | ||
} | ||
|
||
contract PublicInvariant { | ||
function invariant() public {} | ||
} | ||
|
||
contract ExternalInvariant { | ||
function invariant() external {} | ||
} | ||
|
||
contract PrivateInvariant { | ||
function invariant() private {} | ||
} | ||
|
||
contract InternalInvariant { | ||
function invariant() internal {} | ||
} |