Skip to content

Commit

Permalink
Merge b10db15 into 114c9ed
Browse files Browse the repository at this point in the history
  • Loading branch information
gjgd committed Jul 13, 2018
2 parents 114c9ed + b10db15 commit 7df93fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
9 changes: 6 additions & 3 deletions contracts/TransmuteDPOS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ contract TransmuteDPOS is TransmuteToken, RoundManager, ProviderPool {
addProvider(msg.sender, p.totalAmountBonded);
emit ProviderAdded(msg.sender, _pricePerStorageMineral, _pricePerComputeMineral, _blockRewardCut, _feeShare);
} else {
updateProvider(msg.sender, p.totalAmountBonded);
emit ProviderUpdated(msg.sender, _pricePerStorageMineral, _pricePerComputeMineral, _blockRewardCut, _feeShare);
}
p.status = ProviderStatus.Registered;
Expand All @@ -72,7 +71,7 @@ contract TransmuteDPOS is TransmuteToken, RoundManager, ProviderPool {
p.feeShare = _feeShare;
}

function resignAsProvider() public {
function resignAsProvider() external {
require(providers[msg.sender].status != ProviderStatus.Unregistered);
removeProvider(msg.sender);
delete providers[msg.sender];
Expand All @@ -83,11 +82,15 @@ contract TransmuteDPOS is TransmuteToken, RoundManager, ProviderPool {
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
require(_provider == msg.sender || p.status != ProviderStatus.Unregistered);
require(_provider == msg.sender || p.status == ProviderStatus.Registered);
// Check if delegator has not already bonded to some address
require(delegators[msg.sender].delegateAddress == address(0));
this.transferFrom(msg.sender, this, _amount);
delegators[msg.sender] = Delegator(_provider, _amount);
p.totalAmountBonded = p.totalAmountBonded.add(_amount);
// Update the bonded amount of the provider in the pool
if (p.status == ProviderStatus.Registered) {
updateProvider(_provider, p.totalAmountBonded);
}
}
}
32 changes: 20 additions & 12 deletions test/TestTransmuteDPOS.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,12 @@ contract('TransmuteDPOS', accounts => {
await assertFail( approveBondProvider(20 ,10, 2, 25, 1, accounts[5]) );
});

it('should update the value of totalBondedAmount in the providerPool if the provider is Registered and size < maxSize', async () => {
// Check that provider is Registered
assert.equal(true, await tdpos.containsProvider(accounts[3]));
// Check the size of the pool stays the same
let providerPool = await tdpos.providerPool.call();
const previousSize = providerPool[3]; // [3] is current size of the pool
await tdpos.provider(19, 10, 2, 20, {from: accounts[3]});
providerPool = await tdpos.providerPool.call();
assert.deepEqual(previousSize, providerPool[3]);
});

it('should work if provider is Registered and size == maxSize', async () => {
let provider = await tdpos.providers.call(accounts[4]);
assert.equal(20, provider[1]); // [1] is pricePerStorageMineral
await tdpos.provider(21 ,10, 2, 25, {from: accounts[4]});
provider = await tdpos.providers.call(accounts[4]);
assert.equal(21, provider[1]);
});
});

Expand Down Expand Up @@ -267,11 +260,26 @@ contract('TransmuteDPOS', accounts => {
it("should transfer amount from the delegator's balance to the contract's balance", async () => {
const contractBalance = (await tdpos.balanceOf(tdpos.address)).toNumber();
assert.equal(1000, await tdpos.balanceOf(accounts[9]));
await tdpos.approve(contractAddress, 300, {from: accounts[9]});
await tdpos.bond(accounts[1], 300, {from: accounts[9]});
assert.equal(700, await tdpos.balanceOf(accounts[9]));
assert.equal(contractBalance + 300, await tdpos.balanceOf(tdpos.address));
});

it('should not affect the providerPool if provider is not registered', async() => {
assert.equal(false, await tdpos.containsProvider(accounts[2]));
await tdpos.approve(contractAddress, 300, {from: accounts[2]});
await tdpos.bond(accounts[2], 300, {from: accounts[2]});
assert.equal(false, await tdpos.containsProvider(accounts[2]));
});

it('should update the totalBondedAmount of the provider in the providerPool if he is already registered', async () => {
let provider = await tdpos.getProvider.call(accounts[0]);
let previousBondedAmount = provider[0].toNumber(); // [0] is bonded amount
await tdpos.approve(contractAddress, 300, {from: accounts[7]});
await tdpos.bond(accounts[0], 300, {from: accounts[7]});
provider = await tdpos.getProvider.call(accounts[0]);
assert.equal(300 + previousBondedAmount, provider[0]);
});
});
});

0 comments on commit 7df93fc

Please sign in to comment.