Skip to content

Commit

Permalink
Work around issue with overloaded functions in Truffle tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
visitskyworld committed Apr 2, 2018
1 parent 1aec23f commit d6916c1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
5 changes: 2 additions & 3 deletions contracts/ConditionalStarRelease.sol
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,11 @@ contract ConditionalStarRelease is Ownable

// withdraw(): withdraw one star to the sender's address
//
//TODO overloading seems bugged for functions without arguments.
/* function withdraw()
function withdraw()
external
{
withdraw(msg.sender);
} */
}

// withdraw(): withdraw one star from the sender's commitment to _to
//
Expand Down
5 changes: 2 additions & 3 deletions contracts/LinearStarRelease.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,11 @@ contract LinearStarRelease is Ownable

// withdraw(): withdraw one star to the sender's address
//
//TODO overloading seems bugged for functions without arguments.
/* function withdraw()
function withdraw()
external
{
withdraw(msg.sender);
} */
}

// withdraw(): withdraw one star from the sender's batch to _to
//
Expand Down
5 changes: 2 additions & 3 deletions contracts/Ships.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,13 @@ contract Ships is Ownable
// Note: only useful for clients, as Solidity does not currently
// support returning dynamic arrays.
//
//TODO overloading seems bugged for functions without arguments.
/* function getOwnedShips()
function getOwnedShips()
view
public
returns (uint32[] ownedShips)
{
return owners[msg.sender];
} */
}

// getOwnedShips(): return array of ships that _whose owns
//
Expand Down
12 changes: 6 additions & 6 deletions test/TestConditionalStarRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,24 @@ contract('Conditional Star Release', function([owner, user1, user2]) {
assert.equal(await csr.withdrawLimit(user1), 3);
// only commitment participant can do this
try {
await csr.withdraw(user1);
await csr.withdraw({from:owner});
assert.fail('should have thrown before');
} catch(err) {
assertJump(err);
}
await csr.withdraw(user1, {from:user1});
await csr.withdraw({from:user1});
assert.isTrue(await ships.isOwner(2048, user1));
assert.equal((await csr.commitments(user1))[3], 1);
// can't withdraw over limit
try {
await csr.withdraw(user1);
await csr.withdraw();
assert.fail('should have thrown before');
} catch(err) {
assertJump(err);
}
assert.equal(await csr.withdrawLimit(user1), 3);
await csr.withdraw(user1, {from:user1});
await csr.withdraw(user1, {from:user1});
await csr.withdraw({from:user1});
await csr.withdraw({from:user1});
assert.equal((await csr.commitments(user1))[3], 3);
});

Expand All @@ -152,7 +152,7 @@ contract('Conditional Star Release', function([owner, user1, user2]) {
busywait(rateUnit);
// can't withdraw because of forfeit
try {
await csr.withdraw(user1, {from:user1});
await csr.withdraw({from:user1});
assert.fail('should have thrown before');
} catch(err) {
assertJump(err);
Expand Down
16 changes: 8 additions & 8 deletions test/TestLinearStarRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ contract('Linear Star Release', function([owner, user1, user2]) {
assert.equal(await lsr.withdrawLimit(user1), 4);
// only commitment participant can do this
try {
await lsr.withdraw(user1);
await lsr.withdraw({from:owner});
assert.fail('should have thrown before');
} catch(err) {
assertJump(err);
}
await lsr.withdraw(user1, {from:user1});
await lsr.withdraw({from:user1});
assert.isTrue(await ships.isOwner(2048, user1));
assert.equal((await lsr.batches(user1))[4], 1);
await lsr.withdraw({from:user1});
await lsr.withdraw({from:user1});
await lsr.withdraw({from:user1});
assert.equal((await lsr.batches(user1))[4], 4);
assert.equal(await lsr.withdrawLimit(user1), 4);
// can't withdraw over limit
try {
await lsr.withdraw(user1);
await lsr.withdraw({from:user1});
assert.fail('should have thrown before');
} catch(err) {
assertJump(err);
}
assert.equal(await lsr.withdrawLimit(user1), 4);
await lsr.withdraw(user1, {from:user1});
await lsr.withdraw(user1, {from:user1});
await lsr.withdraw(user1, {from:user1});
assert.equal((await lsr.batches(user1))[4], 4);
});
});
4 changes: 2 additions & 2 deletions test/TestShips.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ contract('Ships', function([owner, user]) {
it('getting owned ships', async function() {
await ships.setOwner(1, user);
await ships.setOwner(2, user);
let owned = await ships.getOwnedShips(user);
let owned = await ships.getOwnedShips({from:user});
assert.equal(owned[0].toNumber(), 0);
assert.equal(owned[1].toNumber(), 1);
assert.equal(owned[2].toNumber(), 2);
assert.equal(owned.length, 3);
await ships.setOwner(0, 0);
owned = await ships.getOwnedShips(user);
owned = await ships.getOwnedShips({from:user});
assert.equal(owned[0].toNumber(), 2);
assert.equal(owned[1].toNumber(), 1);
assert.equal(owned.length, 2);
Expand Down

0 comments on commit d6916c1

Please sign in to comment.