Browse Source

Update test names and js style

Alejandro Santander 7 years ago
parent
commit
3009553925
4 changed files with 143 additions and 147 deletions
  1. 0 112
      test/Heritable.js
  2. 110 0
      test/Heritable.test.js
  3. 0 35
      test/SimpleSavingsWallet.js
  4. 33 0
      test/SimpleSavingsWallet.test.js

+ 0 - 112
test/Heritable.js

@@ -1,112 +0,0 @@
-'use strict'
-import increaseTime from './helpers/increaseTime'
-import expectThrow from './helpers/expectThrow';
-
-const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'
-
-const Heritable = artifacts.require('../contracts/ownership/Heritable.sol')
-
-contract('Heritable', function(accounts) {
-  let heritable
-  let owner
-
-  beforeEach(async function() {
-    heritable = await Heritable.new(4141)
-    owner = await heritable.owner()
-  })
-
-  it('should start off with an owner, but without heir', async function() {
-    const heir = await heritable.heir()
-
-    assert.equal(typeof(owner), 'string')
-    assert.equal(typeof(heir), 'string')
-    assert.notStrictEqual(
-      owner, NULL_ADDRESS,
-      "Owner shouldn't be the null address"
-      )
-    assert.isTrue(
-      heir === NULL_ADDRESS,
-      "Heir should be the null address"
-    )
-   })
-
-  it('only owner should set heir', async function() {
-    const newHeir = accounts[1]
-    const someRandomAddress = accounts[2]
-    assert.isTrue(owner !== someRandomAddress)
-
-    await heritable.setHeir(newHeir, {from: owner})
-    await expectThrow(heritable.setHeir(newHeir, {from: someRandomAddress}))
-  })
-
-  it('owner can remove heir', async function() {
-    const newHeir = accounts[1]
-    await heritable.setHeir(newHeir, {from: owner})
-    let heir = await heritable.heir()
-
-    assert.notStrictEqual(heir, NULL_ADDRESS)
-    await heritable.removeHeir()
-    heir = await heritable.heir()
-    assert.isTrue(heir === NULL_ADDRESS)
-  })
-
-  it('heir can claim ownership only if owner is dead and timeout was reached', async function() {
-    const heir = accounts[1]
-    await heritable.setHeir(heir, {from: owner})
-    await expectThrow(heritable.claimHeirOwnership({from: heir}))
-
-    await heritable.proclaimDeath({from: heir})
-    await increaseTime(1)
-    await expectThrow(heritable.claimHeirOwnership({from: heir}))
-
-    await increaseTime(4141)
-    await heritable.claimHeirOwnership({from: heir})
-    assert.isTrue(await heritable.heir() === heir)
-  })
-
-  it('heir can\'t claim ownership if owner heartbeats', async function() {
-    const heir = accounts[1]
-    await heritable.setHeir(heir, {from: owner})
-
-    await heritable.proclaimDeath({from: heir})
-    await heritable.heartbeat({from: owner})
-    await expectThrow(heritable.claimHeirOwnership({from: heir}))
-
-    await heritable.proclaimDeath({from: heir})
-    await increaseTime(4141)
-    await heritable.heartbeat({from: owner})
-    await expectThrow(heritable.claimHeirOwnership({from: heir}))
-  })
-
-  it('should log events appropriately', async function() {
-    const heir = accounts[1]
-
-    const setHeirLogs = (await heritable.setHeir(heir, {from: owner})).logs
-    const setHeirEvent = setHeirLogs.find(e => e.event === 'HeirChanged')
-
-    assert.isTrue(setHeirEvent.args.owner === owner)
-    assert.isTrue(setHeirEvent.args.newHeir === heir)
-
-    const heartbeatLogs = (await heritable.heartbeat({from: owner})).logs
-    const heartbeatEvent = heartbeatLogs.find(e => e.event === 'OwnerHeartbeated')
-
-    assert.isTrue(heartbeatEvent.args.owner === owner)
-
-    const proclaimDeathLogs = (await heritable.proclaimDeath({from: heir})).logs
-    const ownerDeadEvent = proclaimDeathLogs.find(e => e.event === 'OwnerProclaimedDead')
-
-    assert.isTrue(ownerDeadEvent.args.owner === owner)
-    assert.isTrue(ownerDeadEvent.args.heir === heir)
-
-    await increaseTime(4141)
-    const claimHeirOwnershipLogs = (await heritable.claimHeirOwnership({from: heir})).logs
-    const ownershipTransferredEvent = claimHeirOwnershipLogs.find(e => e.event === 'OwnershipTransferred')
-    const heirOwnershipClaimedEvent = claimHeirOwnershipLogs.find(e => e.event === 'HeirOwnershipClaimed')
-
-    assert.isTrue(ownershipTransferredEvent.args.previousOwner === owner)
-    assert.isTrue(ownershipTransferredEvent.args.newOwner === heir)
-    assert.isTrue(heirOwnershipClaimedEvent.args.previousOwner === owner)
-    assert.isTrue(heirOwnershipClaimedEvent.args.newOwner === heir)
-
-  })
-})

