/* eslint no-undef: "off" */ /* eslint arrow-body-style: ["error", "always"] */ const ShowTrader = artifacts.require('ShowTrader') contract('ShowTrader Test', (accounts) => { let trader const danceData = '0x111000' const musicData = '0x000111' it('should create 1 show', () => { const player = accounts[0] const showName = '1st show' return ShowTrader.deployed() .then((instance) => { trader = instance return trader.createFirstShow(showName, danceData, musicData, { from: player }) }) .then(() => { return trader.getShowsByOwner.call(player) }) .then((shows) => { const id = shows[0].toNumber() return trader.shows(id) }) .then((show) => { assert.equal(show[0], showName) assert.equal(show[1], danceData) assert.equal(show[2], musicData) }) }) // The second test begin... it('shoud exchange 2 shows', () => { const name1 = 'show1' const name2 = 'show2' const player1 = accounts[1] // The account[0] is used for the 1st test // Note: 'VM Exception while processing transaction: revert', // usually means that the require() statement is not met const player2 = accounts[2] let id1 let id2 return ShowTrader.deployed() .then((instance) => { trader = instance return trader.createFirstShow(name1, danceData, musicData, { from: player1 }) }) .then(() => { return trader.createFirstShow(name2, danceData, musicData, { from: player2 }) }) .then(() => { return trader.getShowsByOwner.call(player1) }) .then((shows1) => { id1 = shows1[0].toNumber() return trader.getShowsByOwner.call(player2) }) .then((shows2) => { id2 = shows2[0].toNumber() return trader.wantToExchange(id1, id2, { from: player1 }) }) .then(() => { return trader.wantToExchange(id2, id1, { from: player2 }) }) .then(() => { return trader.showToOwner(id1) }) .then((owner1) => { assert.equal(owner1, player2, 'owner of show1 should be player2!') return trader.showToOwner(id2) }) .then((owner2) => { assert.equal(owner2, player1, 'owner of show2 should be player1!') }) }) })