Stoppable.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. contract('Stoppable', function(accounts) {
  2. it("can perform normal process in non-emergency", function(done) {
  3. var stoppable;
  4. return StoppableMock.new()
  5. .then(function(_stoppable) {
  6. stoppable = _stoppable;
  7. return stoppable.count();
  8. })
  9. .then(function(count) {
  10. assert.equal(count, 0);
  11. })
  12. .then(function () {
  13. return stoppable.normalProcess();
  14. })
  15. .then(function() {
  16. return stoppable.count();
  17. })
  18. .then(function(count) {
  19. assert.equal(count, 1);
  20. })
  21. .then(done);
  22. });
  23. it("can not perform normal process in emergency", function(done) {
  24. var stoppable;
  25. return StoppableMock.new()
  26. .then(function(_stoppable) {
  27. stoppable = _stoppable;
  28. return stoppable.emergencyStop();
  29. })
  30. .then(function () {
  31. return stoppable.count();
  32. })
  33. .then(function(count) {
  34. assert.equal(count, 0);
  35. })
  36. .then(function () {
  37. return stoppable.normalProcess();
  38. })
  39. .then(function() {
  40. return stoppable.count();
  41. })
  42. .then(function(count) {
  43. assert.equal(count, 0);
  44. })
  45. .then(done);
  46. });
  47. it("can not take drastic measure in non-emergency", function(done) {
  48. var stoppable;
  49. return StoppableMock.new()
  50. .then(function(_stoppable) {
  51. stoppable = _stoppable;
  52. return stoppable.drasticMeasure();
  53. })
  54. .then(function() {
  55. return stoppable.drasticMeasureTaken();
  56. })
  57. .then(function(taken) {
  58. assert.isFalse(taken);
  59. })
  60. .then(done);
  61. });
  62. it("can take a drastic measure in an emergency", function(done) {
  63. var stoppable;
  64. return StoppableMock.new()
  65. .then(function(_stoppable) {
  66. stoppable = _stoppable;
  67. return stoppable.emergencyStop();
  68. })
  69. .then(function() {
  70. return stoppable.drasticMeasure();
  71. })
  72. .then(function() {
  73. return stoppable.drasticMeasureTaken();
  74. })
  75. .then(function(taken) {
  76. assert.isTrue(taken);
  77. })
  78. .then(done);
  79. });
  80. it("should resume allowing normal process after emergency is over", function(done) {
  81. var stoppable;
  82. return StoppableMock.new()
  83. .then(function(_stoppable) {
  84. stoppable = _stoppable;
  85. return stoppable.emergencyStop();
  86. })
  87. .then(function () {
  88. return stoppable.release();
  89. })
  90. .then(function() {
  91. return stoppable.normalProcess();
  92. })
  93. .then(function() {
  94. return stoppable.count();
  95. })
  96. .then(function(count) {
  97. assert.equal(count, 1);
  98. })
  99. .then(done);
  100. });
  101. });