-
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.
Add a _node property to the provider, which in turn has a _vm property with an object that works as a partial implementation of ethereumjs vm we used to have. More specifically: it supports evm events and some statemanager methods. We are doing this to prevent plugins like solidity-coverage from breaking with the EDR refactor.
- Loading branch information
Showing
5 changed files
with
190 additions
and
155 deletions.
There are no files selected for viewing
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
101 changes: 101 additions & 0 deletions
101
packages/hardhat-core/src/internal/hardhat-network/provider/vm/minimal-vm.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,101 @@ | ||
import type { Provider as EdrProviderT } from "@ignored/edr"; | ||
import type { Address } from "@nomicfoundation/ethereumjs-util"; | ||
import type { | ||
MinimalEVMResult, | ||
MinimalInterpreterStep, | ||
MinimalMessage, | ||
} from "./types"; | ||
|
||
import { AsyncEventEmitter } from "@nomicfoundation/ethereumjs-util"; | ||
|
||
/** | ||
* Used by the provider to keep the `_vm` variable used by some plugins. This | ||
* interface only has the things used by those plugins. | ||
*/ | ||
export interface MinimalEthereumJsVm { | ||
evm: { | ||
events: AsyncEventEmitter<MinimalEthereumJsVmEvents>; | ||
}; | ||
stateManager: { | ||
putContractCode: (address: Address, code: Buffer) => Promise<void>; | ||
getContractStorage: (address: Address, slotHash: Buffer) => Promise<Buffer>; | ||
putContractStorage: ( | ||
address: Address, | ||
slotHash: Buffer, | ||
slotValue: Buffer | ||
) => Promise<void>; | ||
}; | ||
} | ||
|
||
// we need to use a type instead of an interface to satisfy the type constarint | ||
// of the AsyncEventEmitter type param | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
type MinimalEthereumJsVmEvents = { | ||
beforeMessage: ( | ||
data: MinimalMessage, | ||
resolve?: (result?: any) => void | ||
) => void; | ||
afterMessage: ( | ||
data: MinimalEVMResult, | ||
resolve?: (result?: any) => void | ||
) => void; | ||
step: ( | ||
data: MinimalInterpreterStep, | ||
resolve?: (result?: any) => void | ||
) => void; | ||
}; | ||
|
||
export class MinimalEthereumJsVmEventEmitter extends AsyncEventEmitter<MinimalEthereumJsVmEvents> {} | ||
|
||
export function getMinimalEthereumJsVm( | ||
provider: EdrProviderT | ||
): MinimalEthereumJsVm { | ||
const minimalEthereumJsVm: MinimalEthereumJsVm = { | ||
evm: { | ||
events: new MinimalEthereumJsVmEventEmitter(), | ||
}, | ||
stateManager: { | ||
putContractCode: async (address: Address, code: Buffer) => { | ||
await provider.handleRequest( | ||
JSON.stringify({ | ||
method: "hardhat_setCode", | ||
params: [`0x${address.toString()}`, `0x${code.toString("hex")}`], | ||
}) | ||
); | ||
}, | ||
getContractStorage: async (address: Address, slotHash: Buffer) => { | ||
const responseObject = await provider.handleRequest( | ||
JSON.stringify({ | ||
method: "eth_getStorageAt", | ||
params: [ | ||
`0x${address.toString()}`, | ||
`0x${slotHash.toString("hex")}`, | ||
], | ||
}) | ||
); | ||
|
||
const response = JSON.parse(responseObject.json); | ||
|
||
return Buffer.from(response.result.slice(2), "hex"); | ||
}, | ||
putContractStorage: async ( | ||
address: Address, | ||
slotHash: Buffer, | ||
slotValue: Buffer | ||
) => { | ||
await provider.handleRequest( | ||
JSON.stringify({ | ||
method: "hardhat_setStorageAt", | ||
params: [ | ||
`0x${address.toString()}`, | ||
`0x${slotHash.toString("hex")}`, | ||
`0x${slotValue.toString("hex")}`, | ||
], | ||
}) | ||
); | ||
}, | ||
}, | ||
}; | ||
|
||
return minimalEthereumJsVm; | ||
} |
123 changes: 0 additions & 123 deletions
123
packages/hardhat-core/src/internal/hardhat-network/provider/vm/proxy-vm.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.