Skip to content

Commit

Permalink
Added test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbogast committed Aug 14, 2017
1 parent 1fc6204 commit f9296cd
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/ChainListHappyPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Contract to be tested
var ChainList = artifacts.require("./ChainList.sol");

// Test suite
contract('ChainList', function(accounts) {
var chainListInstance;
var seller = accounts[1];
var articleName = "article 1";
var articleDescription = "Description for article 1";
var articlePrice = 10;

// Test case: check initial values
it("should be initialized with empty values", function() {
return ChainList.deployed().then(function(instance) {
return instance.getArticle.call();
}).then(function(data) {
assert.equal(data[0], 0x0, "seller must be empty");
assert.equal(data[1], '', "article name must be empty");
assert.equal(data[2], '', "description must be empty");
assert.equal(data[3].toNumber(), 0, "article price must be zero");
});
});

// Test case: sell an article
it("should sell an article", function() {
return ChainList.deployed().then(function(instance) {
chainListInstance = instance;
return chainListInstance.sellArticle(articleName, articleDescription, web3.toWei(articlePrice, "ether"), {
from: seller
});
}).then(function() {
return chainListInstance.getArticle.call();
}).then(function(data) {
assert.equal(data[0], seller, "seller must be " + seller);
assert.equal(data[1], articleName, "article name must be " + articleName);
assert.equal(data[2], articleDescription, "article descriptio must be " + articleDescription);
assert.equal(data[3].toNumber(), web3.toWei(articlePrice, "ether"), "article price must be " + web3.toWei(articlePrice, "ether"));
});
});
});

0 comments on commit f9296cd

Please sign in to comment.