-
Notifications
You must be signed in to change notification settings - Fork 69
WIP Support hardhat-viem #167
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,24 @@ | ||
| pragma solidity ^0.5.1; | ||
|
|
||
| contract Greeter { | ||
| string public greeting; | ||
|
|
||
| constructor(string memory _greeting) public { | ||
| greeting = _greeting; | ||
| } | ||
|
|
||
| function greet() public view returns (string memory) { | ||
| return greeting; | ||
| } | ||
|
|
||
| function setGreeting(string memory _greeting) public { | ||
| greeting = _greeting; | ||
| } | ||
|
|
||
| function asOther() public {} | ||
|
|
||
| function throwAnError(string memory message) public { | ||
| greeting = "goodbye"; | ||
| require(false, message); | ||
| } | ||
| } |
This file contains hidden or 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,10 @@ | ||
| // We load the plugin here. | ||
| import { HardhatUserConfig } from "hardhat/types"; | ||
| import "../../src/index"; | ||
| import "@nomicfoundation/hardhat-viem"; | ||
|
|
||
| const config: HardhatUserConfig = { | ||
| solidity: "0.5.8", | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or 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,78 @@ | ||
| // @ts-nocheck | ||
| // tslint:disable-next-line no-implicit-dependencies | ||
| import { assert, expect, use } from "chai"; | ||
| import { loadFixture } from "@nomicfoundation/hardhat-toolbox-viem/network-helpers"; | ||
| import { viem } from "hardhat"; | ||
| import chaiAsPromised from "chai-as-promised"; | ||
|
|
||
| use(chaiAsPromised); | ||
|
|
||
| describe("Greeter contract", function() { | ||
| async function deployGreeterFixture() { | ||
| const publicClient = await viem.getPublicClient(); | ||
| const [owner, other] = await viem.getWalletClients(); | ||
|
|
||
| const deployGreeter = (args: [_greeting: string]) => viem.deployContract("Greeter", args); | ||
|
|
||
| const greeter = await deployGreeter(["Hi"]); | ||
|
|
||
| const greeterAsOther = await viem.getContractAt( | ||
| "Greeter", | ||
| greeter.address, | ||
| { walletClient: other } | ||
| ); | ||
|
|
||
| return { | ||
| publicClient, | ||
| owner, | ||
| other, | ||
| deployGreeter, | ||
| greeter, | ||
| greeterAsOther, | ||
| } | ||
| } | ||
|
|
||
| it("Should shoud be deployable with different greetings", async function() { | ||
| const { | ||
| greeter, | ||
| deployGreeter, | ||
| } = await loadFixture(deployGreeterFixture); | ||
| assert.equal(await greeter.read.greeting(), "Hi"); | ||
| const greeter2 = await deployGreeter(["Hola"]); | ||
| assert.equal(await greeter2.read.greeting(), "Hola"); | ||
| }); | ||
|
|
||
| it("Should return the greeting when greet is called", async function() { | ||
| const { | ||
| greeter, | ||
| } = await loadFixture(deployGreeterFixture); | ||
| assert.equal(await greeter.read.greet(), "Hi"); | ||
| }); | ||
|
|
||
| it("Should set a greeting", async function(){ | ||
| const { | ||
| greeter, | ||
| } = await loadFixture(deployGreeterFixture); | ||
| await greeter.write.setGreeting(['ciao']); | ||
| assert.equal(await greeter.read.greet(), "ciao"); | ||
| }) | ||
|
|
||
| it("Should call as other", async function(){ | ||
| // NOTE: This test is to check whether gas reporter can catch calls from viem using other accounts. | ||
| // The result should be checked manually on the gas usage table. | ||
| // Expected to see a row for `asOther` method. | ||
| const { | ||
| greeterAsOther, | ||
| } = await loadFixture(deployGreeterFixture); | ||
| await greeterAsOther.write.asOther(); | ||
| }) | ||
|
|
||
| it("should revert with a message", async function(){ | ||
| const { | ||
| greeterAsOther, | ||
| } = await loadFixture(deployGreeterFixture); | ||
| await expect( | ||
| greeterAsOther.write.throwAnError(['throwing...']) | ||
| ).to.eventually.be.rejectedWith('throwing...'); | ||
| }) | ||
| }); |
This file contains hidden or 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 { TASK_TEST } from "hardhat/builtin-tasks/task-names"; | ||
| // tslint:disable-next-line no-implicit-dependencies | ||
| import { assert } from "chai"; | ||
| import { useEnvironment } from "./helpers"; | ||
|
|
||
| describe("Viem plugin with signers", function() { | ||
| useEnvironment(__dirname + "/hardhat-viem-project"); | ||
|
|
||
| it("no options", async function() { | ||
| await this.env.run(TASK_TEST, { testFiles: [] }); | ||
| }); | ||
| }); | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This results in doubling the number of calls counted for both ethers and truffle plugins...ideally there would be a way to detect Viem and only select this route if it's being used.