modified test to use async await pattern.

This commit is contained in:
Angello Pozo
2016-11-27 12:09:48 -08:00
parent c920c40507
commit f2142545c7
12 changed files with 360 additions and 654 deletions

View File

@ -1,58 +1,35 @@
contract('Ownable', function(accounts) {
var ownable;
beforeEach(function() {
return Ownable.new().then(function(deployed) {
ownable = deployed;
});
beforeEach(async function() {
ownable = await Ownable.new();
});
it("should have an owner", function(done) {
return ownable.owner()
.then(function(owner) {
assert.isTrue(owner != 0);
})
.then(done)
it("should have an owner", async function() {
let owner = await ownable.owner();
assert.isTrue(owner != 0);
});
it("changes owner after transfer", function(done) {
var other = accounts[1];
return ownable.transfer(other)
.then(function() {
return ownable.owner();
})
.then(function(owner) {
assert.isTrue(owner === other);
})
.then(done)
it("changes owner after transfer", async function() {
let other = accounts[1];
let transfer = await ownable.transfer(other);
let owner = await ownable.owner();
assert.isTrue(owner === other);
});
it("should prevent non-owners from transfering" ,function(done) {
var other = accounts[2];
return ownable.transfer(other, {from: accounts[2]})
.then(function() {
return ownable.owner();
})
.then(function(owner) {
assert.isFalse(owner === other);
})
.then(done)
it("should prevent non-owners from transfering", async function() {
let other = accounts[2];
let transfer = await ownable.transfer(other, {from: accounts[2]});
let owner = await ownable.owner();
assert.isFalse(owner === other);
});
it("should guard ownership against stuck state" ,function(done) {
var ownable = Ownable.deployed();
return ownable.owner()
.then(function (originalOwner) {
return ownable.transfer(null, {from: originalOwner})
.then(function() {
return ownable.owner();
})
.then(function(newOwner) {
assert.equal(originalOwner, newOwner);
})
.then(done);
});
it("should guard ownership against stuck state", async function() {
let ownable = Ownable.deployed();
let originalOwner = await ownable.owner();
let transfer = await ownable.transfer(null, {from: originalOwner});
let newOwner = await ownable.owner();
assert.equal(originalOwner, newOwner);
});
});