diff --git a/contracts/TransmuteDPOS.sol b/contracts/TransmuteDPOS.sol index afee2a8..c1dbf5f 100644 --- a/contracts/TransmuteDPOS.sol +++ b/contracts/TransmuteDPOS.sol @@ -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; @@ -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]; @@ -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); + } } } diff --git a/test/TestTransmuteDPOS.spec.js b/test/TestTransmuteDPOS.spec.js index 87ca883..0b74e04 100644 --- a/test/TestTransmuteDPOS.spec.js +++ b/test/TestTransmuteDPOS.spec.js @@ -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]); }); }); @@ -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]); + }); }); });