+ 110 - 0
test/Heritable.test.js

@@ -0,0 +1,110 @@
+import increaseTime from './helpers/increaseTime';
+import expectThrow from './helpers/expectThrow';
+
+const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
+
+const Heritable = artifacts.require('../contracts/ownership/Heritable.sol');
+
+contract('Heritable', function (accounts) {
+  let heritable;
+  let owner;
+
+  beforeEach(async function () {
+    heritable = await Heritable.new(4141);
+    owner = await heritable.owner();
+  });
+
+  it('should start off with an owner, but without heir', async function () {
+    const heir = await heritable.heir();
+
+    assert.equal(typeof (owner), 'string');
+    assert.equal(typeof (heir), 'string');
+    assert.notStrictEqual(
+      owner, NULL_ADDRESS,
+      'Owner shouldn\'t be the null address'
+    );
+    assert.isTrue(
+      heir === NULL_ADDRESS,
+      'Heir should be the null address'
+    );
+  });
+
+  it('only owner should set heir', async function () {
+    const newHeir = accounts[1];
+    const someRandomAddress = accounts[2];
+    assert.isTrue(owner !== someRandomAddress);
+
+    await heritable.setHeir(newHeir, { from: owner });
+    await expectThrow(heritable.setHeir(newHeir, { from: someRandomAddress }));
+  });
+
+  it('owner can remove heir', async function () {
+    const newHeir = accounts[1];
+    await heritable.setHeir(newHeir, { from: owner });
+    let heir = await heritable.heir();
+
+    assert.notStrictEqual(heir, NULL_ADDRESS);
+    await heritable.removeHeir();
+    heir = await heritable.heir();
+    assert.isTrue(heir === NULL_ADDRESS);
+  });
+
+  it('heir can claim ownership only if owner is dead and timeout was reached', async function () {
+    const heir = accounts[1];
+    await heritable.setHeir(heir, { from: owner });
+    await expectThrow(heritable.claimHeirOwnership({ from: heir }));
+
+    await heritable.proclaimDeath({ from: heir });
+    await increaseTime(1);
+    await expectThrow(heritable.claimHeirOwnership({ from: heir }));
+
+    await increaseTime(4141);
+    await heritable.claimHeirOwnership({ from: heir });
+    assert.isTrue(await heritable.heir() === heir);
+  });
+
+  it('heir can\'t claim ownership if owner heartbeats', async function () {
+    const heir = accounts[1];
+    await heritable.setHeir(heir, { from: owner });
+
+    await heritable.proclaimDeath({ from: heir });
+    await heritable.heartbeat({ from: owner });
+    await expectThrow(heritable.claimHeirOwnership({ from: heir }));
+
+    await heritable.proclaimDeath({ from: heir });
+    await increaseTime(4141);
+    await heritable.heartbeat({ from: owner });
+    await expectThrow(heritable.claimHeirOwnership({ from: heir }));
+  });
+
+  it('should log events appropriately', async function () {
+    const heir = accounts[1];
+
+    const setHeirLogs = (await heritable.setHeir(heir, { from: owner })).logs;
+    const setHeirEvent = setHeirLogs.find(e => e.event === 'HeirChanged');
+
+    assert.isTrue(setHeirEvent.args.owner === owner);
+    assert.isTrue(setHeirEvent.args.newHeir === heir);
+
+    const heartbeatLogs = (await heritable.heartbeat({ from: owner })).logs;
+    const heartbeatEvent = heartbeatLogs.find(e => e.event === 'OwnerHeartbeated');
+
+    assert.isTrue(heartbeatEvent.args.owner === owner);
+
+    const proclaimDeathLogs = (await heritable.proclaimDeath({ from: heir })).logs;
+    const ownerDeadEvent = proclaimDeathLogs.find(e => e.event === 'OwnerProclaimedDead');
+
+    assert.isTrue(ownerDeadEvent.args.owner === owner);
+    assert.isTrue(ownerDeadEvent.args.heir === heir);
+
+    await increaseTime(4141);
+    const claimHeirOwnershipLogs = (await heritable.claimHeirOwnership({ from: heir })).logs;
+    const ownershipTransferredEvent = claimHeirOwnershipLogs.find(e => e.event === 'OwnershipTransferred');
+    const heirOwnershipClaimedEvent = claimHeirOwnershipLogs.find(e => e.event === 'HeirOwnershipClaimed');
+
+    assert.isTrue(ownershipTransferredEvent.args.previousOwner === owner);
+    assert.isTrue(ownershipTransferredEvent.args.newOwner === heir);
+    assert.isTrue(heirOwnershipClaimedEvent.args.previousOwner === owner);
+    assert.isTrue(heirOwnershipClaimedEvent.args.newOwner === heir);
+  });
+});

