邓心一 6 anos atrás
pai
commit
d61b85f1b7
1 arquivos alterados com 33 adições e 6 exclusões
  1. 33 6
      test/test-contract.js

+ 33 - 6
test/test-contract.js

@@ -1,5 +1,24 @@
 /* eslint no-undef: "off" */
-/* eslint arrow-body-style: ["error", "always"] */
+const logger = console.log.bind(console) // eslint-disable-line no-console
+
+function logEvents(result, name) {
+    result.logs.forEach((log) => {
+        if (log.event === name) {
+            logger(log)
+        }
+    })
+}
+
+function assertEventInResult(result, name) {
+    let isIn = false
+    result.logs.forEach((log) => {
+        if (log.event === name) {
+            isIn = true
+        }
+    })
+    assert.equal(isIn, true, `Event ${name} should be in the result!`)
+}
+
 const ShowTrader = artifacts.require('ShowTrader')
 
 contract('ShowTrader Test', (accounts) => {
@@ -14,7 +33,9 @@ contract('ShowTrader Test', (accounts) => {
             trader = instance
             return trader.createFirstShow(showName, danceData, musicData, { from: player })
         })
-        .then(() => {
+        .then((result) => {
+            // logEvents(result, 'NewShow')
+            assertEventInResult(result, 'NewShow')
             return trader.getShowsByOwner.call(player)
         })
         .then((shows) => {
@@ -42,10 +63,12 @@ contract('ShowTrader Test', (accounts) => {
             trader = instance
             return trader.createFirstShow(name1, danceData, musicData, { from: player1 })
         })
-        .then(() => {
+        .then((result) => {
+            assertEventInResult(result, 'NewShow')
             return trader.createFirstShow(name2, danceData, musicData, { from: player2 })
         })
-        .then(() => {
+        .then((result) => {
+            assertEventInResult(result, 'NewShow')
             return trader.getShowsByOwner.call(player1)
         })
         .then((shows1) => {
@@ -56,10 +79,14 @@ contract('ShowTrader Test', (accounts) => {
             id2 = shows2[0].toNumber()
             return trader.wantToExchange(id1, id2, { from: player1 })
         })
-        .then(() => {
+        .then((result) => {
+            // logEvents(result, 'WantToExchange')
+            assertEventInResult(result, 'WantToExchange')
             return trader.wantToExchange(id2, id1, { from: player2 })
         })
-        .then(() => {
+        .then((result) => {
+            // logEvents(result, 'Transfer')
+            assertEventInResult(result, 'Transfer')
             return trader.showToOwner(id1)
         })
         .then((owner1) => {