From 02443518df52dc62775d9ecfbd30a4dec300c183 Mon Sep 17 00:00:00 2001 From: Mikhail Kadysev Date: Tue, 5 Feb 2019 23:20:30 +0300 Subject: [PATCH] Additional deposit - withdraw possibilities --- contracts/EmmSharedNodes.sol | 16 ++++++++++++++-- test/2_emm_shared_nodes.js | 6 ++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/contracts/EmmSharedNodes.sol b/contracts/EmmSharedNodes.sol index 385993c..d3e0de2 100644 --- a/contracts/EmmSharedNodes.sol +++ b/contracts/EmmSharedNodes.sol @@ -78,7 +78,19 @@ contract EmmSharedNodes { // Coin management function() payable public { - // Here comes mining rewards + if (msg.value >= ONE_ETZ) { + deposit(); + } else if (msg.value == 0) { + withdraw(0); + } else { + revert(); + } + } + + function addReward() payable public { + } + + function returnCoins() payable public { } function accountsCount() public view returns (uint count) { @@ -263,7 +275,7 @@ contract EmmSharedNodeProxy { require(address(this).balance == 0); require(nodesContract.call.value(0)()); assert(address(this).balance == MASTERNODE_WITHDRAW); - owner.transfer(address(this).balance); + require(owner.call.value(address(this).balance)(bytes4(keccak256("returnCoins()")))); assert(address(this).balance == 0); active = false; } diff --git a/test/2_emm_shared_nodes.js b/test/2_emm_shared_nodes.js index 5ae6051..64da416 100644 --- a/test/2_emm_shared_nodes.js +++ b/test/2_emm_shared_nodes.js @@ -137,7 +137,7 @@ contract('Emm Shared Nodes', async (accounts) => { let proxy = EmmSharedNodeProxy.at(await emmSharedNodes.nodes(0)); assert.ok(await proxy.active()); - web3.eth.sendTransaction({ + emmSharedNodes.addReward({ from: accounts[5], to: emmSharedNodes.address, value: web3.toWei(100), @@ -169,11 +169,9 @@ contract('Emm Shared Nodes', async (accounts) => { assert.isNotNull(await emmSharedNodes.nodes(0)); let proxy = EmmSharedNodeProxy.at(await emmSharedNodes.nodes(0)); assert.ok(await proxy.active()); - assert.ok(balance(emmSharedNodes.address) < 20000, "Shared Nodes Contract balance too big"); let oldUserBalance = balance(accounts[1]); - await emmSharedNodes.withdraw(15000 * 10 ** 18, {from: accounts[1], gasLimit: 270000}); - + await emmSharedNodes.withdraw(15000 * 10 ** 18, {from: accounts[1], gasLimit: 2700000}); assert.ok(!await proxy.active(), "Node should be inactive"); assert.ok(Math.abs(oldUserBalance + 15000 - balance(accounts[1])) < 0.09, "User balance wrong") });