6

The simplest way I'm aware of involves opening Test-RPC, making a Web3 instance, a contract, and then using it. That looks more complex than it should. Ideally, we should be able to do something like:

sm = require("solc-mock");

var contract = sm.mock(`
  pragma solidity ^0.4.11;
  contract Test {
    function add(uint x, uint y) constant returns (uint) {
      return x + y;
    }
  }
`);

console.log(contract.add("0x1", "0x2")); // output: 0x3
// also contract.add.send for txs

Is there any lib that would allow for some mocking as simple as this?

1

Update: I took a look at the source for remix and noticed they are using a nice library called ethereumjs-vm which implements the Ethereum VM in JavaScript. You can use this to mock your tests programatically.


Original Answer: The closest you can get without touching RPC is the Javascript VM provided by Remix. Here's a screenshot I took running your code using just the in-browser VM provided by Remix:

Remix Javascript VM

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.