Skip to content

Commit

Permalink
feat: add support for evm_setAccountCode (#2636)
Browse files Browse the repository at this point in the history
* add evm_setAccountCode to rpc schema

* add evm_setAccountCode to rpc schema

* revert pnpm-lock.yaml

* add changeset

* chore: tweaks

---------

Co-authored-by: Tom Meagher <tom@meagher.co>
  • Loading branch information
saeta-eth and tmm committed Aug 20, 2024
1 parent 8e1b3c9 commit 5f60093
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-wasps-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Added support for `'evm_setAccountCode'` to `setCode` action.
14 changes: 10 additions & 4 deletions src/actions/test/setCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ export async function setCode<
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ address, bytecode }: SetCodeParameters,
) {
await client.request({
method: `${client.mode}_setCode`,
params: [address, bytecode],
})
if (client.mode === 'ganache')
await client.request({
method: 'evm_setAccountCode',
params: [address, bytecode],
})
else
await client.request({
method: `${client.mode}_setCode`,
params: [address, bytecode],
})
}
20 changes: 17 additions & 3 deletions src/types/eip1193.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ export type TestRpcSchema<mode extends string> = [
* @link https://ganache.dev/#evm_setAccountBalance
*/
{
Method: `evm_setAccountBalance`
Method: 'evm_setAccountBalance'
Parameters: [
/** The address of the target account. */
address: Address,
Expand All @@ -1344,12 +1344,26 @@ export type TestRpcSchema<mode extends string> = [
]
ReturnType: void
},
/**
* @description Modifies the bytecode stored at an account's address.
* @link https://ganache.dev/#evm_setAccountCode
*/
{
Method: 'evm_setAccountCode'
Parameters: [
/** The address of the contract. */
address: Address,
/** Data bytecode. */
data: string,
]
ReturnType: void
},
/**
* @description Enables or disables, based on the single boolean argument, the automatic mining of new blocks with each new transaction submitted to the network.
* @link https://hardhat.org/hardhat-network/docs/reference#evm_setautomine
*/
{
Method: `evm_setAutomine`
Method: 'evm_setAutomine'
Parameters: [boolean]
ReturnType: void
},
Expand All @@ -1367,7 +1381,7 @@ export type TestRpcSchema<mode extends string> = [
* @link https://github.com/trufflesuite/ganache/blob/ef1858d5d6f27e4baeb75cccd57fb3dc77a45ae8/src/chains/ethereum/ethereum/RPC-METHODS.md#evm_increasetime
*/
{
Method: `evm_increaseTime`
Method: 'evm_increaseTime'
Parameters: [seconds: Quantity]
ReturnType: Quantity
},
Expand Down

0 comments on commit 5f60093

Please sign in to comment.