Skip to content

Feat/jvd/hardhat plugin #15

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
wants to merge 33 commits into from
Closed

Feat/jvd/hardhat plugin #15

wants to merge 33 commits into from

Conversation

javadkh2
Copy link
Collaborator

@javadkh2 javadkh2 commented Feb 12, 2025

Created a hardhat plugin setups the hardhat chains and spins up them.
refactored the solidity test into a new folder based on the plugin.

@javadkh2 javadkh2 changed the base branch from main to lars/hardhat-network February 12, 2025 08:22
Copy link
Collaborator

@hswopeams hswopeams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks promising, but the plugin should be in its own repo. It needs to be installable in a project using npm install (or similar command, depending on package manager). Even the plugins provided by the Nomic Foundation itself have their own repos. The plugins are installed in each project. See solidity/package.json There are several plugins installed, such as @nomicfoundation/hardhat-chai-matchers, @nomicfoundation/hardhat-network-helpers, etc.

Also, please provide a README to show how it should be used. It's not celar to me.

@javadkh2
Copy link
Collaborator Author

This looks promising, but the plugin should be in its own repo. It needs to be installable in a project using npm install (or similar command, depending on package manager). Even the plugins provided by the Nomic Foundation itself have their own repos. The plugins are installed in each project. See solidity/package.json There are several plugins installed, such as @nomicfoundation/hardhat-chai-matchers, @nomicfoundation/hardhat-network-helpers, etc.

Also, please provide a README to show how it should be used. It's not celar to me.

Yes we will move this to a separate repo. But even in the current version the plugin is a separate npm package that can be already published
Also the solidity-example uses the plugin as an npm dependency

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file (and also SpvPrecompile.yul) provide system contracts that are installed in the hardhat network. The contracts are only needed for generating new byte code when something changes. It is therefore only relevant for the developers of the plugin. The role of these contracts should probably be documented.

So, I think, the yul code should be somewhere in the hardhat plugging package and not in the solidity-example.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on file ChainwebChainId.yul.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to add script for then to compile the contracts on each build.

@larskuhtz
Copy link
Collaborator

I am also wondering about the devnet-accounts file. In case of devnet and hardhat those are builtin. So, it's a bit odd that the user has to generate that. All this accounts are in a BIP-44 wallet (and the allocations folder in the demo repo contains the details along with code). So, it feels there is no ned to hardcode that in yet another separate file.

@hswopeams
Copy link
Collaborator

hswopeams commented Feb 14, 2025

I am also wondering about the devnet-accounts file. In case of devnet and hardhat those are builtin. So, it's a bit odd that the user has to generate that. All this accounts are in a BIP-44 wallet (and the allocations folder in the demo repo contains the details along with code). So, it feels there is no ned to hardcode that in yet another separate file.

You have to tell hardhat about the accounts if the network is not the hardhat network. You either have to specify the mnemonic and path in the hardhat config file, or you have to specify the accounts. By specifying the accounts in a file, the developer can see the addresses and private keys, which are needed for certain actions and sometimes debugging. It may not be needed in the new plugin paradigm, but it is needed in the current setup. The developer MUST be albe to see all accounts and their private keys somewhere.

@hswopeams
Copy link
Collaborator

It looks good. I updated the skipped integration tests to that they match what is in main in the solidity-example dir.

I noticed there are still a lot of switchNetwork calls in both test files. Are these supposed to be replaced with chainweb.switchChain?

@javadkh2
Copy link
Collaborator Author

I am also wondering about the devnet-accounts file. In case of devnet and hardhat those are builtin. So, it's a bit odd that the user has to generate that. All this accounts are in a BIP-44 wallet (and the allocations folder in the demo repo contains the details along with code). So, it feels there is no ned to hardcode that in yet another separate file.

I use default hardhat accounts when chainweb.accounts is not presented. So technically you don’t have to pass accounts

@hswopeams
Copy link
Collaborator

hswopeams commented Feb 18, 2025

I think we should also adjust the account and PK output to look more like a hardhat node would:

Account #0: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000 ETH)
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Account #1: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000 ETH)
Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d

Account #2: 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC (10000 ETH)
Private Key: 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
...

That way the devs can also see which private keys go with which accounts

Instead we see this for our devnet:
Accounts

Account #0: 0x8849BAbdDcfC1327Ad199877861B577cEBd8A7b6 (1000 ETH)

Account #1: 0xFB8Fb7f9bdc8951040a6D195764905138F7462Ed (1000 ETH)

Account #2: 0x28f2d8ef4e0fe6B2E945cF5C33a0118a30a62354 (1000 ETH)

Account #3: 0xa24a79678c9fffEF3E9A1f3cb7e51f88F173B3D5 (1000 ETH)

The amount is wrong. Each address actually starts with 1000000 ETH.

Above these we see

