Merge pull request #281 from rudygodoy/master
Tests refactoring and typo fixes
This commit is contained in:
@ -58,7 +58,7 @@ contract StandardToken is ERC20, BasicToken {
|
||||
* @dev Function to check the amount of tokens that an owner allowed to a spender.
|
||||
* @param _owner address The address which owns the funds.
|
||||
* @param _spender address The address which will spend the funds.
|
||||
* @return A uint256 specifing the amount of tokens still avaible for the spender.
|
||||
* @return A uint256 specifing the amount of tokens still available for the spender.
|
||||
*/
|
||||
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
||||
return allowed[_owner][_spender];
|
||||
|
||||
@ -7,17 +7,19 @@ var DayLimitMock = artifacts.require('./helpers/DayLimitMock.sol');
|
||||
contract('DayLimit', function(accounts) {
|
||||
const day = 60 * 60 * 24;
|
||||
|
||||
let dayLimit;
|
||||
let initLimit = 10;
|
||||
|
||||
beforeEach( async function() {
|
||||
dayLimit = await DayLimitMock.new(initLimit);
|
||||
});
|
||||
|
||||
it('should construct with the passed daily limit', async function() {
|
||||
let initLimit = 10;
|
||||
let dayLimit = await DayLimitMock.new(initLimit);
|
||||
let dailyLimit = await dayLimit.dailyLimit();
|
||||
assert.equal(initLimit, dailyLimit);
|
||||
});
|
||||
|
||||
it('should be able to spend if daily limit is not reached', async function() {
|
||||
let limit = 10;
|
||||
let dayLimit = await DayLimitMock.new(limit);
|
||||
|
||||
await dayLimit.attemptSpend(8);
|
||||
let spentToday = await dayLimit.spentToday();
|
||||
assert.equal(spentToday, 8);
|
||||
@ -28,9 +30,6 @@ contract('DayLimit', function(accounts) {
|
||||
});
|
||||
|
||||
it('should prevent spending if daily limit is reached', async function() {
|
||||
let limit = 10;
|
||||
let dayLimit = await DayLimitMock.new(limit);
|
||||
|
||||
await dayLimit.attemptSpend(8);
|
||||
let spentToday = await dayLimit.spentToday();
|
||||
assert.equal(spentToday, 8);
|
||||
@ -43,9 +42,6 @@ contract('DayLimit', function(accounts) {
|
||||
});
|
||||
|
||||
it('should allow spending if daily limit is reached and then set higher', async function() {
|
||||
let limit = 10;
|
||||
let dayLimit = await DayLimitMock.new(limit);
|
||||
|
||||
await dayLimit.attemptSpend(8);
|
||||
let spentToday = await dayLimit.spentToday();
|
||||
assert.equal(spentToday, 8);
|
||||
@ -65,9 +61,6 @@ contract('DayLimit', function(accounts) {
|
||||
});
|
||||
|
||||
it('should allow spending if daily limit is reached and then amount spent is reset', async function() {
|
||||
let limit = 10;
|
||||
let dayLimit = await DayLimitMock.new(limit);
|
||||
|
||||
await dayLimit.attemptSpend(8);
|
||||
let spentToday = await dayLimit.spentToday();
|
||||
assert.equal(spentToday, 8);
|
||||
|
||||
@ -1,15 +1,19 @@
|
||||
var PullPaymentMock = artifacts.require("./helpers/PullPaymentMock.sol");
|
||||
|
||||
contract('PullPayment', function(accounts) {
|
||||
|
||||
let ppce;
|
||||
let amount = 17*1e18;
|
||||
|
||||
beforeEach(async function() {
|
||||
ppce = await PullPaymentMock.new({value: amount});
|
||||
});
|
||||
|
||||
it("can't call asyncSend externally", async function() {
|
||||
let ppc = await PullPaymentMock.new();
|
||||
assert.isUndefined(ppc.asyncSend);
|
||||
assert.isUndefined(ppce.asyncSend);
|
||||
});
|
||||
|
||||
it("can record an async payment correctly", async function() {
|
||||
let AMOUNT = 100;
|
||||
let ppce = await PullPaymentMock.new();
|
||||
let callSend = await ppce.callSend(accounts[0], AMOUNT);
|
||||
let paymentsToAccount0 = await ppce.payments(accounts[0]);
|
||||
let totalPayments = await ppce.totalPayments();
|
||||
@ -19,7 +23,6 @@ contract('PullPayment', function(accounts) {
|
||||
});
|
||||
|
||||
it("can add multiple balances on one account", async function() {
|
||||
let ppce = await PullPaymentMock.new();
|
||||
let call1 = await ppce.callSend(accounts[0], 200);
|
||||
let call2 = await ppce.callSend(accounts[0], 300);
|
||||
let paymentsToAccount0 = await ppce.payments(accounts[0]);
|
||||
@ -30,7 +33,6 @@ contract('PullPayment', function(accounts) {
|
||||
});
|
||||
|
||||
it("can add balances on multiple accounts", async function() {
|
||||
let ppce = await PullPaymentMock.new();
|
||||
let call1 = await ppce.callSend(accounts[0], 200);
|
||||
let call2 = await ppce.callSend(accounts[1], 300);
|
||||
|
||||
@ -45,18 +47,16 @@ contract('PullPayment', function(accounts) {
|
||||
});
|
||||
|
||||
it("can withdraw payment", async function() {
|
||||
let AMOUNT = 17*1e18;
|
||||
let payee = accounts[1];
|
||||
let initialBalance = web3.eth.getBalance(payee);
|
||||
|
||||
let ppce = await PullPaymentMock.new({value: AMOUNT});
|
||||
let call1 = await ppce.callSend(payee, AMOUNT);
|
||||
let call1 = await ppce.callSend(payee, amount);
|
||||
|
||||
let payment1 = await ppce.payments(payee);
|
||||
assert.equal(payment1, AMOUNT);
|
||||
assert.equal(payment1, amount);
|
||||
|
||||
let totalPayments = await ppce.totalPayments();
|
||||
assert.equal(totalPayments, AMOUNT);
|
||||
assert.equal(totalPayments, amount);
|
||||
|
||||
let withdraw = await ppce.withdrawPayments({from: payee});
|
||||
let payment2 = await ppce.payments(payee);
|
||||
@ -66,7 +66,7 @@ contract('PullPayment', function(accounts) {
|
||||
assert.equal(totalPayments, 0);
|
||||
|
||||
let balance = web3.eth.getBalance(payee);
|
||||
assert(Math.abs(balance-initialBalance-AMOUNT) < 1e16);
|
||||
assert(Math.abs(balance-initialBalance-amount) < 1e16);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -5,8 +5,13 @@ var StandardTokenMock = artifacts.require('./helpers/StandardTokenMock.sol');
|
||||
|
||||
contract('StandardToken', function(accounts) {
|
||||
|
||||
let token;
|
||||
|
||||
beforeEach(async function() {
|
||||
token = await StandardTokenMock.new(accounts[0], 100);
|
||||
});
|
||||
|
||||
it('should return the correct totalSupply after construction', async function() {
|
||||
let token = await StandardTokenMock.new(accounts[0], 100);
|
||||
let totalSupply = await token.totalSupply();
|
||||
|
||||
assert.equal(totalSupply, 100);
|
||||
@ -56,7 +61,6 @@ contract('StandardToken', function(accounts) {
|
||||
});
|
||||
|
||||
it('should throw an error when trying to transfer more than allowed', async function() {
|
||||
let token = await StandardTokenMock.new();
|
||||
await token.approve(accounts[1], 99);
|
||||
try {
|
||||
await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
|
||||
|
||||
@ -5,9 +5,13 @@ var StandardTokenMock = artifacts.require("./helpers/StandardTokenMock.sol");
|
||||
require('./helpers/transactionMined.js');
|
||||
|
||||
contract('TokenDestructible', function(accounts) {
|
||||
let destructible;
|
||||
|
||||
beforeEach(async function() {
|
||||
destructible = await TokenDestructible.new({fron: accounts[0], value: web3.toWei('10', 'ether')});
|
||||
});
|
||||
|
||||
it('should send balance to owner after destruction', async function() {
|
||||
let destructible = await TokenDestructible.new({from: accounts[0], value: web3.toWei('10','ether')});
|
||||
let owner = await destructible.owner();
|
||||
let initBalance = web3.eth.getBalance(owner);
|
||||
await destructible.destroy([], {from: owner});
|
||||
@ -16,7 +20,6 @@ contract('TokenDestructible', function(accounts) {
|
||||
});
|
||||
|
||||
it('should send tokens to owner after destruction', async function() {
|
||||
let destructible = await TokenDestructible.new({from: accounts[0], value: web3.toWei('10','ether')});
|
||||
let owner = await destructible.owner();
|
||||
let token = await StandardTokenMock.new(destructible.address, 100);
|
||||
let initContractBalance = await token.balanceOf(destructible.address);
|
||||
|
||||
Reference in New Issue
Block a user