fix: made all the tests consistent. now with done.

This commit is contained in:
Angello Pozo
2016-11-30 13:24:02 -08:00
parent f2142545c7
commit 688106e9c3
10 changed files with 108 additions and 59 deletions

View File

@ -1,37 +1,41 @@
contract('SafeMath', function(accounts) {
var safeMath;
let safeMath;
before(async function() {
before(async function(done) {
safeMath = await SafeMathMock.new();
done();
});
it("multiplies correctly", async function() {
it("multiplies correctly", async function(done) {
let a = 5678;
let b = 1234;
let mult = await safeMath.multiply(a, b);
let result = await safeMath.result();
assert.equal(result, a*b);
done();
});
it("adds correctly", async function() {
it("adds correctly", async function(done) {
let a = 5678;
let b = 1234;
let add = await safeMath.add(a, b);
let result = await safeMath.result();
assert.equal(result, a+b);
done();
});
it("subtracts correctly", async function() {
it("subtracts correctly", async function(done) {
let a = 5678;
let b = 1234;
let subtract = await safeMath.subtract(a, b);
let result = await safeMath.result();
assert.equal(result, a-b);
done();
});
it("should throw an error if subtraction result would be negative", async function () {
it("should throw an error if subtraction result would be negative", async function (done) {
let a = 1234;
let b = 5678;
try {
@ -39,10 +43,11 @@ contract('SafeMath', function(accounts) {
} catch(error) {
if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
}
});
it("should throw an error on addition overflow", async function() {
it("should throw an error on addition overflow", async function(done) {
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
let b = 1;
try {
@ -50,10 +55,11 @@ contract('SafeMath', function(accounts) {
} catch(error) {
if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
}
});
it("should throw an error on multiplication overflow", async function() {
it("should throw an error on multiplication overflow", async function(done) {
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639933;
let b = 2;
try {
@ -61,6 +67,7 @@ contract('SafeMath', function(accounts) {
} catch(error) {
if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
}
});