From 1547000d1c63257659c09b79019dd5114c26d08b Mon Sep 17 00:00:00 2001 From: Steve Ellis Date: Sun, 13 Nov 2016 16:49:05 -0500 Subject: [PATCH 1/2] move Ownable tests away from migration fixtures --- test/Ownable.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/Ownable.js b/test/Ownable.js index 83ae4b93e..8663da9ee 100644 --- a/test/Ownable.js +++ b/test/Ownable.js @@ -1,6 +1,13 @@ contract('Ownable', function(accounts) { + var ownable; + + beforeEach(function() { + return Ownable.new().then(function(deployed) { + ownable = deployed; + }); + }); + it("should have an owner", function(done) { - var ownable = Ownable.deployed(); return ownable.owner() .then(function(owner) { assert.isTrue(owner != 0); @@ -9,7 +16,6 @@ contract('Ownable', function(accounts) { }); it("changes owner after transfer", function(done) { - var ownable = Ownable.deployed(); var other = accounts[1]; return ownable.transfer(other) .then(function() { @@ -22,7 +28,6 @@ contract('Ownable', function(accounts) { }); it("should prevent non-owners from transfering" ,function(done) { - var ownable = Ownable.deployed(); var other = accounts[2]; return ownable.transfer(other, {from: accounts[2]}) .then(function() { From a156064b33eb4d0b815710a93fe878aa69e2faa6 Mon Sep 17 00:00:00 2001 From: Steve Ellis Date: Sun, 13 Nov 2016 17:00:15 -0500 Subject: [PATCH 2/2] make claimable use fresh instances for each test --- test/Claimable.js | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/test/Claimable.js b/test/Claimable.js index 9d62663d6..464b7406e 100644 --- a/test/Claimable.js +++ b/test/Claimable.js @@ -1,7 +1,13 @@ contract('Claimable', function(accounts) { + var claimable; + + beforeEach(function() { + return Claimable.new().then(function(deployed) { + claimable = deployed; + }); + }); it("should have an owner", function(done) { - var claimable = Claimable.deployed(); return claimable.owner() .then(function(owner) { assert.isTrue(owner != 0); @@ -10,19 +16,18 @@ contract('Claimable', function(accounts) { }); it("changes pendingOwner after transfer", function(done) { - var claimable = Claimable.deployed(); - return claimable.transfer(accounts[1]) + var newOwner = accounts[1]; + return claimable.transfer(newOwner) .then(function() { return claimable.pendingOwner(); }) .then(function(pendingOwner) { - assert.isTrue(pendingOwner === accounts[1]); + assert.isTrue(pendingOwner === newOwner); }) .then(done) }); it("should prevent to claimOwnership from no pendingOwner", function(done) { - var claimable = Claimable.deployed(); return claimable.claimOwnership({from: accounts[2]}) .then(function() { return claimable.owner(); @@ -33,20 +38,7 @@ contract('Claimable', function(accounts) { .then(done) }); - it("changes allow pending owner to claim ownership", function(done) { - var claimable = Claimable.deployed(); - return claimable.claimOwnership({from: accounts[1]}) - .then(function() { - return claimable.owner(); - }) - .then(function(owner) { - assert.isTrue(owner === accounts[1]); - }) - .then(done) - }); - it("should prevent non-owners from transfering" ,function(done) { - var claimable = Claimable.deployed(); return claimable.transfer(accounts[2], {from: accounts[2]}) .then(function() { return claimable.pendingOwner(); @@ -57,4 +49,23 @@ contract('Claimable', function(accounts) { .then(done) }); + describe("after initiating a transfer", function () { + var newOwner; + + beforeEach(function () { + newOwner = accounts[1]; + return claimable.transfer(newOwner); + }); + + it("changes allow pending owner to claim ownership", function(done) { + return claimable.claimOwnership({from: newOwner}) + .then(function() { + return claimable.owner(); + }) + .then(function(owner) { + assert.isTrue(owner === newOwner); + }) + .then(done) + }); + }); });