+ 0 - 35
test/SimpleSavingsWallet.js

@@ -1,35 +0,0 @@
-'use strict'
-import expectThrow from './helpers/expectThrow';
-
-const SimpleSavingsWallet = artifacts.require('../contracts/examples/SimpleSavingsWallet.sol')
-
-contract('SimpleSavingsWallet', function(accounts) {
-  let savingsWallet
-  let owner
-
-	const paymentAmount = 4242
- 
-  beforeEach(async function() {
-    savingsWallet = await SimpleSavingsWallet.new(4141)
-    owner = await savingsWallet.owner()
-  })
-
-	it('should receive funds', async function() {
-		await web3.eth.sendTransaction({from: owner, to: savingsWallet.address, value: paymentAmount})    
-    assert.isTrue(
-    	(new web3.BigNumber(paymentAmount)).equals(web3.eth.getBalance(savingsWallet.address))
-    )
-  })
-
-  it('owner can send funds', async function() {
-  	// Receive payment so we have some money to spend.
-		await web3.eth.sendTransaction({from: accounts[9], to: savingsWallet.address, value: 1000000})
-    await expectThrow(savingsWallet.sendTo(0, paymentAmount, {from: owner}))
-    await expectThrow(savingsWallet.sendTo(savingsWallet.address, paymentAmount, {from: owner}))
-    await expectThrow(savingsWallet.sendTo(accounts[1], 0, {from: owner}))
-
-    const balance = web3.eth.getBalance(accounts[1])
-  	await savingsWallet.sendTo(accounts[1], paymentAmount, {from: owner})
-  	assert.isTrue(balance.plus(paymentAmount).equals(web3.eth.getBalance(accounts[1])))
-  })
-})

+ 33 - 0
test/SimpleSavingsWallet.test.js

@@ -0,0 +1,33 @@
+
+import expectThrow from './helpers/expectThrow';
+
+const SimpleSavingsWallet = artifacts.require('../contracts/examples/SimpleSavingsWallet.sol');
+
+contract('SimpleSavingsWallet', function (accounts) {
+  let savingsWallet;
+  let owner;
+
+  const paymentAmount = 4242;
+ 
+  beforeEach(async function () {
+    savingsWallet = await SimpleSavingsWallet.new(4141);
+    owner = await savingsWallet.owner();
+  });
+
+  it('should receive funds', async function () {
+    await web3.eth.sendTransaction({ from: owner, to: savingsWallet.address, value: paymentAmount });
+    assert.isTrue((new web3.BigNumber(paymentAmount)).equals(web3.eth.getBalance(savingsWallet.address)));
+  });
+
+  it('owner can send funds', async function () {
+    // Receive payment so we have some money to spend.
+    await web3.eth.sendTransaction({ from: accounts[9], to: savingsWallet.address, value: 1000000 });
+    await expectThrow(savingsWallet.sendTo(0, paymentAmount, { from: owner }));
+    await expectThrow(savingsWallet.sendTo(savingsWallet.address, paymentAmount, { from: owner }));
+    await expectThrow(savingsWallet.sendTo(accounts[1], 0, { from: owner }));
+
+    const balance = web3.eth.getBalance(accounts[1]);
+    await savingsWallet.sendTo(accounts[1], paymentAmount, { from: owner });
+    assert.isTrue(balance.plus(paymentAmount).equals(web3.eth.getBalance(accounts[1])));
+  });
+});