forked from chainskills/chainlist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
}); | ||
}); | ||
}); |