From 4ff42d8913851090913b1448eadf246a739b6d04 Mon Sep 17 00:00:00 2001 From: Matt Gucci Date: Sat, 18 Aug 2018 23:48:22 +0900 Subject: [PATCH 1/4] Suppress warnings about events without "emit" When I first start the Remix IDE, the following warnings are shown in the Compile tab. ``` remix_tests.sol:13:5: Warning: Invoking events without "emit" prefix is deprecated. AssertionEvent(result, message); ^-----------------------------^ ``` To avoid this, add `emit` in front. --- sol/tests.sol.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/sol/tests.sol.js b/sol/tests.sol.js index 2fa6821bbe..8cc903f86f 100644 --- a/sol/tests.sol.js +++ b/sol/tests.sol.js @@ -10,93 +10,93 @@ library Assert { function ok(bool a, string message) public returns (bool result) { result = a; - AssertionEvent(result, message); + emit AssertionEvent(result, message); } function equal(uint a, uint b, string message) public returns (bool result) { result = (a == b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } function equal(int a, int b, string message) public returns (bool result) { result = (a == b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } function equal(bool a, bool b, string message) public returns (bool result) { result = (a == b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } // TODO: only for certain versions of solc //function equal(fixed a, fixed b, string message) public returns (bool result) { // result = (a == b); - // AssertionEvent(result, message); + // emit AssertionEvent(result, message); //} // TODO: only for certain versions of solc //function equal(ufixed a, ufixed b, string message) public returns (bool result) { // result = (a == b); - // AssertionEvent(result, message); + // emit AssertionEvent(result, message); //} function equal(address a, address b, string message) public returns (bool result) { result = (a == b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } function equal(bytes32 a, bytes32 b, string message) public returns (bool result) { result = (a == b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } // TODO: needs to be convert to bytes first to be comparable //function equal(string a, string b, string message) public returns (bool result) { // result = (a == b); - // AssertionEvent(result, message); + // emit AssertionEvent(result, message); //} function notEqual(uint a, uint b, string message) public returns (bool result) { result = (a != b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } function notEqual(int a, int b, string message) public returns (bool result) { result = (a != b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } function notEqual(bool a, bool b, string message) public returns (bool result) { result = (a != b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } // TODO: only for certain versions of solc //function notEqual(fixed a, fixed b, string message) public returns (bool result) { // result = (a != b); - // AssertionEvent(result, message); + // emit AssertionEvent(result, message); //} // TODO: only for certain versions of solc //function notEqual(ufixed a, ufixed b, string message) public returns (bool result) { // result = (a != b); - // AssertionEvent(result, message); + // emit AssertionEvent(result, message); //} function notEqual(address a, address b, string message) public returns (bool result) { result = (a != b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } function notEqual(bytes32 a, bytes32 b, string message) public returns (bool result) { result = (a != b); - AssertionEvent(result, message); + emit AssertionEvent(result, message); } // TODO: needs to be convert to bytes first to be comparable //function notEqual(string a, string b, string message) public returns (bool result) { // result = (a != b); - // AssertionEvent(result, message); + // emit AssertionEvent(result, message); //} } From 59d9931c7cb0db4dc7eff78874194ed5ca7d985f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 21 Aug 2018 13:31:14 -0400 Subject: [PATCH 2/4] update readme --- README.md | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 36bb5d4901..25e83a72b0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,107 @@ [![Build Status](https://travis-ci.org/ethereum/remix-tests.svg?branch=master)](https://travis-ci.org/ethereum/remix-tests) -# remix-tests +Remix-Tests +--- + +### Installation + +`npm -g install remix-tests` + +### Test structure + +Example test file: +```Javascript +pragma solidity ^0.4.7; +import "remix_tests.sol"; // injected by remix-tests +import "./simple_storage.sol"; + +contract MyTest { + SimpleStorage foo; + uint i = 0; + + function beforeAll() { + foo = new SimpleStorage(); + } + + function beforeEach() { + if (i == 1) { + foo.set(200); + } + i += 1; + } + + function initialValueShouldBe100() public { + Assert.equal(foo.get(), 100, "initial value is not correct"); + } + + function initialValueShouldBe200() public constant returns { + return Assert.equal(foo.get(), 200, "initial value is not correct"); + } + +} +``` + +Available special functions: +* `beforeEach` - runs before each test +* `beforeAll` - runs before all tests + +#### Assert library + +Available functions: +`Assert.ok(value, message)` +`Assert.equal(value1, value2, message)` +`Assert.notEqual(value1, value2, message)` + +supported values currently are: `bool` `uint` `int` `address` `bytes32` + +### Command Line + +Usage: + +* A directory with tests files `remix-tests examples/` +* A test file `remix-tests examples/simple_storage_test.sol` + +### Library + +Importing the library: +```Javascript +const RemixTests = require('remix-tests'); +``` + +Running a single test object: +```Javascript +remixTests.runTest(contractName, contractObj, testCallback, resultsCallback) +``` +params: +`testName` - `string` name of the test +`testObj` - web3.js 1.0 contract instance of the test +`testCallback(object)` - called each time there is a test event. 3 possible type of objects: +* `{ type: 'contract', value: '', filename: '' }` +* `{ type: 'testPass', value: '', time: