Skip to content

Commit

Permalink
Add test to improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gjgd committed Jul 19, 2018
1 parent c934b13 commit b496314
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion contracts/TransmuteDPOS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ contract TransmuteDPOS is TransmuteToken, RoundManager, ProviderPool {
require(_feeShare <= 100);
Provider storage p = providers[msg.sender];
Delegator storage d = delegators[msg.sender];
// Provider has to be a Delegator to himself
require(d.delegateAddress == msg.sender);
require(d.amountBonded > 0);
if (p.status == ProviderStatus.Unregistered) {
numberOfProviders = numberOfProviders.add(1);
addProvider(msg.sender, p.totalAmountBonded);
Expand All @@ -108,6 +108,7 @@ contract TransmuteDPOS is TransmuteToken, RoundManager, ProviderPool {
}

function bond(address _provider, uint _amount) external {
require(_amount > 0);
Provider storage p = providers[_provider];
// A delegator is only allowed to bond to an Unregistered provider if the provider is himself
// otherwise _provider has to be associated with a Registered provider
Expand Down
6 changes: 5 additions & 1 deletion test/TestTransmuteDPOS.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ contract('TransmuteDPOS', accounts => {
assert.equal(10, firstDelegator[1]); // [1] is amountBonded
});

it('should increase the totalAmountBonded of the Provider', async () => {
it('should fail if amount is zero', async () => {
await tdpos.approve(contractAddress, 20, {from: accounts[6]});
await assertFail( tdpos.bond(accounts[0], 0, {from: accounts[6]}) );
});

it('should increase the totalAmountBonded of the Provider', async () => {
await tdpos.bond(accounts[0], 20, {from: accounts[6]});
const provider = await tdpos.providers.call(accounts[0]);
assert.equal(31, provider[5].toNumber()); // [5] is totalAmountBonded
Expand Down

0 comments on commit b496314

Please sign in to comment.