var PotOfEther = artifacts.require('./PotOfEther.sol');

contract('PotOfEther', accounts => {
  describe('createPot', () => {
    it('should fail when buyIn == 0', async () => {
      var instance = await PotOfEther.new();

      try {
        await instance.createPot('pot1', {
          from: accounts[0],
          value: 0
        });
      } catch (err) {
        assert(true);
        return;
      }
      assert(false, "empty buyIn but didn't fail");
    });

    it('should fail when name.length == 0', async () => {
      var instance = await PotOfEther.new();

      try {
        await instance.createPot('', {
          from: accounts[0],
          value: 1000
        });
      } catch (err) {
        assert(true);
        return;
      }
      assert(false, "empty name but didn't fail");
    });

    it('should emit LogPotCreated event', async () => {
      var instance = await PotOfEther.new();

      var result = await instance.createPot('banana', {
        from: accounts[0],
        value: 1000
      });

      assert.equal(result.logs.length, 2);
      assert.equal(result.logs[0].args.name, 'banana');
      assert.equal(result.logs[0].args.buyIn.valueOf(), 1000);
      assert.equal(result.logs[0].args.firstPlayer, accounts[0]);
    });

    it('should emit LogPotJoin event', async () => {
      var instance = await PotOfEther.new();

      var result = await instance.createPot('papaya', {
        from: accounts[0],
        value: 1000
      });

      assert.equal(result.logs.length, 2);
      assert.equal(result.logs[1].args.name, 'papaya');
      assert.equal(result.logs[1].args.newPlayer, accounts[0]);
    });
  })
});



@@ -267,12 +267,14 @@
 ot('
-pot1
+banana
 ', %7B
@@ -801,32 +801,502 @@
 ail%22);%0A    %7D);%0A%0A
+    it('should fail when name already exists', async () =%3E %7B%0A      var instance = await PotOfEther.new();%0A%0A      await instance.createPot('banana', %7B%0A        from: accounts%5B0%5D,%0A        value: 1000%0A      %7D);%0A%0A      try %7B%0A        await instance.createPot('banana', %7B%0A          from: accounts%5B0%5D,%0A          value: 1000%0A        %7D);%0A      %7D catch (err) %7B%0A        assert(true);%0A        return;%0A      %7D%0A%0A      assert(false, %22two pots with same name but didn't fail%22);%0A    %7D);%0A%0A
     it('should e
@@ -1876,21 +1876,21 @@
 atePot('
-papay
+banan
 a', %7B%0A  
@@ -2038,13 +2038,13 @@
 e, '
-papay
+banan
 a');

test error on 2 pots with same name