Created
January 31, 2017 15:16
-
-
Save CowboyJim/d7de6e07eff0dec810922d7e1abdcf50 to your computer and use it in GitHub Desktop.
Payment Directory Distributed Unit Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract('AliasDirectoryContract', function (accounts) { | |
// Note: account[0] is the contract owner | |
var authorizedBank = accounts[1]; | |
var unauthorizedBank = accounts[2]; | |
var directory; | |
// Grap a reference to the directory contract and add an authorized user prior to the tests | |
before("Add authorized bank and user", function () { | |
directory = AliasDirectoryContract.deployed(); | |
return directory.addAuthorizedBanks("Authorized Bank", "053000196", authorizedBank).then(function (tx_id) { | |
// Add a new user | |
return directory.newOwner("Sam Smith", { from: authorizedBank }).then(function (tx_id) { | |
return; | |
}) | |
}); | |
}); | |
it("should add a new user and alias the directory", function () { | |
directory.newOwnerAndAlias("John Doe", "7043869776", false, "bof12345").then(function (tx_id) { | |
return directory.getAlias.call("7043869776").then(function (results) { | |
assert.isFalse(results[0], "Should be false"); | |
assert.equal(results[1], "bof12345"); | |
assert.equal(results[2], "John Doe"); | |
assert.equal(results[3], 101); | |
return directory.getOwnerId.call("John Doe").then(function (id) { | |
assert.equal(id, 101); | |
return directory.getOwnerId.call("Sam Smith").then(function (id) { | |
assert.equal(id, 100); | |
}); | |
}); | |
}).catch(function (err) { | |
assert.fail(0, 1, err); | |
}); | |
}).catch(function (err) { | |
assert.fail(0, 1, err); | |
}); | |
}); | |
it("should fail to let an unauthorized bank add any bank to authorized list", function () { | |
directory.addAuthorizedBanks("Bogus Bank", accounts[4], { from: unauthorizedBank }).then(function (tx_id) { | |
assert.fail(0, 1, "This should fail"); | |
}).catch(function () { | |
// An exception was thrown as expected | |
}); | |
}); | |
it("should ensure that only the bank that owns the alias can delete it", function () { | |
directory.newAlias(100, "[email protected]", true, "bof12345", { from: authorizedBank }).then(function (tx_id) { | |
return directory.deleteAlias("[email protected]", { from: accounts[0] }).then(function (tx_id) { | |
assert.fail(0, 1, "This should fail"); | |
}).catch(function (err) { | |
return directory.deleteAlias("[email protected]", { from: authorizedBank }).then(function (tx_id) { | |
}).catch(function () { | |
assert.fail(0, 1, "This should not fail"); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment