When making tests with truffle test
you can request for deploying contract in the testfile Here is an example of a series of tests i wrote to give an example :
var Organizations = artifacts.require("./Organizations.sol");
// Deploy an instance of the contract
contract('Organizations',function(accounts){
it("Owner on deployment should be : " + accounts[0],function(){
return Organizations.new("GroupTest",accounts[0],{from : accounts[0], gas : '2500000'}).then(function(inst){
return inst.owner();
}).then(function(r){
assert.equal(r,accounts[0],"Owner is not : " + accounts[0]);
});
});
// Check data keeps coherence : TODO
it("Users should be able to request membership",function(){
return Organizations.new("GroupTest",accounts[0],{from : accounts[0], gas : '2500000'}).then(function(inst){
return inst.requestMembership({from: accounts[1], gas : 150000}).then(function(){
return inst.membershipRequests(accounts[1]);
}).then(function(r){
assert.equal(r,true,"User hasn\'t been registered in membership request registry");
});
});
});
Aknowledging the following parts of the contract :
contract Organizations{
string public name;
address public owner;
mapping(address => bool) public membershipRequests;
function Organizations(string _name, address _owner){
owner = _owner;
name = _name;
}
function requestMembership() returns(bool success){
membershipRequests[msg.sender] = true;
return true;
}
}