How to use @nomiclabs/ethereumjs-vm - 6 common examples

To help you get started, we’ve selected a few @nomiclabs/ethereumjs-vm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethereum-optimism / optimism / packages / smock / src / smockit / binding.ts View on Github external
const mock: MockContract = vm._smockState.mocks[target]
    const {
      resolve,
      functionName,
      rawReturnValue,
      returnValue,
      gasUsed,
    } = await mock._smockit(message.data)

    // Set the mock return data, potentially set the `exceptionError` field if the user requested
    // a revert.
    result.gasUsed = new BN(gasUsed)
    result.execResult.returnValue = returnValue
    result.execResult.gasUsed = new BN(gasUsed)
    result.execResult.exceptionError =
      resolve === 'revert' ? new VmError('smocked revert' as any) : undefined
  })
github nomiclabs / buidler / packages / buidler-core / src / internal / buidler-evm / provider / node.ts View on Github external
nonce: "0x42",
          extraData: "0x1234",
          stateRoot: bufferToHex(stateTrie.root)
        }
      },
      hardfork
    );

    const stateManager = new StateManager({
      common: common as any, // TS error because of a version mismatch
      trie: stateTrie
    });

    const blockchain = new Blockchain();

    const vm = new VM({
      common: common as any, // TS error because of a version mismatch
      activatePrecompiles: true,
      stateManager,
      blockchain: blockchain as any
    });

    const genesisBlock = new Block(null, { common });
    genesisBlock.setGenesisParams();

    await new Promise(resolve => {
      blockchain.putBlock(genesisBlock, () => resolve());
    });

    const node = new BuidlerNode(
      vm,
      genesisAccounts.map(acc => toBuffer(acc.privateKey)),
github nomiclabs / buidler / packages / buidler-core / src / internal / buidler-evm / provider / node.ts View on Github external
networkId,
        name: networkName,
        genesis: {
          timestamp: `0x${getCurrentTimestamp().toString(16)}`,
          hash: "0x",
          gasLimit: blockGasLimit,
          difficulty: 1,
          nonce: "0x42",
          extraData: "0x1234",
          stateRoot: bufferToHex(stateTrie.root)
        }
      },
      hardfork
    );

    const stateManager = new StateManager({
      common: common as any, // TS error because of a version mismatch
      trie: stateTrie
    });

    const blockchain = new Blockchain();

    const vm = new VM({
      common: common as any, // TS error because of a version mismatch
      activatePrecompiles: true,
      stateManager,
      blockchain: blockchain as any
    });

    const genesisBlock = new Block(null, { common });
    genesisBlock.setGenesisParams();
github nomiclabs / buidler / packages / buidler-core / src / internal / buidler-evm / provider / node.ts View on Github external
private constructor(
    private readonly _vm: VM,
    localAccounts: Buffer[],
    private readonly _blockGasLimit: BN,
    genesisBlock: Block,
    private readonly _throwOnTransactionFailures: boolean,
    private readonly _throwOnCallFailures: boolean,
    stackTracesOptions?: SolidityTracerOptions
  ) {
    const config = getUserConfigPath();
    this._stateManager = new PStateManager(this._vm.stateManager);
    this._common = this._vm._common as any; // TODO: There's a version mismatch, that's why we cast
    this._initLocalAccounts(localAccounts);

    this._blockHashToTotalDifficulty.set(
      bufferToHex(genesisBlock.hash()),
      this._computeTotalDifficulty(genesisBlock)
    );

    this._getLatestBlock = promisify(
      this._vm.blockchain.getLatestBlock.bind(this._vm.blockchain)
    );

    this._getBlock = promisify(
      this._vm.blockchain.getBlock.bind(this._vm.blockchain)
    );
github nomiclabs / buidler / packages / buidler-core / src / internal / buidler-evm / provider / node.ts View on Github external
messageTrace
        );

        stackTrace = this._solidityTracer!.getStackTrace(decodedTrace);
      } catch (error) {
        this._failedStackTraces += 1;
        log(
          "Could not generate stack trace. Please report this to help us improve Buidler.\n",
          error
        );
      }
    }

    const error = vmResult.exceptionError;

    if (error.error === ERROR.OUT_OF_GAS) {
      return new TransactionExecutionError("Transaction run out of gas");
    }

    if (error.error === ERROR.REVERT) {
      if (vmResult.returnValue.length === 0) {
        if (stackTrace !== undefined) {
          return encodeSolidityStackTrace(
            "Transaction reverted without a reason",
            stackTrace
          );
        }

        return new TransactionExecutionError(
          "Transaction reverted without a reason"
        );
      }
github nomiclabs / buidler / packages / buidler-core / src / internal / buidler-evm / provider / node.ts View on Github external
} catch (error) {
        this._failedStackTraces += 1;
        log(
          "Could not generate stack trace. Please report this to help us improve Buidler.\n",
          error
        );
      }
    }

    const error = vmResult.exceptionError;

    if (error.error === ERROR.OUT_OF_GAS) {
      return new TransactionExecutionError("Transaction run out of gas");
    }

    if (error.error === ERROR.REVERT) {
      if (vmResult.returnValue.length === 0) {
        if (stackTrace !== undefined) {
          return encodeSolidityStackTrace(
            "Transaction reverted without a reason",
            stackTrace
          );
        }

        return new TransactionExecutionError(
          "Transaction reverted without a reason"
        );
      }

      if (stackTrace !== undefined) {
        return encodeSolidityStackTrace(
          `VM Exception while processing transaction: revert ${decodeRevertReason(