Git Product home page Git Product logo

testing-oraclize's Introduction

Testing Oraclize with Truffle

This repo is an example of how to write and test a contract that utilizes Oraclize on a private network locally. This is intended to serve as a fully integrated starting point for developers that wish to leverage the Oraclize service.

Quick Start

  1. Clone Me and Install Dependencies

Note the recursive flag as the ethereum-bridge is a submodule

$ git clone --recursive https://github.com/AdamJLemmon/testing-oraclize.git
$ cd testing-oraclize/ethereum-bridge && npm install && cd ..
  1. Start your local client

In another terminal window. We are using testrpc here but any other client is also supported. The remainder of this document assumes the client is running at localhost:8545

Your client, testrpc here, should be configured to use a static set of account addresses, as the bridge will be dependent upon a specified address for deploying its required contracts on your private chain. Therefore if you want those addresses to stay constant, between testrpc runs, you should be running testrpc with some re-usable addresses. You can do this by adding the --mnemonic flag when starting it, and using the same mnemonic phrase over when restarting testrpc, to ensure it generates the same Oraclize OAR (OraclizeAddressResolver), which you will need to use in the next step.

Start testrpc using a specific mnemonic phrase, and take note of the index of the last available account, (you can use any for this, but I recommend the last one, as it's an account that shouldn't be used in tests, also make sure enough other accounts were generated for you to be able to do tests using).

Since 50 accounts are generated, the last address' index is 49.

$ testrpc --mnemonic testingOraclize --accounts 50
  1. Start the bridge

In a separate terminal window.

Node version < 7.0.0 is required. NVM provides an excellent interface to manage several versions of node. Install nvm and switch to node version 6.9.1.

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash

Confirm the install was successful.

$ command -v nvm
nvm

If you do not see nvm output then simply close and re-open your terminal window. If this does not work then refer to the nvm link above for further instructions.

$ nvm install 6.9.1
$ nvm use 6.9.1

Now start the bridge. Note specifying account 49.

testing-oraclize $ cd ethereum-bridge
ethereum-bridge $ node bridge -a 49

Once the bridge has booted up successfully you should see the following output:

Please add this line to your contract constructor:

OAR = OraclizeAddrResolverI(0x145437eac36aeacee0c135c9015fff316ba938ed);

Update /contracts/TestingOraclize#L25 with the above line. Now as long as the same mnemonic is used when starting your client and the same account when starting the bridge than this line will not need to be changed. (Do remember to remove the OAR variable from your constructor before production, this is just for testing, in production it will automatically fetch the OAR depending on the chain you're running it, currently the Mainnet, Ropsten, and browser-solidity VM environment are supported.)

  1. Execute the contract test suite

Don't forget to switch your node version back first.

testing-oraclize $ nvm use 8.0.0
testing-oraclize $ truffle test

And you are able to query the Kraken web api from your smart contract utilizing a local chain!

testing-oraclize's People

Contributors

adamjlemmon 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.