Coder Social home page Coder Social logo

solidity-test-adapter's Introduction

What is it?

It is a small utility that glues smart-contracts in solidity language and your favorite testing framework. This utility taking care of compiling and deploying them to the ethreumjs-testrpc blockchain emulator.

Originally it was designed to work with mocha testing framework.

How to write tests?

Same way you usually do. Just specify before hook with the setup you want. Here is mocha example:

    var config = {
      'MyTest': {
        args: [ 1 ],
        instanceOf: 'Test',
        gas: 4e6,
      },
    }

    before(done => setup.config.call(this, config, done))

In your tests you can do something like

  MyTest.myMethod(arg1, arg2, { gas: 4e6, from: testWallets[7] }, (e, r) => console.log(e, r) )

Config

The syntax for config was inpired by embark framework.

'DeployedContractName': {  // name of variable to store contract - (1)
  args: [ 1 ],             // constructor arguments
  instanceOf: 'Test',      // contract class name, by default equals to (1)
  gas: 4e6,                // gas amount, default is in the file `config.json`
  from: testWallets[1]     // address of a contract that sendds request, `testWallets[0]` by defalut
}

Variables

Apart from contracts deployed according to whatever you've deployed in setup.config, there is a set of global variables available for your convenience:

  • global.web3 -- Web3 instance
  • global.contracts -- compiler output (ABI, bytecode, etc)
  • global.testWallets -- an array with 10 unlocked contracts with non-zero balance

How to run tests?

Depends on your framework. To run example shipped with the utility try

    > mocha example-test.js --no-timeouts
    ...

solidity-test-adapter's People

Contributors

bbrh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.