Merge pull request #22 from 0mkara/string-test

Assert library string comparison
pull/7/head
Iuri Matias 6 years ago committed by GitHub
commit b068d9844b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6981
      package-lock.json
  2. 2
      package.json
  3. 18
      sol/tests.sol.js
  4. 12
      tests/examples_3/simple_string.sol
  5. 23
      tests/examples_3/simple_string_test.sol
  6. 39
      tests/testRunner.js

6981
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -42,7 +42,7 @@
"colors": "^1.1.2",
"commander": "^2.13.0",
"remix-simulator": "latest",
"remix-solidity": "latest",
"remix-solidity": "^0.2.2",
"solc": "^0.4.24",
"standard": "^10.0.3",
"web3": "1.0.0-beta.27"

@ -50,11 +50,10 @@ library Assert {
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);
// emit AssertionEvent(result, message);
//}
function equal(string a, string b, string message) public returns (bool result) {
result = (keccak256(a) == keccak256(b));
AssertionEvent(result, message);
}
function notEqual(uint a, uint b, string message) public returns (bool result) {
result = (a != b);
@ -93,11 +92,10 @@ library Assert {
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);
// emit AssertionEvent(result, message);
//}
function notEqual(string a, string b, string message) public returns (bool result) {
result = (keccak256(a) != keccak256(b));
AssertionEvent(result, message);
}
}
`

@ -0,0 +1,12 @@
pragma solidity ^0.4.7;
contract SimpleString {
string public storedData;
function SimpleString() public {
storedData = "Hello world!";
}
function get() public view returns (string retVal) {
return storedData;
}
}

@ -0,0 +1,23 @@
pragma solidity ^0.4.7;
import "./tests.sol";
import "./simple_string.sol";
contract StringTest {
SimpleString foo;
function beforeAll() {
foo = new SimpleString();
}
function initialValueShouldBeHello() public constant returns (bool) {
return Assert.equal(foo.get(), "Hello world!", "initial value is not correct");
}
function valueShouldNotBeHelloWorld() public constant returns (bool) {
return Assert.notEqual(foo.get(), "Hello wordl!", "initial value is not correct");
}
function valueShouldBeHelloWorld() public constant returns (bool) {
return Assert.equal(foo.get(), "Hello wordl!", "initial value is not correct");
}
}

@ -50,7 +50,7 @@ describe('testRunner', function () {
assert.equal(results.failureNum, 2)
})
it('should returns 3 messages', function () {
it('should returns 5 messages', function () {
assert.deepEqual(tests, [
{ type: 'contract', value: 'MyTest', filename: 'simple_storage_test.sol' },
{ type: 'testFailure', value: 'Should trigger one fail', time: 1, context: 'MyTest', errMsg: 'the test 1 fails' },
@ -94,5 +94,42 @@ describe('testRunner', function () {
])
})
})
// Test string comparision
describe('test with beforeAll', function () {
let filename = 'tests/examples_3/simple_string_test.sol'
let tests = [], results = {}
before(function (done) {
compileAndDeploy(filename, function (_err, contracts) {
var testCallback = function (test) {
tests.push(test)
}
var resultsCallback = function (_err, _results) {
results = _results
done()
}
TestRunner.runTest('StringTest', contracts.StringTest, testCallback, resultsCallback)
TestRunner.runTest('StringTest2', contracts.StringTest2, testCallback, resultsCallback)
})
})
it('should 2 passing tests', function () {
assert.equal(results.passingNum, 2)
})
it('should 1 failing tests', function () {
assert.equal(results.failureNum, 1)
})
it('should returns 3 messages', function () {
assert.deepEqual(tests, [
{ type: 'contract', value: 'StringTest', filename: 'simple_string_test.sol' },
{ type: 'testFailure', value: 'Value should be hello world', time: 1, context: 'StringTest', "errMsg": "function returned false" },
{ type: 'testPass', value: 'Value should not be hello world', time: 1, context: 'StringTest' },
{ type: 'testPass', value: 'Initial value should be hello', time: 1, context: 'StringTest' },
])
})
})
})
})

Loading…
Cancel
Save