From b407f477071f26f897dc72028acf0c0544ff6a89 Mon Sep 17 00:00:00 2001 From: Oren Date: Tue, 29 Jan 2019 13:47:10 +0200 Subject: [PATCH] add wallet.sol --- contracts/test/Wallet.sol | 20 ++++++++++++++++++++ test/genericscheme.js | 20 ++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 contracts/test/Wallet.sol diff --git a/contracts/test/Wallet.sol b/contracts/test/Wallet.sol new file mode 100644 index 00000000..883b347d --- /dev/null +++ b/contracts/test/Wallet.sol @@ -0,0 +1,20 @@ +pragma solidity ^0.5.2; +import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; + + +contract Wallet is Ownable { + + event ReceiveEther(address indexed _sender, uint256 _value); + event Pay(address indexed _sender, uint256 _value); + + function() external payable { + emit ReceiveEther(msg.sender, msg.value); + } + + function pay(address payable _beneficiary) public onlyOwner { + uint256 amount = address(this).balance; + _beneficiary.transfer(amount); + emit Pay(_beneficiary, amount); + } + +} diff --git a/test/genericscheme.js b/test/genericscheme.js index 23697dd7..f876fc16 100644 --- a/test/genericscheme.js +++ b/test/genericscheme.js @@ -5,9 +5,8 @@ const GenericScheme = artifacts.require('./GenericScheme.sol'); const DaoCreator = artifacts.require("./DaoCreator.sol"); const ControllerCreator = artifacts.require("./ControllerCreator.sol"); const ERC20Mock = artifacts.require("./ERC20Mock.sol"); - - const ActionMock = artifacts.require("./ActionMock.sol"); +const Wallet = artifacts.require("./Wallet.sol"); export class GenericSchemeParams { constructor() { @@ -232,4 +231,21 @@ contract('genericScheme', function(accounts) { assert.equal(events[0].args._param,2); }); }); + + it("Wallet - execute proposeVote -positive decision - check action - with GenesisProtocol", async function() { + var wallet =await Wallet.new(); + await web3.eth.sendTransaction({from:accounts[0],to:wallet.address, value: web3.utils.toWei('1', "ether")}); + var standardTokenMock = await ERC20Mock.new(accounts[0],1000); + var testSetup = await setup(accounts,wallet.address,0,true,standardTokenMock.address); + var callData = await new web3.eth.Contract(wallet.abi).methods.pay(accounts[1]).encodeABI(); + var tx = await testSetup.genericScheme.proposeCall(testSetup.org.avatar.address,callData,helpers.NULL_HASH); + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId'); + assert.equal(await web3.eth.getBalance(wallet.address),web3.utils.toWei('1', "ether")); + await testSetup.genericSchemeParams.votingMachine.genesisProtocol.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]}); + assert.equal(await web3.eth.getBalance(wallet.address),web3.utils.toWei('1', "ether")); + await wallet.transferOwnership(testSetup.org.avatar.address); + await testSetup.genericScheme.execute(proposalId); + assert.equal(await web3.eth.getBalance(wallet.address),0); + }); + });