Skip to content

Commit

Permalink
Additional deposit - withdraw possibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
neonomaly committed Feb 5, 2019
1 parent ca0863b commit 0244351
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 14 additions & 2 deletions contracts/EmmSharedNodes.sol
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 2 additions & 4 deletions test/2_emm_shared_nodes.js
Expand Up @@ -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),
Expand Down Expand Up @@ -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")
});
Expand Down

0 comments on commit 0244351

Please sign in to comment.