TEST_PROVIDER [
'0x8849babddcfc1327ad199877861b577cebd8a7b6',
'0xfb8fb7f9bdc8951040a6d195764905138f7462ed',
'0x28f2d8ef4e0fe6b2e945cf5c33a0118a30a62354',
'0xa24a79678c9fffef3e9a1f3cb7e51f88f173b3d5',
'0x47fae86f6416e6115a80635238afd2f18d69926b',
'0x87466a8266b9dfb3dc9180a9c43946c4ab2c2cb2',
'0xa310df9740eb6cc2f5e41c59c87e339142834ea4',
'0xd4eece51cf451b60f59b271c5a748a8a9f16bc01',
'0xe08643a1c4786b573d739625fd268732dbb3d033',
'0x33018a42499f10b54d9dbcebb71831c805d64ce3',
'0xa3659d39c901d5985450ee18a63b5b0811fda521',
'0x7e99c2f1731d3750b74a2a0623c1f1dcb8cca45e',
'0xfd70bef78778ce8554e79d97521b69183960c574',
'0xee2722c39db6014eacc5fbe43601136825b00977',
'0xd455842986f766c9e244105077a78b622ca6ccaa',
'0x99b832eb3f76ac3277b00beadc1e487c594ffb4c',
'0xda1380825f827c6ea92dfb547ef0a341cbe21d77',
'0xc201d4a5e6de676938533a0997802634e859e78b',
'0x03e95af0fc4971edca12e6d2d1540c28314d15d5',
'0x3492da004098d728201fd82657f1207a6e5426bd'
]
TEST_PROVIDER [
'0x8849babddcfc1327ad199877861b577cebd8a7b6',
'0xfb8fb7f9bdc8951040a6d195764905138f7462ed',
'0x28f2d8ef4e0fe6b2e945cf5c33a0118a30a62354',
'0xa24a79678c9fffef3e9a1f3cb7e51f88f173b3d5',
'0x47fae86f6416e6115a80635238afd2f18d69926b',
'0x87466a8266b9dfb3dc9180a9c43946c4ab2c2cb2',
'0xa310df9740eb6cc2f5e41c59c87e339142834ea4',
'0xd4eece51cf451b60f59b271c5a748a8a9f16bc01',
'0xe08643a1c4786b573d739625fd268732dbb3d033',
'0x33018a42499f10b54d9dbcebb71831c805d64ce3',
'0xa3659d39c901d5985450ee18a63b5b0811fda521',
'0x7e99c2f1731d3750b74a2a0623c1f1dcb8cca45e',
'0xfd70bef78778ce8554e79d97521b69183960c574',
'0xee2722c39db6014eacc5fbe43601136825b00977',
'0xd455842986f766c9e244105077a78b622ca6ccaa',
'0x99b832eb3f76ac3277b00beadc1e487c594ffb4c',
'0xda1380825f827c6ea92dfb547ef0a341cbe21d77',
'0xc201d4a5e6de676938533a0997802634e859e78b',
'0x03e95af0fc4971edca12e6d2d1540c28314d15d5',
'0x3492da004098d728201fd82657f1207a6e5426bd'
]

and above that:
[
{
privateKey: '0xe711c50150f500fdebec57e5c299518c2f7b36271c138c55759e5b4515dc7161',
balance: '1000000000000000000000'
},
{
privateKey: '0xb332ddc4e0801582e154d10cad8b672665656cbf0097f2b47483c0cfe3261299',
balance: '1000000000000000000000'
},
{
privateKey: '0x28536b3ec112d99faeceb6cfaccd4b2b920fcb7cd6689ed3b2f842142ce196cb',
balance: '1000000000000000000000'
},

It would be nice if everything could be displayed in one place with the correct amount, like the default hardhat.

… runs properly against internal and external hardhat networks
Copy link
Collaborator

@hswopeams hswopeams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log inside smart contracts works great.

);
}

/** @type import('hardhat/config').HardhatUserConfig */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed since this project isn't using typescript.

"@nomicfoundation/hardhat-verify": "^2.0.12",
"@nomicfoundation/ignition-core": "^0.15.9",
"@openzeppelin/contracts": "^5.2.0",
"@typechain/ethers-v6": "^0.5.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

References to typechain, types, typescript, etc can be removed since typescript is not being used in this project. This was also removed from the demo solidity dir in the main branch.

@hswopeams hswopeams closed this Feb 21, 2025
@hswopeams hswopeams reopened this Feb 21, 2025
@hswopeams
Copy link
Collaborator

Didn't mean to click on close PR. That was an accident.

@hswopeams
Copy link
Collaborator

hswopeams commented Feb 21, 2025

I am also wondering about the devnet-accounts file. In case of devnet and hardhat those are builtin. So, it's a bit odd that the user has to generate that. All this accounts are in a BIP-44 wallet (and the allocations folder in the demo repo contains the details along with code). So, it feels there is no ned to hardcode that in yet another separate file.

I use default hardhat accounts when chainweb.accounts is not presented. So technically you don’t have to pass accounts

For chainweb devnet, the accounts file is 100% necessary because otherwise hardhat has no way of knowing about chainweb devnet's accounts. If this plugin can "see" the default hardhat accounts, then the accounts file isn't needed. You don't even really need the hardhat network config in that case, unless you want to assign it a different chainId than it has by default.

@hswopeams hswopeams marked this pull request as draft February 21, 2025 15:59
@hswopeams
Copy link
Collaborator

Converted this PR to draft so that it doesn't accidentally get merged into main.

@larskuhtz larskuhtz changed the base branch from lars/hardhat-network to main February 21, 2025 18:00
@larskuhtz larskuhtz mentioned this pull request Feb 21, 2025
13 tasks
@javadkh2 javadkh2 force-pushed the feat/jvd/hardhat-plugin branch from 3a412b9 to 9280036 Compare February 24, 2025 10:00
@javadkh2
Copy link
Collaborator Author

javadkh2 commented Mar 3, 2025

Moved the plugin to its own repo https://github.com/kadena-io/hardhat-kadena-plugin

@javadkh2 javadkh2 closed this Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants