Skip to content

Commit

Permalink
js tests added, slight contract changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Zoghb committed Sep 29, 2017
1 parent 368bf1b commit d16ab1d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 32 deletions.
28 changes: 14 additions & 14 deletions ex1/test/greeterTest.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
var Greeter = artifacts.require("./Greeter.sol");

contract('Greeter', function(accounts) {
/* In general, it is not good practice to hard-code test values */
const args = {_greeting: "Hello, World!"};
it("Should use the Greeter constructor to set a greeting", function() {
/* Constructor arguement already sent in `migrations/2_deploy_greeter.js` */
return Greeter.deployed()
.then(function(instance) {
/* Call the greet function */
return instance.greet.call();
})
.then(function(result) {
assert.equal(args._greeting, result, `Greeter constructor greeting
and test value do not match`)
})
});
/* In general, it is not good practice to hard-code test values */
const args = {_greeting: "Hello, World!"};
it("Should use the Greeter constructor to set a greeting", function() {
/* Constructor arguement already sent in `migrations/2_deploy_greeter.js` */
return Greeter.deployed()
.then(function(instance) {
/* Call the greet function */
return instance.greet.call();
})
.then(function(result) {
assert.equal(args._greeting, result, "Greeter constructor " +
"greeting and test value do not match")
});
});
});
2 changes: 1 addition & 1 deletion ex2/contracts/Betting_skeleton.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity ^0.4.15;

contract Betting {
/* Standard state variables */
address owner;
address public owner;
address public gamblerA;
address public gamblerB;
address public oracle;
Expand Down
2 changes: 1 addition & 1 deletion ex2/migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ var Betting = artifacts.require("./Betting.sol");

module.exports = function(deployer) {
/* Input value to constructor on contract deployment */
var testOutcomes = [1, 2, 3];
const testOutcomes = [1, 2, 3];
deployer.deploy(Betting, testOutcomes);
};
23 changes: 7 additions & 16 deletions ex2/test/BettingTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,22 @@ contract BettingTest {
Betting betting = Betting(DeployedAddresses.Betting());

function testChooseOracle() {
address oracle = betting.chooseOracle(0x14723a09acff6d2a60dcdf7aa4aff308fddc160c);
address oracle = betting.chooseOracle(0x56a686aa7ce2a9a4210dfe2dc28d24fdd8d83a1e);
address expected = betting.oracle();
Assert.equal(oracle, expected, "Oracle chosen by Owner should be registered.");
}

/** *************************************** */
/** The tests below do not work in solidity */
/** *************************************** */
/** ************************************************************ */
/** The test below does not work in Solidity, see bettingTest.js */
/** ************************************************************ */

// function testMakeBet() {
// address exampleA = 0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db;
// // betting.getCurrAddress.call({from:exampleA});
// bool boolA = betting.makeBet(1, {value: 50});
// // bool boolB = betting.makeBet({from: 0x583031d1113ad414f02576bd6afabfb302140225, value: 600});
// address exampleB = 0x583031d1113ad414f02576bd6afabfb302140225;
// bool boolA = betting.makeBet(1, {from: exampleA, value: 600});
// bool boolB = betting.makeBet(2, {from: exampleB, value: 600});
// address gamblerA = betting.gamblerA();
// Assert.equal(boolA, true, "GamblerA should be set correctly.");
// Assert.equal(gamblerA, exampleA, "GamblerA should be set to correct address.");
// }

// function testCheckOutcomes() {
// uint[] outcomes;
// outcomes.push(1);
// outcomes.push(2);
// outcomes.push(3);
// uint[] storage expected = betting.checkOutcomes();
// Assert.equal(outcomes, expected, "Outcomes should be the array declared in ../migrations/2_deploy_contracts.js.");
// }
}
62 changes: 62 additions & 0 deletions ex2/test/bettingTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var Betting = artifacts.require("./Betting.sol");

contract('BettingTestGeneric', function(accounts) {
const args = {_default: accounts[0], _owner: accounts[1]};

it("The contract can be deployed", function() {
return Betting.new()
.then(function(instance) {
assert.ok(instance.address);
});
});

it("The contract can be deployed by custom addresses (default)", function() {
return Betting.new()
.then(function(instance) {
return instance.owner.call();
})
.then(function(result) {
assert.equal(result, args._default, "contract owned by " +
"the wrong address");
});
});

it("The contract can be deployed by custom addresses (using 'from')", function() {
return Betting.new({from: args._owner})
.then(function(instance) {
return instance.owner.call();
})
.then(function(result) {
assert.equal(result, args._owner, "contract owned by " +
"the wrong address");
});
});
});

contract('BettingTestOracleSet', function(accounts) {
const null_address = '0x0000000000000000000000000000000000000000';
const args = {_owner: accounts[1], _oracle: accounts[2],
_other: accounts[3], _fail: null_address};

it("The Owner can set a new Oracle", function() {
return Betting.new({from: args._owner})
.then(function(instance) {
return instance.chooseOracle.call(args._oracle, {from: args._owner});
})
.then(function(result) {
assert.equal(result, args._oracle, "Oracle address and test " +
"values do not match");
});
});

it("The Oracle cannot be set by non-Owner addresses", function() {
return Betting.new({from: args._owner})
.then(function(instance) {
return instance.chooseOracle.call(args._oracle, {from: args._other});
})
.then(function(result) {
assert.equal(result, args._fail, "Oracle address and test " +
"values should both be uninitialized addresses");
});
});
});

0 comments on commit d16ab1d

Please sign in to comment.