public async void Test() { var abi = "[{'constant':true,'inputs':[],'name':'InvestmentsCount','outputs':[{'name':'','type':'uint256'}],'payable':false,'type':'function'},{'constant':true,'inputs':[],'name':'GetAllInvestments','outputs':[{'name':'ids','type':'uint256[]'},{'name':'addresses','type':'address[]'},{'name':'chargerIds','type':'uint256[]'},{'name':'balances','type':'uint256[]'},{'name':'states','type':'bool[]'}],'payable':false,'type':'function'},{'constant':false,'inputs':[{'name':'_from','type':'address'},{'name':'_charger','type':'uint256'}],'name':'investInQueue','outputs':[{'name':'success','type':'bool'}],'payable':true,'type':'function'},{'constant':false,'inputs':[{'name':'_newCharge','type':'uint256'}],'name':'addCharge','outputs':[],'payable':false,'type':'function'},{'constant':true,'inputs':[],'name':'getChargers','outputs':[{'name':'chargers','type':'uint256[]'}],'payable':false,'type':'function'}]"; var byteCode = "0x60606040526108f2806100126000396000f3606060405260e060020a6000350463472ad331811461004a5780637996c88714610058578063b4821203146102ff578063dbda4c0814610400578063fa82518514610449575b610002565b34610002576104af60005481565b346100025760408051602080820183526000808352835180830185528181528451808401865282815285518085018752838152865180860188528481528751808701895285815288518088018a5286815289518089018b528781528a51808a018c528881528b51998a018c52888a5288549b516104c19c989a979996989597959694959394929391929087908059106100ee5750595b908082528060200260200182016040528015610105575b509550866040518059106101165750595b90808252806020026020018201604052801561012d575b5094508660405180591061013e5750595b908082528060200260200182016040528015610155575b509350866040518059106101665750595b90808252806020026020018201604052801561017d575b5092508660405180591061018e5750595b9080825280602002602001820160405280156101a5575b509150600090505b60005481101561065757600180548290811015610002579060005260206000209060050201600050548651879083908110156100025760209081029091010152600180548290811015610002579060005260206000209060050201600050600101548551600160a060020a03909116908690839081101561000257600160a060020a03909216602092830290910190910152600180548290811015610002579060005260206000209060050201600050600201600050548482815181101561000257602090810290910101526001805482908110156100025790600052602060002090600502016000506003016000505483828151811015610002576020908102909101015260018054829081101561000257906000526020600020906005020160005060040154825160ff9091169083908390811015610002579115156020928302909101909101526001016101ad565b6105f760043560243560008082151561032f57600280546000908110156100025760009182526020909120015492505b61066a84846040805160a081018252600080825260208201819052918101829052606081018290526080810182905281905b6000548210156106c05784600160a060020a0316600160005083815481101561000257906000526020600020906005020160005060010154600160a060020a03161480156103d1575083600160005083815481101561000257906000526020600020906005020160005060020154145b156107a7576001805483908110156100025790600052602060002090600502016000505492505b505092915050565b346100025761060b600435600280546001810180835582818380158290116106a6576000838152602090206106a69181019083015b808211156106bc5760008155600101610435565b34610002576040805160208082018352600082526002805484518184028101840190955280855261060d94928301828280156104a557602002820191906000526020600020905b81548152600190910190602001808311610490575b5050505050905090565b60408051918252519081900360200190f35b60405180806020018060200180602001806020018060200186810386528b8181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f15090500186810385528a8181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f1509050018681038452898181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f1509050018681038352888181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f1509050018681038252878181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f1509050019a505050505050505050505060405180910390f35b604080519115158252519081900360200190f35b005b60405180806020018281038252838181518152602001915080519060200190602002808383829060006004602084601f0104600302600f01f1509050019250505060405180910390f35b50939a9299509097509550909350915050565b905034600160005060018303815481101561000257906000526020600020906005020160005060030180549091019055600191505b5092915050565b5050506000928352506020909120018190555b50565b5090565b6107b2858560a06040519081016040528060008152602001600081526020016000815260200160008152602001600081526020015060a0604051908101604052806000815260200160008152602001600081526020016000815260200160008152602001506107bd8360008181526003602052604090205460ff60a060020a9091041615156106b9576000818152600360205260409020805474ff0000000000000000000000000000000000000000191660a060020a179055600280546001810180835582818380158290116106a6576000838152602090206106a6918101908301610435565b600190910190610361565b8051935090506103f8565b60008054600190810191829055600160a060020a0386166020840152604083018590529082528054808201808355828183801582901161085e5760050281600502836000526020600020918201910161085e91905b808211156106bc57600080825560018201805473ffffffffffffffffffffffffffffffffffffffff1916905560028201819055600382015560048101805460ff19169055600501610812565b50505060009283525060209182902083516005909202019081559082015160018201805473ffffffffffffffffffffffffffffffffffffffff19166c0100000000000000000000000092830292909204919091179055604082015160028201556060820151600382015560808201516004909101805460ff191660f860020a9283029290920491909117905590508061069f56"; var web3 = new Web3(ClientFactory.GetClient()); var gethTester = GethTesterFactory.GetLocal(web3); var receipt = await gethTester.DeployTestContractLocal(byteCode); var contract = web3.Eth.GetContract(abi, receipt.ContractAddress); var addChargeFunction = contract.GetFunction("addCharge"); //await gethTester.UnlockAccount(); await gethTester.StartMining(); var tx = await addChargeFunction.SendTransactionAsync(gethTester.Account, 20); tx = await addChargeFunction.SendTransactionAsync(gethTester.Account, 30); receipt = await gethTester.GetTransactionReceipt(tx); await gethTester.StopMining(); var chargers = contract.GetFunction("getChargers"); var result = await chargers.CallAsync <List <BigInteger> >(); Assert.Equal(20, result[0]); Assert.Equal(30, result[1]); }
public async void Test() { /* * contract Hashes{ * * function sha3Test(string _myvalue) returns (bytes32 val){ * return sha3(_myvalue); * } * * bytes32 public myHash; * * function storeMyHash(bytes32 _myHash){ * myHash = _myHash; * } * } */ var text = "code monkeys are great"; var hash = "0x1c21348936d43dc62d853ff6238cff94e361f8dcee9fde6fd5fbfed9ff663150"; var web3 = new Web3(ClientFactory.GetClient()); var sha3Hello = Web3.Sha3(text); Assert.Equal(hash, "0x" + sha3Hello); var contractByteCode = "0x6060604052610154806100126000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480632bb49eb71461004f5780637c886096146100bd578063b6f61649146100d55761004d565b005b6100a36004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509090919050506100fc565b604051808260001916815260200191505060405180910390f35b6100d3600480803590602001909190505061013d565b005b6100e2600480505061014b565b604051808260001916815260200191505060405180910390f35b600081604051808280519060200190808383829060006004602084601f0104600f02600301f15090500191505060405180910390209050610138565b919050565b806000600050819055505b50565b6000600050548156"; var abi = @"[{""constant"":false,""inputs"":[{""name"":""_myvalue"",""type"":""string""}],""name"":""sha3Test"",""outputs"":[{""name"":""val"",""type"":""bytes32""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""_myHash"",""type"":""bytes32""}],""name"":""storeMyHash"",""outputs"":[],""type"":""function""},{""constant"":true,""inputs"":[],""name"":""myHash"",""outputs"":[{""name"":"""",""type"":""bytes32""}],""type"":""function""}]"; var gethTester = GethTesterFactory.GetLocal(web3); var receipt = await gethTester.DeployTestContractLocal(contractByteCode); //"0x350b79547251fdb18b64ec17cf3783e7d854bd30" (prev deployed contract) var contract = web3.Eth.GetContract(abi, receipt.ContractAddress); var sha3Function = contract.GetFunction("sha3Test"); var result = await sha3Function.CallAsync <byte[]>(text); Assert.Equal(hash, "0x" + result.ToHex()); var storeMyHash = contract.GetFunction("storeMyHash"); await gethTester.UnlockAccount(); var gas = await storeMyHash.EstimateGasAsync(gethTester.Account, null, null, hash.HexToByteArray()); var txn = await storeMyHash.SendTransactionAsync(gethTester.Account, gas, null, hash.HexToByteArray()); await gethTester.GetTransactionReceipt(txn); var myHashFuction = contract.GetFunction("myHash"); result = await myHashFuction.CallAsync <byte[]>(); Assert.Equal(hash, "0x" + result.ToHex()); }
public async void Test() { var contractByteCode = "0x60606040526040516020806106f5833981016040528080519060200190919050505b80600160005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005081905550806000600050819055505b506106868061006f6000396000f360606040523615610074576000357c010000000000000000000000000000000000000000000000000000000090048063095ea7b31461008157806318160ddd146100b657806323b872dd146100d957806370a0823114610117578063a9059cbb14610143578063dd62ed3e1461017857610074565b61007f5b610002565b565b005b6100a060048080359060200190919080359060200190919050506101ad565b6040518082815260200191505060405180910390f35b6100c36004805050610674565b6040518082815260200191505060405180910390f35b6101016004808035906020019091908035906020019091908035906020019091905050610281565b6040518082815260200191505060405180910390f35b61012d600480803590602001909190505061048d565b6040518082815260200191505060405180910390f35b61016260048080359060200190919080359060200190919050506104cb565b6040518082815260200191505060405180910390f35b610197600480803590602001909190803590602001909190505061060b565b6040518082815260200191505060405180910390f35b600081600260005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905061027b565b92915050565b600081600160005060008673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541015801561031b575081600260005060008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505410155b80156103275750600082115b1561047c5781600160005060008573ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a381600160005060008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282825054039250508190555081600260005060008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505403925050819055506001905061048656610485565b60009050610486565b5b9392505050565b6000600160005060008373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505490506104c6565b919050565b600081600160005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541015801561050c5750600082115b156105fb5781600160005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282825054039250508190555081600160005060008573ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828282505401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905061060556610604565b60009050610605565b5b92915050565b6000600260005060008473ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060008373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005054905061066e565b92915050565b60006000600050549050610683565b9056"; var abi = @"[{""constant"":false,""inputs"":[{""name"":""_spender"",""type"":""address""},{""name"":""_value"",""type"":""uint256""}],""name"":""approve"",""outputs"":[{""name"":""success"",""type"":""bool""}],""type"":""function""},{""constant"":true,""inputs"":[],""name"":""totalSupply"",""outputs"":[{""name"":""supply"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""_from"",""type"":""address""},{""name"":""_to"",""type"":""address""},{""name"":""_value"",""type"":""uint256""}],""name"":""transferFrom"",""outputs"":[{""name"":""success"",""type"":""bool""}],""type"":""function""},{""constant"":true,""inputs"":[{""name"":""_owner"",""type"":""address""}],""name"":""balanceOf"",""outputs"":[{""name"":""balance"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""_to"",""type"":""address""},{""name"":""_value"",""type"":""uint256""}],""name"":""transfer"",""outputs"":[{""name"":""success"",""type"":""bool""}],""type"":""function""},{""constant"":true,""inputs"":[{""name"":""_owner"",""type"":""address""},{""name"":""_spender"",""type"":""address""}],""name"":""allowance"",""outputs"":[{""name"":""remaining"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""_initialAmount"",""type"":""uint256""}],""type"":""constructor""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""_from"",""type"":""address""},{""indexed"":true,""name"":""_to"",""type"":""address""},{""indexed"":false,""name"":""_value"",""type"":""uint256""}],""name"":""Transfer"",""type"":""event""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""_owner"",""type"":""address""},{""indexed"":true,""name"":""_spender"",""type"":""address""},{""indexed"":false,""name"":""_value"",""type"":""uint256""}],""name"":""Approval"",""type"":""event""}]"; var web3 = new Web3(ClientFactory.GetClient()); var gethTester = GethTesterFactory.GetLocal(web3); ulong totalSupply = 1000000; var receipt = await gethTester.DeployTestContractLocal(abi, contractByteCode, totalSupply); string pass = "******"; await web3.Personal.UnlockAccount.SendRequestAsync(gethTester.Account, pass, 60); var newAddress = await web3.Personal.NewAccount.SendRequestAsync(pass); Assert.NotNull(newAddress); var contract = web3.Eth.GetContract(abi, receipt.ContractAddress); var transferFunction = contract.GetFunction("transfer"); var balanceFunction = contract.GetFunction("balanceOf"); var transactionService = new TransactionReceiptPollingService(web3); var gethWeb3 = new Web3Geth(web3.Client); await gethWeb3.Miner.Start.SendRequestAsync(6); var receiptFirstBlock = await transactionService.SendRequestAsync(() => transferFunction.SendTransactionAsync(gethTester.Account, newAddress, 1000)); var balanceFirstBlock = await balanceFunction.CallAsync <int>(newAddress); var receiptSecondBlock = await transactionService.SendRequestAsync(() => transferFunction.SendTransactionAsync(gethTester.Account, newAddress, 1000)); var balanceSecondBlock = await balanceFunction.CallAsync <int>(newAddress); var balanceOldBlock = await balanceFunction.CallAsync <int>( new BlockParameter(receiptFirstBlock.BlockNumber), newAddress); await gethWeb3.Miner.Stop.SendRequestAsync(); Assert.Equal(2000, balanceSecondBlock); Assert.Equal(1000, balanceOldBlock); Assert.Equal(1000, balanceFirstBlock); }