Skip to content

Commit 5f60093

Browse files
saeta-ethtmm
andauthored
feat: add support for evm_setAccountCode (#2636)
* 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 <[email protected]>
1 parent 8e1b3c9 commit 5f60093

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

.changeset/wet-wasps-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"viem": patch
3+
---
4+
5+
Added support for `'evm_setAccountCode'` to `setCode` action.

src/actions/test/setCode.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ export async function setCode<
5050
client: TestClient<TestClientMode, Transport, chain, account, false>,
5151
{ address, bytecode }: SetCodeParameters,
5252
) {
53-
await client.request({
54-
method: `${client.mode}_setCode`,
55-
params: [address, bytecode],
56-
})
53+
if (client.mode === 'ganache')
54+
await client.request({
55+
method: 'evm_setAccountCode',
56+
params: [address, bytecode],
57+
})
58+
else
59+
await client.request({
60+
method: `${client.mode}_setCode`,
61+
params: [address, bytecode],
62+
})
5763
}

src/types/eip1193.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ export type TestRpcSchema<mode extends string> = [
13351335
* @link https://ganache.dev/#evm_setAccountBalance
13361336
*/
13371337
{
1338-
Method: `evm_setAccountBalance`
1338+
Method: 'evm_setAccountBalance'
13391339
Parameters: [
13401340
/** The address of the target account. */
13411341
address: Address,
@@ -1344,12 +1344,26 @@ export type TestRpcSchema<mode extends string> = [
13441344
]
13451345
ReturnType: void
13461346
},
1347+
/**
1348+
* @description Modifies the bytecode stored at an account's address.
1349+
* @link https://ganache.dev/#evm_setAccountCode
1350+
*/
1351+
{
1352+
Method: 'evm_setAccountCode'
1353+
Parameters: [
1354+
/** The address of the contract. */
1355+
address: Address,
1356+
/** Data bytecode. */
1357+
data: string,
1358+
]
1359+
ReturnType: void
1360+
},
13471361
/**
13481362
* @description Enables or disables, based on the single boolean argument, the automatic mining of new blocks with each new transaction submitted to the network.
13491363
* @link https://hardhat.org/hardhat-network/docs/reference#evm_setautomine
13501364
*/
13511365
{
1352-
Method: `evm_setAutomine`
1366+
Method: 'evm_setAutomine'
13531367
Parameters: [boolean]
13541368
ReturnType: void
13551369
},
@@ -1367,7 +1381,7 @@ export type TestRpcSchema<mode extends string> = [
13671381
* @link https://github.com/trufflesuite/ganache/blob/ef1858d5d6f27e4baeb75cccd57fb3dc77a45ae8/src/chains/ethereum/ethereum/RPC-METHODS.md#evm_increasetime
13681382
*/
13691383
{
1370-
Method: `evm_increaseTime`
1384+
Method: 'evm_increaseTime'
13711385
Parameters: [seconds: Quantity]
13721386
ReturnType: Quantity
13731387
},

0 commit comments

Comments
 (0)