Bug fixes And add Unit Test

This commit is contained in:
MrDev023 2018-02-01 12:49:21 +01:00
parent a4e84eff45
commit 5caf069681
5 changed files with 5862 additions and 3 deletions

3
.gitignore vendored
View file

@ -2,4 +2,5 @@ data/*
node_modules/*
*.json
bin/*
build/*
build/*
!package*.json

View file

@ -3,11 +3,16 @@ pragma solidity ^0.4.4;
contract HelloEthSalon {
string message = "I know smart contract testing!!";
function HelloEthSalon() {
function HelloEthSalon() public {
// constructor
}
function GetMessage() returns (string) {
function SetMessage(string m) public {
require(bytes(m).length > 0);
message = m;
}
function GetMessage() public returns (string) {
return message;
}
}

5805
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

31
package.json Normal file
View file

@ -0,0 +1,31 @@
{
"name": "eth_projet",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start_rpc": "testrpc",
"start_test": "npm run clean && truffle compile && truffle migrate && truffle test",
"test": "concurrently --names 'RPC,TEST' --kill-others \"npm run start_rpc\" \"npm run start_test\" || true",
"clean": "rm -rf build"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/MrDev023/ETH_PROJET.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gitlab.com/MrDev023/ETH_PROJET/issues"
},
"homepage": "https://gitlab.com/MrDev023/ETH_PROJET#README",
"devDependencies": {
"concurrently": "^3.5.1",
"ethereumjs-testrpc": "^6.0.3",
"fs": "0.0.1-security",
"geth": "^0.4.0",
"solc": "^0.4.19",
"truffle": "^4.0.6",
"web3": "^1.0.0-beta.29"
}
}

View file

@ -6,4 +6,21 @@ contract("HelloEthSalon:GetMessage", function (accounts) {
const result = await contract.GetMessage.call();
assert.isTrue(result === "I know smart contract testing!!");
});
});
contract("HelloEthSalon:SetMessage", function (accounts) {
it("should not set a empty string", async function () {
const contract = await HelloEthSalon.deployed();
var ret = false;
try{const result = await contract.SetMessage.call("");}catch (e){ret = true;}
assert.isTrue(ret);
});
it("should set to test", async function () {
const contract = await HelloEthSalon.deployed();
var ret = false;
try{const result = await contract.SetMessage.call("test");}catch (e){ret = true;}
assert.isTrue(!ret,"Erreur de transaction"); // Pas d'erreur de transaction
});
});