├── .gitignore ├── ISSUE_TEMPLATE.zh-CN.md ├── LICENSE ├── PULL_REQUEST_TEMPLATE.zh-CN.md ├── README.md ├── app ├── bank.html ├── customer.html ├── index.html ├── javascripts │ ├── app.js │ ├── bank.js │ ├── customer.js │ ├── merchant.js │ └── utils.js ├── merchant.html └── stylesheets │ └── app.css ├── build ├── app.css ├── app.js ├── bank.html ├── contracts │ ├── Score.sol.js │ └── Utils.sol.js ├── customer.html ├── index.html └── merchant.html ├── contracts └── Score.sol ├── migrations └── 2_deploy_contracts.js ├── test └── metacoin.js ├── truffle.js └── web3js ├── .bowerrc ├── .editorconfig ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── .versions ├── LICENSE ├── README.md ├── bower.json ├── dist ├── web3-light.js ├── web3-light.min.js ├── web3.js ├── web3.js.map └── web3.min.js ├── example ├── balance.html ├── contract.html ├── contract_array.html ├── event_inc.html ├── icap.html ├── namereg.html └── node-app.js ├── gulpfile.js ├── index.js ├── lib ├── contracts │ ├── GlobalRegistrar.json │ ├── ICAPRegistrar.json │ └── SmartExchange.json ├── solidity │ ├── address.js │ ├── bool.js │ ├── bytes.js │ ├── coder.js │ ├── dynamicbytes.js │ ├── formatters.js │ ├── int.js │ ├── param.js │ ├── real.js │ ├── string.js │ ├── type.js │ ├── uint.js │ └── ureal.js ├── utils │ ├── browser-bn.js │ ├── browser-xhr.js │ ├── config.js │ ├── sha3.js │ └── utils.js ├── version.json ├── web3.js └── web3 │ ├── allevents.js │ ├── batch.js │ ├── contract.js │ ├── errors.js │ ├── event.js │ ├── extend.js │ ├── filter.js │ ├── formatters.js │ ├── function.js │ ├── httpprovider.js │ ├── iban.js │ ├── ipcprovider.js │ ├── jsonrpc.js │ ├── method.js │ ├── methods │ ├── db.js │ ├── eth.js │ ├── net.js │ ├── personal.js │ ├── shh.js │ └── watches.js │ ├── namereg.js │ ├── property.js │ ├── requestmanager.js │ ├── settings.js │ ├── syncing.js │ └── transfer.js ├── package-init.js ├── package.js ├── package.json ├── styleguide.md └── test ├── async.js ├── batch.js ├── coder.decodeParam.js ├── coder.encodeParam.js ├── contract.js ├── errors.js ├── event.decode.js ├── event.encode.js ├── formatters.inputAddressFormatter.js ├── formatters.inputDefaultBlockFormatter.js ├── formatters.inputPostFormatter.js ├── formatters.inputTransactionFormatter.js ├── formatters.outputBlockFormatter.js ├── formatters.outputLogFormatter.js ├── formatters.outputPostFormatter.js ├── formatters.outputTransactionFormatter.js ├── helpers ├── FakeHttpProvider.js ├── FakeHttpProvider2.js ├── FakeIpcRequest.js ├── FakeQtNavigator.js ├── FakeXMLHttpRequest.js ├── test.method.js └── test.utils.js ├── httpprovider.js ├── iban.createIndirect.js ├── iban.fromAddress.js ├── iban.isValid.js ├── iban.toAddress.js ├── ipcprovider.js ├── jsonrpc.id.js ├── jsonrpc.isValidResponse.js ├── jsonrpc.toBatchPayload.js ├── jsonrpc.toPayload.js ├── method.extractCallback.js ├── method.formatInput.js ├── method.formatOutput.js ├── method.getCall.js ├── method.validateArgs.js ├── mocha.opts ├── node ├── app.js └── package.json ├── polling.js ├── requestmanager.js ├── sha3.js ├── utils.extractDisplayName.js ├── utils.extractTypeName.js ├── utils.fromAscii.js ├── utils.fromDecimal.js ├── utils.fromUtf8.js ├── utils.fromWei.js ├── utils.isAddress.js ├── utils.isBigNumber.js ├── utils.isChecksumAddress.js ├── utils.isFunction.js ├── utils.isJson.js ├── utils.isStrictAddress.js ├── utils.isString.js ├── utils.toAscii.js ├── utils.toBigNumber.js ├── utils.toDecimal.js ├── utils.toHex.js ├── utils.toUtf8.js ├── utils.toWei.js ├── web3.db.getHex.js ├── web3.db.getString.js ├── web3.db.methods.js ├── web3.db.putHex.js ├── web3.db.putString.js ├── web3.eth.accounts.js ├── web3.eth.blockNumber.js ├── web3.eth.call.js ├── web3.eth.coinbase.js ├── web3.eth.contract.js ├── web3.eth.defaultBlock.js ├── web3.eth.estimateGas.js ├── web3.eth.filter.js ├── web3.eth.gasPrice.js ├── web3.eth.getBalance.js ├── web3.eth.getBlock.js ├── web3.eth.getBlockTransactionCount.js ├── web3.eth.getBlockUncleCount.js ├── web3.eth.getCode.js ├── web3.eth.getCompilers.js ├── web3.eth.getStorageAt.js ├── web3.eth.getTransaction.js ├── web3.eth.getTransactionFromBlock.js ├── web3.eth.getTransactionReceipt.js ├── web3.eth.getUncle.js ├── web3.eth.getWork.js ├── web3.eth.hashRate.js ├── web3.eth.isSyncing.js ├── web3.eth.methods.js ├── web3.eth.mining.js ├── web3.eth.sendIBANTransaction.js ├── web3.eth.submitWork.js ├── web3.extend.js ├── web3.fromICAP.js ├── web3.methods.js ├── web3.net.listening.js ├── web3.net.methods.js ├── web3.net.peerCount.js ├── web3.personal.listAccounts.js ├── web3.personal.methods.js ├── web3.personal.newAccount.js ├── web3.personal.unlockAccount.js ├── web3.sha3.js ├── web3.shh.filter.js ├── web3.shh.hasIdentity.js ├── web3.shh.methods.js └── web3.shh.post.js /.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | .idea 3 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.zh-CN.md: -------------------------------------------------------------------------------- 1 | ## 该问题是怎么引起的? 2 | 3 | 4 | 5 | ## 重现步骤 6 | 7 | 8 | 9 | ## 报错信息 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 chenyufeng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.zh-CN.md: -------------------------------------------------------------------------------- 1 | ## 该Pull Request关联的Issue 2 | 3 | 4 | ## 修改描述 5 | 6 | 7 | 8 | ## 测试用例 9 | 10 | 11 | 12 | ## 修复效果的截屏 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Score 2 | 基于以太坊的通用积分系统案例 3 | 4 | note:该版本代码在Truffle v4.1.11 (core: 4.1.11), Solidity v0.4.24 (solc-js)上存在一定问题;故对此项目进行了重构,新版本请查看https://github.com/Blockchain-book/Ethereum-Score-Hella 5 | 6 | -------------------------------------------------------------------------------- /app/bank.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 银行管理员 6 | 7 | 8 | 9 | 15 | 16 | 17 | 18 |


19 |
20 |
21 | 22 |



23 |
24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/customer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 用户 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | 21 |


22 |
23 |
24 | 25 |


26 |
27 | 28 |
29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Score 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |


15 |
16 |
17 | 18 | 19 |


20 |
21 |
22 | 23 | 24 |


25 |
26 |
27 | 28 | 29 |


30 |
31 |
32 | 33 | 34 |


35 |
36 |
37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/javascripts/bank.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by chenyufeng on 12/22/16. 3 | */ 4 | 5 | function sendScoreToCustomer() { 6 | 7 | var address = document.getElementById("customerAddress").value; 8 | var score = document.getElementById("scoreAmount").value; 9 | 10 | console.log(address); 11 | console.log(score); 12 | 13 | contractAddr.sendScoreToCustomer(address, score, {from: account}); 14 | var eventSendScoreToCustomer = contractAddr.SendScoreToCustomer(); 15 | eventSendScoreToCustomer.watch(function (error, event) { 16 | console.log(event.args.message); 17 | alert(event.args.message); 18 | 19 | eventSendScoreToCustomer.stopWatching(); 20 | }); 21 | } 22 | 23 | function getIssuedScoreAmount() { 24 | contractAddr.getIssuedScoreAmount({from: account}).then(function (result) { 25 | alert("已发行的积分总数为:" + result); 26 | }); 27 | } 28 | 29 | function getSettledScoreAmount() { 30 | contractAddr.getSettledScoreAmount({from: account}).then(function (result) { 31 | alert("已清算的积分总数为:" + result); 32 | }); 33 | } -------------------------------------------------------------------------------- /app/javascripts/customer.js: -------------------------------------------------------------------------------- 1 | //根据客户address获取积分余额 2 | function getScoreWithCustomerAddr() { 3 | console.log(currentAccount); 4 | contractAddr.getScoreWithCustomerAddr.call(currentAccount, {from: account}).then(function(value) { 5 | alert("当前余额:" + value.valueOf()); 6 | }).catch(function(e) { 7 | console.log(e); 8 | alert("出现异常,查询余额失败!"); 9 | }); 10 | } 11 | 12 | function getCurrentCustomer() { 13 | alert(currentAccount); 14 | } 15 | 16 | //客户实现任意的积分转让 17 | function transferScoreToAnotherFromCustomer() { 18 | var receivedAddr = document.getElementById("anotherAddress").value; 19 | var amount = parseInt(document.getElementById("scoreAmount").value); 20 | contractAddr.transferScoreToAnother(0, currentAccount, receivedAddr, amount, {from: account}); 21 | var eventTransferScoreToAnother = contractAddr.TransferScoreToAnother(); 22 | eventTransferScoreToAnother.watch(function (error, event) { 23 | console.log(event.args.message); 24 | alert(event.args.message); 25 | 26 | eventTransferScoreToAnother.stopWatching(); 27 | }); 28 | } 29 | 30 | //客户购买商品 31 | function buyGood() { 32 | var goodId = document.getElementById("goodId").value; 33 | contractAddr.buyGood(currentAccount, goodId, {from: account, gas: 1000000}).then(function () { 34 | var eventBuyGood = contractAddr.BuyGood(); 35 | eventBuyGood.watch(function (error, event) { 36 | console.log(event.args.message); 37 | alert(event.args.message); 38 | 39 | eventBuyGood.stopWatching(); 40 | }); 41 | }); 42 | } 43 | 44 | //查看已经购买的商品 45 | function getGoodsByCustomer() { 46 | contractAddr.getGoodsByCustomer.call(currentAccount, {from: account}).then(function (result) { 47 | console.log(result.length); 48 | console.log(result); 49 | 50 | for (var i = 0; i < result.length; i++){ 51 | var temp = hexCharCodeToStr(result[i]); 52 | console.log(temp); 53 | } 54 | }); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /app/javascripts/merchant.js: -------------------------------------------------------------------------------- 1 | //根据商户address获取积分余额 2 | function getScoreWithMerchantAddr() { 3 | console.log(currentAccount); 4 | contractAddr.getScoreWithMerchantAddr.call(currentAccount, {from: account}).then(function(value) { 5 | alert("当前余额:" + value.valueOf()); 6 | }).catch(function(e) { 7 | console.log(e); 8 | alert("出现异常,查询余额失败!"); 9 | }); 10 | } 11 | 12 | function getCurrentMerchant() { 13 | alert(currentAccount); 14 | } 15 | 16 | //商户实现任意的积分转让 17 | function transferScoreToAnotherFromMerchant() { 18 | var receivedAddr = document.getElementById("anotherAccountAddr").value; 19 | var amount = parseInt(document.getElementById("scoreAmount").value); 20 | contractAddr.transferScoreToAnother(1, currentAccount, receivedAddr, amount, {from: account}); 21 | var eventTransferScoreToAnother = contractAddr.TransferScoreToAnother(); 22 | eventTransferScoreToAnother.watch(function (error, event) { 23 | console.log(event.args.message); 24 | alert(event.args.message); 25 | 26 | eventTransferScoreToAnother.stopWatching(); 27 | }); 28 | } 29 | 30 | //商户增加一件商品:默认gas会OOG 31 | function addGood() { 32 | var goodId = document.getElementById("goodId").value; 33 | var goodPrice = parseInt(document.getElementById("goodPrice").value); 34 | contractAddr.addGood(currentAccount, goodId, goodPrice, {from: account, gas: 2000000}).then(function () { 35 | var eventAddGood = contractAddr.AddGood(); 36 | eventAddGood.watch(function (error, event) { 37 | console.log(event.args.message); 38 | alert(event.args.message); 39 | eventAddGood.stopWatching(); 40 | }); 41 | }); 42 | } 43 | 44 | //商户查看已添加的所有商品 45 | function getGoodsByMerchant() { 46 | contractAddr.getGoodsByMerchant.call(currentAccount, {from: account}).then(function (result) { 47 | console.log(result.length); 48 | console.log(result); 49 | 50 | for (var i = 0; i < result.length; i++){ 51 | var temp = hexCharCodeToStr(result[i]).toString(); 52 | console.log(temp); 53 | } 54 | }); 55 | } 56 | 57 | //商户和银行进行积分清算 58 | function settleScoreWithBank() { 59 | var settleAmount = parseInt(document.getElementById("settleAmount").value); 60 | contractAddr.settleScoreWithBank(currentAccount, settleAmount, {from: account}).then(function() { 61 | var eventSettleScoreWithBank = contractAddr.SettleScoreWithBank(); 62 | eventSettleScoreWithBank.watch(function (error, event) { 63 | console.log(event.args.message); 64 | alert(event.args.message); 65 | eventSettleScoreWithBank.stopWatching(); 66 | }); 67 | }).catch(function(e) { 68 | console.log(e); 69 | setStatus("清算积分失败"); 70 | }); 71 | } -------------------------------------------------------------------------------- /app/javascripts/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by chenyufeng on 12/24/16. 3 | */ 4 | //十六进制转化为字符串 5 | function hexCharCodeToStr(hexCharCodeStr) { 6 | var trimedStr = hexCharCodeStr.trim(); 7 | var rawStr = 8 | trimedStr.substr(0,2).toLowerCase() === "0x" ? trimedStr.substr(2) : trimedStr; 9 | var len = rawStr.length; 10 | if(len % 2 !== 0) { 11 | alert("Illegal Format ASCII Code!"); 12 | return ""; 13 | } 14 | var curCharCode; 15 | var resultStr = []; 16 | for(var i = 0; i < len;i = i + 2) { 17 | curCharCode = parseInt(rawStr.substr(i, 2), 16); // ASCII Code Value 18 | resultStr.push(String.fromCharCode(curCharCode)); 19 | } 20 | return resultStr.join(""); 21 | } -------------------------------------------------------------------------------- /app/merchant.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 商户 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | 21 |


22 |
23 |
24 | 25 |


26 |
27 |
28 | 29 |
30 | 31 |


32 |
33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/stylesheets/app.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-left: 25%; 3 | margin-right: 25%; 4 | margin-top: 5%; 5 | font-family: "Open Sans", sans-serif; 6 | } 7 | 8 | label { 9 | display: inline-block; 10 | width: 150px; 11 | } 12 | 13 | input { 14 | width: 500px; 15 | padding: 5px; 16 | font-size: 16px; 17 | } 18 | 19 | button { 20 | font-size: 16px; 21 | padding: 5px; 22 | } 23 | 24 | h1, h2 { 25 | display: inline-block; 26 | vertical-align: middle; 27 | margin-top: 0px; 28 | margin-bottom: 10px; 29 | } 30 | 31 | h2 { 32 | color: #AAA; 33 | font-size: 32px; 34 | } 35 | 36 | h3 { 37 | font-weight: normal; 38 | color: #AAA; 39 | font-size: 24px; 40 | } 41 | 42 | .black { 43 | color: black; 44 | } 45 | 46 | #balance { 47 | color: black; 48 | } 49 | -------------------------------------------------------------------------------- /build/app.css: -------------------------------------------------------------------------------- 1 | 2 | 3 | body { 4 | margin-left: 25%; 5 | margin-right: 25%; 6 | margin-top: 5%; 7 | font-family: "Open Sans", sans-serif; 8 | } 9 | 10 | label { 11 | display: inline-block; 12 | width: 150px; 13 | } 14 | 15 | input { 16 | width: 500px; 17 | padding: 5px; 18 | font-size: 16px; 19 | } 20 | 21 | button { 22 | font-size: 16px; 23 | padding: 5px; 24 | } 25 | 26 | h1, h2 { 27 | display: inline-block; 28 | vertical-align: middle; 29 | margin-top: 0px; 30 | margin-bottom: 10px; 31 | } 32 | 33 | h2 { 34 | color: #AAA; 35 | font-size: 32px; 36 | } 37 | 38 | h3 { 39 | font-weight: normal; 40 | color: #AAA; 41 | font-size: 24px; 42 | } 43 | 44 | .black { 45 | color: black; 46 | } 47 | 48 | #balance { 49 | color: black; 50 | } 51 | -------------------------------------------------------------------------------- /build/bank.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 银行管理员 8 | 9 | 10 | 11 | 17 | 18 | 19 | 20 |


21 |
22 |
23 | 24 |



25 |
26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /build/customer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 用户 7 | 8 | 9 | 10 | 16 | 17 | 18 | 19 | 20 |
21 |
22 | 23 |


24 |
25 |
26 | 27 |


28 |
29 | 30 |
31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /build/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Score 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |


17 |
18 |
19 | 20 | 21 |


22 |
23 |
24 | 25 | 26 |


27 |
28 |
29 | 30 | 31 |


32 |
33 |
34 | 35 | 36 |


37 |
38 |
39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /build/merchant.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 商户 7 | 8 | 9 | 10 | 16 | 17 | 18 | 19 | 20 |
21 |
22 | 23 |


24 |
25 |
26 | 27 |


28 |
29 |
30 | 31 |
32 | 33 |


34 |
35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | module.exports = function(deployer) { 2 | deployer.deploy(Score); 3 | }; 4 | -------------------------------------------------------------------------------- /test/metacoin.js: -------------------------------------------------------------------------------- 1 | contract('MetaCoin', function(accounts) { 2 | it("should put 10000 MetaCoin in the first account", function() { 3 | var meta = MetaCoin.deployed(); 4 | 5 | return meta.getBalance.call(accounts[0]).then(function(balance) { 6 | assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account"); 7 | }); 8 | }); 9 | it("should call a function that depends on a linked library", function() { 10 | var meta = MetaCoin.deployed(); 11 | var metaCoinBalance; 12 | var metaCoinEthBalance; 13 | 14 | return meta.getBalance.call(accounts[0]).then(function(outCoinBalance) { 15 | metaCoinBalance = outCoinBalance.toNumber(); 16 | return meta.getBalanceInEth.call(accounts[0]); 17 | }).then(function(outCoinBalanceEth) { 18 | metaCoinEthBalance = outCoinBalanceEth.toNumber(); 19 | }).then(function() { 20 | assert.equal(metaCoinEthBalance, 2 * metaCoinBalance, "Library function returned unexpeced function, linkage may be broken"); 21 | }); 22 | }); 23 | it("should send coin correctly", function() { 24 | var meta = MetaCoin.deployed(); 25 | 26 | // Get initial balances of first and second account. 27 | var account_one = accounts[0]; 28 | var account_two = accounts[1]; 29 | 30 | var account_one_starting_balance; 31 | var account_two_starting_balance; 32 | var account_one_ending_balance; 33 | var account_two_ending_balance; 34 | 35 | var amount = 10; 36 | 37 | return meta.getBalance.call(account_one).then(function(balance) { 38 | account_one_starting_balance = balance.toNumber(); 39 | return meta.getBalance.call(account_two); 40 | }).then(function(balance) { 41 | account_two_starting_balance = balance.toNumber(); 42 | return meta.sendCoin(account_two, amount, {from: account_one}); 43 | }).then(function() { 44 | return meta.getBalance.call(account_one); 45 | }).then(function(balance) { 46 | account_one_ending_balance = balance.toNumber(); 47 | return meta.getBalance.call(account_two); 48 | }).then(function(balance) { 49 | account_two_ending_balance = balance.toNumber(); 50 | 51 | assert.equal(account_one_ending_balance, account_one_starting_balance - amount, "Amount wasn't correctly taken from the sender"); 52 | assert.equal(account_two_ending_balance, account_two_starting_balance + amount, "Amount wasn't correctly sent to the receiver"); 53 | }); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | build: { 3 | "index.html": "index.html", 4 | "customer.html": "customer.html", 5 | "bank.html": "bank.html", 6 | "merchant.html": "merchant.html", 7 | "app.js": [ 8 | "javascripts/app.js", 9 | "javascripts/customer.js", 10 | "javascripts/bank.js", 11 | "javascripts/merchant.js", 12 | "javascripts/utils.js" 13 | ], 14 | "app.css": [ 15 | "stylesheets/app.css" 16 | ], 17 | "images/": "images/" 18 | }, 19 | rpc: { 20 | host: "localhost", 21 | port: 8545 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /web3js/.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "bower", 3 | "cwd": "./", 4 | "analytics": false 5 | } 6 | -------------------------------------------------------------------------------- /web3js/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /web3js/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile ~/.gitignore_global 6 | 7 | *.swp 8 | /coverage 9 | /tmp 10 | */**/*un~ 11 | *un~ 12 | .DS_Store 13 | */**/.DS_Store 14 | ethereum/ethereum 15 | ethereal/ethereal 16 | example/js 17 | node_modules 18 | bower_components 19 | npm-debug.log 20 | /bower 21 | .npm/ 22 | -------------------------------------------------------------------------------- /web3js/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "browserify": true, 3 | "bitwise": true, 4 | "camelcase": true, 5 | "eqeqeq": true, 6 | "freeze": true, 7 | "funcscope": false, 8 | "maxcomplexity": 4, /* our target is 3! */ 9 | "maxdepth": 3, 10 | "maxerr": 50, 11 | /*"maxlen": 80*/ /*this should be our goal*/ 12 | /*"maxparams": 3,*/ 13 | "nonew": true, 14 | "unused": true, 15 | "undef": true, 16 | "predef": [ 17 | "console" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /web3js/.npmignore: -------------------------------------------------------------------------------- 1 | example/js 2 | node_modules 3 | test 4 | .gitignore 5 | .editorconfig 6 | .travis.yml 7 | .npmignore 8 | component.json 9 | testling.html -------------------------------------------------------------------------------- /web3js/.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4.1" 4 | - "4.0" 5 | before_script: 6 | - npm install 7 | - npm install jshint 8 | - export DISPLAY=:99.0 9 | - sh -e /etc/init.d/xvfb start 10 | script: 11 | - "jshint *.js lib" 12 | after_script: 13 | - npm run-script build 14 | - npm run-script test-coveralls 15 | - cd test/node && npm install && node app.js 16 | 17 | -------------------------------------------------------------------------------- /web3js/.versions: -------------------------------------------------------------------------------- 1 | ethereum:web3@0.17.0-alpha 2 | meteor@1.1.14 3 | underscore@1.0.8 4 | -------------------------------------------------------------------------------- /web3js/LICENSE: -------------------------------------------------------------------------------- 1 | This file is part of web3.js. 2 | 3 | web3.js is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | web3.js is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Lesser General Public License for more details. 12 | 13 | You should have received a copy of the GNU Lesser General Public License 14 | along with web3.js. If not, see . 15 | -------------------------------------------------------------------------------- /web3js/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web3", 3 | "namespace": "ethereum", 4 | "version": "0.17.0-alpha", 5 | "description": "Ethereum Compatible JavaScript API", 6 | "main": [ 7 | "./dist/web3.js", 8 | "./dist/web3.min.js" 9 | ], 10 | "dependencies": { 11 | "bignumber.js": ">=2.0.0", 12 | "crypto-js": "~3.1.4" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/ethereum/web3.js.git" 17 | }, 18 | "homepage": "https://github.com/ethereum/web3.js", 19 | "bugs": { 20 | "url": "https://github.com/ethereum/web3.js/issues" 21 | }, 22 | "keywords": [ 23 | "ethereum", 24 | "javascript", 25 | "API" 26 | ], 27 | "authors": [ 28 | { 29 | "name": "Marek Kotewicz", 30 | "email": "marek@ethdev.com", 31 | "homepage": "https://github.com/debris" 32 | }, 33 | { 34 | "name": "Marian Oancea", 35 | "email": "marian@ethdev.com", 36 | "homepage": "https://github.com/cubedro" 37 | }, 38 | { 39 | "name": "Fabian Vogelsteller", 40 | "email": "fabian@ethdev.com", 41 | "homepage": "https://github.com/frozeman" 42 | } 43 | ], 44 | "license": "LGPL-3.0", 45 | "ignore": [ 46 | "example", 47 | "lib", 48 | "node_modules", 49 | "package.json", 50 | "package.js", 51 | ".versions", 52 | ".bowerrc", 53 | ".editorconfig", 54 | ".gitignore", 55 | ".jshintrc", 56 | ".npmignore", 57 | ".travis.yml", 58 | "gulpfile.js", 59 | "index.js", 60 | "**/*.txt" 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /web3js/example/balance.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 29 | 30 | 31 | 32 |

coinbase balance

33 | 34 |
35 |
36 |
37 |
38 |
39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /web3js/example/contract.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 63 | 64 | 65 |

contract

66 |
67 |
68 |
69 | 70 |
71 | 74 |
75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /web3js/example/contract_array.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 63 | 64 | 65 |

contract

66 |
67 |
68 |
69 | 70 |
71 | 78 |
79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /web3js/example/event_inc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 74 | 75 | 76 | 77 |
78 |
79 | 80 |
81 |
82 | 83 |
84 |
85 |
86 |
87 | 88 | 89 | -------------------------------------------------------------------------------- /web3js/example/node-app.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var Web3 = require('../index.js'); 4 | var web3 = new Web3(); 5 | 6 | web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); 7 | 8 | var coinbase = web3.eth.coinbase; 9 | console.log(coinbase); 10 | 11 | var balance = web3.eth.getBalance(coinbase); 12 | console.log(balance.toString(10)); 13 | 14 | -------------------------------------------------------------------------------- /web3js/index.js: -------------------------------------------------------------------------------- 1 | var Web3 = require('./lib/web3'); 2 | 3 | // dont override global variable 4 | if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 5 | window.Web3 = Web3; 6 | } 7 | 8 | module.exports = Web3; 9 | -------------------------------------------------------------------------------- /web3js/lib/contracts/ICAPRegistrar.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": true, 4 | "inputs": [ 5 | { 6 | "name": "_name", 7 | "type": "bytes32" 8 | } 9 | ], 10 | "name": "owner", 11 | "outputs": [ 12 | { 13 | "name": "", 14 | "type": "address" 15 | } 16 | ], 17 | "type": "function" 18 | }, 19 | { 20 | "constant": false, 21 | "inputs": [ 22 | { 23 | "name": "_name", 24 | "type": "bytes32" 25 | }, 26 | { 27 | "name": "_refund", 28 | "type": "address" 29 | } 30 | ], 31 | "name": "disown", 32 | "outputs": [], 33 | "type": "function" 34 | }, 35 | { 36 | "constant": true, 37 | "inputs": [ 38 | { 39 | "name": "_name", 40 | "type": "bytes32" 41 | } 42 | ], 43 | "name": "addr", 44 | "outputs": [ 45 | { 46 | "name": "", 47 | "type": "address" 48 | } 49 | ], 50 | "type": "function" 51 | }, 52 | { 53 | "constant": false, 54 | "inputs": [ 55 | { 56 | "name": "_name", 57 | "type": "bytes32" 58 | } 59 | ], 60 | "name": "reserve", 61 | "outputs": [], 62 | "type": "function" 63 | }, 64 | { 65 | "constant": false, 66 | "inputs": [ 67 | { 68 | "name": "_name", 69 | "type": "bytes32" 70 | }, 71 | { 72 | "name": "_newOwner", 73 | "type": "address" 74 | } 75 | ], 76 | "name": "transfer", 77 | "outputs": [], 78 | "type": "function" 79 | }, 80 | { 81 | "constant": false, 82 | "inputs": [ 83 | { 84 | "name": "_name", 85 | "type": "bytes32" 86 | }, 87 | { 88 | "name": "_a", 89 | "type": "address" 90 | } 91 | ], 92 | "name": "setAddr", 93 | "outputs": [], 94 | "type": "function" 95 | }, 96 | { 97 | "anonymous": false, 98 | "inputs": [ 99 | { 100 | "indexed": true, 101 | "name": "name", 102 | "type": "bytes32" 103 | } 104 | ], 105 | "name": "Changed", 106 | "type": "event" 107 | } 108 | ] 109 | -------------------------------------------------------------------------------- /web3js/lib/contracts/SmartExchange.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": false, 4 | "inputs": [ 5 | { 6 | "name": "from", 7 | "type": "bytes32" 8 | }, 9 | { 10 | "name": "to", 11 | "type": "address" 12 | }, 13 | { 14 | "name": "value", 15 | "type": "uint256" 16 | } 17 | ], 18 | "name": "transfer", 19 | "outputs": [], 20 | "type": "function" 21 | }, 22 | { 23 | "constant": false, 24 | "inputs": [ 25 | { 26 | "name": "from", 27 | "type": "bytes32" 28 | }, 29 | { 30 | "name": "to", 31 | "type": "address" 32 | }, 33 | { 34 | "name": "indirectId", 35 | "type": "bytes32" 36 | }, 37 | { 38 | "name": "value", 39 | "type": "uint256" 40 | } 41 | ], 42 | "name": "icapTransfer", 43 | "outputs": [], 44 | "type": "function" 45 | }, 46 | { 47 | "constant": false, 48 | "inputs": [ 49 | { 50 | "name": "to", 51 | "type": "bytes32" 52 | } 53 | ], 54 | "name": "deposit", 55 | "outputs": [], 56 | "type": "function" 57 | }, 58 | { 59 | "anonymous": false, 60 | "inputs": [ 61 | { 62 | "indexed": true, 63 | "name": "from", 64 | "type": "address" 65 | }, 66 | { 67 | "indexed": false, 68 | "name": "value", 69 | "type": "uint256" 70 | } 71 | ], 72 | "name": "AnonymousDeposit", 73 | "type": "event" 74 | }, 75 | { 76 | "anonymous": false, 77 | "inputs": [ 78 | { 79 | "indexed": true, 80 | "name": "from", 81 | "type": "address" 82 | }, 83 | { 84 | "indexed": true, 85 | "name": "to", 86 | "type": "bytes32" 87 | }, 88 | { 89 | "indexed": false, 90 | "name": "value", 91 | "type": "uint256" 92 | } 93 | ], 94 | "name": "Deposit", 95 | "type": "event" 96 | }, 97 | { 98 | "anonymous": false, 99 | "inputs": [ 100 | { 101 | "indexed": true, 102 | "name": "from", 103 | "type": "bytes32" 104 | }, 105 | { 106 | "indexed": true, 107 | "name": "to", 108 | "type": "address" 109 | }, 110 | { 111 | "indexed": false, 112 | "name": "value", 113 | "type": "uint256" 114 | } 115 | ], 116 | "name": "Transfer", 117 | "type": "event" 118 | }, 119 | { 120 | "anonymous": false, 121 | "inputs": [ 122 | { 123 | "indexed": true, 124 | "name": "from", 125 | "type": "bytes32" 126 | }, 127 | { 128 | "indexed": true, 129 | "name": "to", 130 | "type": "address" 131 | }, 132 | { 133 | "indexed": false, 134 | "name": "indirectId", 135 | "type": "bytes32" 136 | }, 137 | { 138 | "indexed": false, 139 | "name": "value", 140 | "type": "uint256" 141 | } 142 | ], 143 | "name": "IcapTransfer", 144 | "type": "event" 145 | } 146 | ] 147 | -------------------------------------------------------------------------------- /web3js/lib/solidity/address.js: -------------------------------------------------------------------------------- 1 | var f = require('./formatters'); 2 | var SolidityType = require('./type'); 3 | 4 | /** 5 | * SolidityTypeAddress is a prootype that represents address type 6 | * It matches: 7 | * address 8 | * address[] 9 | * address[4] 10 | * address[][] 11 | * address[3][] 12 | * address[][6][], ... 13 | */ 14 | var SolidityTypeAddress = function () { 15 | this._inputFormatter = f.formatInputInt; 16 | this._outputFormatter = f.formatOutputAddress; 17 | }; 18 | 19 | SolidityTypeAddress.prototype = new SolidityType({}); 20 | SolidityTypeAddress.prototype.constructor = SolidityTypeAddress; 21 | 22 | SolidityTypeAddress.prototype.isType = function (name) { 23 | return !!name.match(/address(\[([0-9]*)\])?/); 24 | }; 25 | 26 | SolidityTypeAddress.prototype.staticPartLength = function (name) { 27 | return 32 * this.staticArrayLength(name); 28 | }; 29 | 30 | module.exports = SolidityTypeAddress; 31 | 32 | -------------------------------------------------------------------------------- /web3js/lib/solidity/bool.js: -------------------------------------------------------------------------------- 1 | var f = require('./formatters'); 2 | var SolidityType = require('./type'); 3 | 4 | /** 5 | * SolidityTypeBool is a prootype that represents bool type 6 | * It matches: 7 | * bool 8 | * bool[] 9 | * bool[4] 10 | * bool[][] 11 | * bool[3][] 12 | * bool[][6][], ... 13 | */ 14 | var SolidityTypeBool = function () { 15 | this._inputFormatter = f.formatInputBool; 16 | this._outputFormatter = f.formatOutputBool; 17 | }; 18 | 19 | SolidityTypeBool.prototype = new SolidityType({}); 20 | SolidityTypeBool.prototype.constructor = SolidityTypeBool; 21 | 22 | SolidityTypeBool.prototype.isType = function (name) { 23 | return !!name.match(/^bool(\[([0-9]*)\])*$/); 24 | }; 25 | 26 | SolidityTypeBool.prototype.staticPartLength = function (name) { 27 | return 32 * this.staticArrayLength(name); 28 | }; 29 | 30 | module.exports = SolidityTypeBool; 31 | -------------------------------------------------------------------------------- /web3js/lib/solidity/bytes.js: -------------------------------------------------------------------------------- 1 | var f = require('./formatters'); 2 | var SolidityType = require('./type'); 3 | 4 | /** 5 | * SolidityTypeBytes is a prootype that represents bytes type 6 | * It matches: 7 | * bytes 8 | * bytes[] 9 | * bytes[4] 10 | * bytes[][] 11 | * bytes[3][] 12 | * bytes[][6][], ... 13 | * bytes32 14 | * bytes64[] 15 | * bytes8[4] 16 | * bytes256[][] 17 | * bytes[3][] 18 | * bytes64[][6][], ... 19 | */ 20 | var SolidityTypeBytes = function () { 21 | this._inputFormatter = f.formatInputBytes; 22 | this._outputFormatter = f.formatOutputBytes; 23 | }; 24 | 25 | SolidityTypeBytes.prototype = new SolidityType({}); 26 | SolidityTypeBytes.prototype.constructor = SolidityTypeBytes; 27 | 28 | SolidityTypeBytes.prototype.isType = function (name) { 29 | return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/); 30 | }; 31 | 32 | SolidityTypeBytes.prototype.staticPartLength = function (name) { 33 | var matches = name.match(/^bytes([0-9]*)/); 34 | var size = parseInt(matches[1]); 35 | return size * this.staticArrayLength(name); 36 | }; 37 | 38 | module.exports = SolidityTypeBytes; 39 | -------------------------------------------------------------------------------- /web3js/lib/solidity/dynamicbytes.js: -------------------------------------------------------------------------------- 1 | var f = require('./formatters'); 2 | var SolidityType = require('./type'); 3 | 4 | var SolidityTypeDynamicBytes = function () { 5 | this._inputFormatter = f.formatInputDynamicBytes; 6 | this._outputFormatter = f.formatOutputDynamicBytes; 7 | }; 8 | 9 | SolidityTypeDynamicBytes.prototype = new SolidityType({}); 10 | SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes; 11 | 12 | SolidityTypeDynamicBytes.prototype.isType = function (name) { 13 | return !!name.match(/^bytes(\[([0-9]*)\])*$/); 14 | }; 15 | 16 | SolidityTypeDynamicBytes.prototype.staticPartLength = function (name) { 17 | return 32 * this.staticArrayLength(name); 18 | }; 19 | 20 | SolidityTypeDynamicBytes.prototype.isDynamicType = function () { 21 | return true; 22 | }; 23 | 24 | module.exports = SolidityTypeDynamicBytes; 25 | 26 | -------------------------------------------------------------------------------- /web3js/lib/solidity/int.js: -------------------------------------------------------------------------------- 1 | var f = require('./formatters'); 2 | var SolidityType = require('./type'); 3 | 4 | /** 5 | * SolidityTypeInt is a prootype that represents int type 6 | * It matches: 7 | * int 8 | * int[] 9 | * int[4] 10 | * int[][] 11 | * int[3][] 12 | * int[][6][], ... 13 | * int32 14 | * int64[] 15 | * int8[4] 16 | * int256[][] 17 | * int[3][] 18 | * int64[][6][], ... 19 | */ 20 | var SolidityTypeInt = function () { 21 | this._inputFormatter = f.formatInputInt; 22 | this._outputFormatter = f.formatOutputInt; 23 | }; 24 | 25 | SolidityTypeInt.prototype = new SolidityType({}); 26 | SolidityTypeInt.prototype.constructor = SolidityTypeInt; 27 | 28 | SolidityTypeInt.prototype.isType = function (name) { 29 | return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 30 | }; 31 | 32 | SolidityTypeInt.prototype.staticPartLength = function (name) { 33 | return 32 * this.staticArrayLength(name); 34 | }; 35 | 36 | module.exports = SolidityTypeInt; 37 | -------------------------------------------------------------------------------- /web3js/lib/solidity/real.js: -------------------------------------------------------------------------------- 1 | var f = require('./formatters'); 2 | var SolidityType = require('./type'); 3 | 4 | /** 5 | * SolidityTypeReal is a prootype that represents real type 6 | * It matches: 7 | * real 8 | * real[] 9 | * real[4] 10 | * real[][] 11 | * real[3][] 12 | * real[][6][], ... 13 | * real32 14 | * real64[] 15 | * real8[4] 16 | * real256[][] 17 | * real[3][] 18 | * real64[][6][], ... 19 | */ 20 | var SolidityTypeReal = function () { 21 | this._inputFormatter = f.formatInputReal; 22 | this._outputFormatter = f.formatOutputReal; 23 | }; 24 | 25 | SolidityTypeReal.prototype = new SolidityType({}); 26 | SolidityTypeReal.prototype.constructor = SolidityTypeReal; 27 | 28 | SolidityTypeReal.prototype.isType = function (name) { 29 | return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 30 | }; 31 | 32 | SolidityTypeReal.prototype.staticPartLength = function (name) { 33 | return 32 * this.staticArrayLength(name); 34 | }; 35 | 36 | module.exports = SolidityTypeReal; 37 | -------------------------------------------------------------------------------- /web3js/lib/solidity/string.js: -------------------------------------------------------------------------------- 1 | var f = require('./formatters'); 2 | var SolidityType = require('./type'); 3 | 4 | var SolidityTypeString = function () { 5 | this._inputFormatter = f.formatInputString; 6 | this._outputFormatter = f.formatOutputString; 7 | }; 8 | 9 | SolidityTypeString.prototype = new SolidityType({}); 10 | SolidityTypeString.prototype.constructor = SolidityTypeString; 11 | 12 | SolidityTypeString.prototype.isType = function (name) { 13 | return !!name.match(/^string(\[([0-9]*)\])*$/); 14 | }; 15 | 16 | SolidityTypeString.prototype.staticPartLength = function (name) { 17 | return 32 * this.staticArrayLength(name); 18 | }; 19 | 20 | SolidityTypeString.prototype.isDynamicType = function () { 21 | return true; 22 | }; 23 | 24 | module.exports = SolidityTypeString; 25 | 26 | -------------------------------------------------------------------------------- /web3js/lib/solidity/uint.js: -------------------------------------------------------------------------------- 1 | var f = require('./formatters'); 2 | var SolidityType = require('./type'); 3 | 4 | /** 5 | * SolidityTypeUInt is a prootype that represents uint type 6 | * It matches: 7 | * uint 8 | * uint[] 9 | * uint[4] 10 | * uint[][] 11 | * uint[3][] 12 | * uint[][6][], ... 13 | * uint32 14 | * uint64[] 15 | * uint8[4] 16 | * uint256[][] 17 | * uint[3][] 18 | * uint64[][6][], ... 19 | */ 20 | var SolidityTypeUInt = function () { 21 | this._inputFormatter = f.formatInputInt; 22 | this._outputFormatter = f.formatOutputUInt; 23 | }; 24 | 25 | SolidityTypeUInt.prototype = new SolidityType({}); 26 | SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 27 | 28 | SolidityTypeUInt.prototype.isType = function (name) { 29 | return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 30 | }; 31 | 32 | SolidityTypeUInt.prototype.staticPartLength = function (name) { 33 | return 32 * this.staticArrayLength(name); 34 | }; 35 | 36 | module.exports = SolidityTypeUInt; 37 | -------------------------------------------------------------------------------- /web3js/lib/solidity/ureal.js: -------------------------------------------------------------------------------- 1 | var f = require('./formatters'); 2 | var SolidityType = require('./type'); 3 | 4 | /** 5 | * SolidityTypeUReal is a prootype that represents ureal type 6 | * It matches: 7 | * ureal 8 | * ureal[] 9 | * ureal[4] 10 | * ureal[][] 11 | * ureal[3][] 12 | * ureal[][6][], ... 13 | * ureal32 14 | * ureal64[] 15 | * ureal8[4] 16 | * ureal256[][] 17 | * ureal[3][] 18 | * ureal64[][6][], ... 19 | */ 20 | var SolidityTypeUReal = function () { 21 | this._inputFormatter = f.formatInputReal; 22 | this._outputFormatter = f.formatOutputUReal; 23 | }; 24 | 25 | SolidityTypeUReal.prototype = new SolidityType({}); 26 | SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 27 | 28 | SolidityTypeUReal.prototype.isType = function (name) { 29 | return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 30 | }; 31 | 32 | SolidityTypeUReal.prototype.staticPartLength = function (name) { 33 | return 32 * this.staticArrayLength(name); 34 | }; 35 | 36 | module.exports = SolidityTypeUReal; 37 | -------------------------------------------------------------------------------- /web3js/lib/utils/browser-bn.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = BigNumber; // jshint ignore:line 4 | 5 | -------------------------------------------------------------------------------- /web3js/lib/utils/browser-xhr.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // go env doesn't have and need XMLHttpRequest 4 | if (typeof XMLHttpRequest === 'undefined') { 5 | exports.XMLHttpRequest = {}; 6 | } else { 7 | exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 8 | } 9 | 10 | -------------------------------------------------------------------------------- /web3js/lib/utils/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** @file config.js 18 | * @authors: 19 | * Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | /** 24 | * Utils 25 | * 26 | * @module utils 27 | */ 28 | 29 | /** 30 | * Utility functions 31 | * 32 | * @class [utils] config 33 | * @constructor 34 | */ 35 | 36 | 37 | /// required to define ETH_BIGNUMBER_ROUNDING_MODE 38 | var BigNumber = require('bignumber.js'); 39 | 40 | var ETH_UNITS = [ 41 | 'wei', 42 | 'kwei', 43 | 'Mwei', 44 | 'Gwei', 45 | 'szabo', 46 | 'finney', 47 | 'femtoether', 48 | 'picoether', 49 | 'nanoether', 50 | 'microether', 51 | 'milliether', 52 | 'nano', 53 | 'micro', 54 | 'milli', 55 | 'ether', 56 | 'grand', 57 | 'Mether', 58 | 'Gether', 59 | 'Tether', 60 | 'Pether', 61 | 'Eether', 62 | 'Zether', 63 | 'Yether', 64 | 'Nether', 65 | 'Dether', 66 | 'Vether', 67 | 'Uether' 68 | ]; 69 | 70 | module.exports = { 71 | ETH_PADDING: 32, 72 | ETH_SIGNATURE_LENGTH: 4, 73 | ETH_UNITS: ETH_UNITS, 74 | ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 75 | ETH_POLLING_TIMEOUT: 1000/2, 76 | defaultBlock: 'latest', 77 | defaultAccount: undefined 78 | }; 79 | 80 | -------------------------------------------------------------------------------- /web3js/lib/utils/sha3.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file sha3.js 19 | * @author Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | var CryptoJS = require('crypto-js'); 24 | var sha3 = require('crypto-js/sha3'); 25 | 26 | module.exports = function (value, options) { 27 | if (options && options.encoding === 'hex') { 28 | if (value.length > 2 && value.substr(0, 2) === '0x') { 29 | value = value.substr(2); 30 | } 31 | value = CryptoJS.enc.Hex.parse(value); 32 | } 33 | 34 | return sha3(value, { 35 | outputLength: 256 36 | }).toString(); 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /web3js/lib/version.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.17.0-alpha" 3 | } 4 | -------------------------------------------------------------------------------- /web3js/lib/web3/allevents.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file allevents.js 19 | * @author Marek Kotewicz 20 | * @date 2014 21 | */ 22 | 23 | var sha3 = require('../utils/sha3'); 24 | var SolidityEvent = require('./event'); 25 | var formatters = require('./formatters'); 26 | var utils = require('../utils/utils'); 27 | var Filter = require('./filter'); 28 | var watches = require('./methods/watches'); 29 | 30 | var AllSolidityEvents = function (requestManager, json, address) { 31 | this._requestManager = requestManager; 32 | this._json = json; 33 | this._address = address; 34 | }; 35 | 36 | AllSolidityEvents.prototype.encode = function (options) { 37 | options = options || {}; 38 | var result = {}; 39 | 40 | ['fromBlock', 'toBlock'].filter(function (f) { 41 | return options[f] !== undefined; 42 | }).forEach(function (f) { 43 | result[f] = formatters.inputBlockNumberFormatter(options[f]); 44 | }); 45 | 46 | result.address = this._address; 47 | 48 | return result; 49 | }; 50 | 51 | AllSolidityEvents.prototype.decode = function (data) { 52 | data.data = data.data || ''; 53 | data.topics = data.topics || []; 54 | 55 | var eventTopic = data.topics[0].slice(2); 56 | var match = this._json.filter(function (j) { 57 | return eventTopic === sha3(utils.transformToFullName(j)); 58 | })[0]; 59 | 60 | if (!match) { // cannot find matching event? 61 | console.warn('cannot find event for log'); 62 | return data; 63 | } 64 | 65 | var event = new SolidityEvent(this._requestManager, match, this._address); 66 | return event.decode(data); 67 | }; 68 | 69 | AllSolidityEvents.prototype.execute = function (options, callback) { 70 | 71 | if (utils.isFunction(arguments[arguments.length - 1])) { 72 | callback = arguments[arguments.length - 1]; 73 | if(arguments.length === 1) 74 | options = null; 75 | } 76 | 77 | var o = this.encode(options); 78 | var formatter = this.decode.bind(this); 79 | return new Filter(this._requestManager, o, watches.eth(), formatter, callback); 80 | }; 81 | 82 | AllSolidityEvents.prototype.attachToContract = function (contract) { 83 | var execute = this.execute.bind(this); 84 | contract.allEvents = execute; 85 | }; 86 | 87 | module.exports = AllSolidityEvents; 88 | 89 | -------------------------------------------------------------------------------- /web3js/lib/web3/batch.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file batch.js 19 | * @author Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | var Jsonrpc = require('./jsonrpc'); 24 | var errors = require('./errors'); 25 | 26 | var Batch = function (web3) { 27 | this.requestManager = web3._requestManager; 28 | this.requests = []; 29 | }; 30 | 31 | /** 32 | * Should be called to add create new request to batch request 33 | * 34 | * @method add 35 | * @param {Object} jsonrpc requet object 36 | */ 37 | Batch.prototype.add = function (request) { 38 | this.requests.push(request); 39 | }; 40 | 41 | /** 42 | * Should be called to execute batch request 43 | * 44 | * @method execute 45 | */ 46 | Batch.prototype.execute = function () { 47 | var requests = this.requests; 48 | this.requestManager.sendBatch(requests, function (err, results) { 49 | results = results || []; 50 | requests.map(function (request, index) { 51 | return results[index] || {}; 52 | }).forEach(function (result, index) { 53 | if (requests[index].callback) { 54 | 55 | if (!Jsonrpc.getInstance().isValidResponse(result)) { 56 | return requests[index].callback(errors.InvalidResponse(result)); 57 | } 58 | 59 | requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); 60 | } 61 | }); 62 | }); 63 | }; 64 | 65 | module.exports = Batch; 66 | 67 | -------------------------------------------------------------------------------- /web3js/lib/web3/errors.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file errors.js 19 | * @author Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | module.exports = { 24 | InvalidNumberOfParams: function () { 25 | return new Error('Invalid number of input parameters'); 26 | }, 27 | InvalidConnection: function (host){ 28 | return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.'); 29 | }, 30 | InvalidProvider: function () { 31 | return new Error('Provider not set or invalid'); 32 | }, 33 | InvalidResponse: function (result){ 34 | var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result); 35 | return new Error(message); 36 | } 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /web3js/lib/web3/extend.js: -------------------------------------------------------------------------------- 1 | var formatters = require('./formatters'); 2 | var utils = require('./../utils/utils'); 3 | var Method = require('./method'); 4 | var Property = require('./property'); 5 | 6 | // TODO: refactor, so the input params are not altered. 7 | // it's necessary to make same 'extension' work with multiple providers 8 | var extend = function (web3) { 9 | /* jshint maxcomplexity:5 */ 10 | var ex = function (extension) { 11 | 12 | var extendedObject; 13 | if (extension.property) { 14 | if (!web3[extension.property]) { 15 | web3[extension.property] = {}; 16 | } 17 | extendedObject = web3[extension.property]; 18 | } else { 19 | extendedObject = web3; 20 | } 21 | 22 | if (extension.methods) { 23 | extension.methods.forEach(function (method) { 24 | method.attachToObject(extendedObject); 25 | method.setRequestManager(web3._requestManager); 26 | }); 27 | } 28 | 29 | if (extension.properties) { 30 | extension.properties.forEach(function (property) { 31 | property.attachToObject(extendedObject); 32 | property.setRequestManager(web3._requestManager); 33 | }); 34 | } 35 | }; 36 | 37 | ex.formatters = formatters; 38 | ex.utils = utils; 39 | ex.Method = Method; 40 | ex.Property = Property; 41 | 42 | return ex; 43 | }; 44 | 45 | 46 | 47 | module.exports = extend; 48 | 49 | -------------------------------------------------------------------------------- /web3js/lib/web3/jsonrpc.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** @file jsonrpc.js 18 | * @authors: 19 | * Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | var Jsonrpc = function () { 24 | // singleton pattern 25 | if (arguments.callee._singletonInstance) { 26 | return arguments.callee._singletonInstance; 27 | } 28 | arguments.callee._singletonInstance = this; 29 | 30 | this.messageId = 1; 31 | }; 32 | 33 | /** 34 | * @return {Jsonrpc} singleton 35 | */ 36 | Jsonrpc.getInstance = function () { 37 | var instance = new Jsonrpc(); 38 | return instance; 39 | }; 40 | 41 | /** 42 | * Should be called to valid json create payload object 43 | * 44 | * @method toPayload 45 | * @param {Function} method of jsonrpc call, required 46 | * @param {Array} params, an array of method params, optional 47 | * @returns {Object} valid jsonrpc payload object 48 | */ 49 | Jsonrpc.prototype.toPayload = function (method, params) { 50 | if (!method) 51 | console.error('jsonrpc method should be specified!'); 52 | 53 | return { 54 | jsonrpc: '2.0', 55 | method: method, 56 | params: params || [], 57 | id: this.messageId++ 58 | }; 59 | }; 60 | 61 | /** 62 | * Should be called to check if jsonrpc response is valid 63 | * 64 | * @method isValidResponse 65 | * @param {Object} 66 | * @returns {Boolean} true if response is valid, otherwise false 67 | */ 68 | Jsonrpc.prototype.isValidResponse = function (response) { 69 | return !!response && 70 | !response.error && 71 | response.jsonrpc === '2.0' && 72 | typeof response.id === 'number' && 73 | response.result !== undefined; // only undefined is not valid json object 74 | }; 75 | 76 | /** 77 | * Should be called to create batch payload object 78 | * 79 | * @method toBatchPayload 80 | * @param {Array} messages, an array of objects with method (required) and params (optional) fields 81 | * @returns {Array} batch payload 82 | */ 83 | Jsonrpc.prototype.toBatchPayload = function (messages) { 84 | var self = this; 85 | return messages.map(function (message) { 86 | return self.toPayload(message.method, message.params); 87 | }); 88 | }; 89 | 90 | module.exports = Jsonrpc; 91 | 92 | -------------------------------------------------------------------------------- /web3js/lib/web3/methods/db.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** @file db.js 18 | * @authors: 19 | * Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | var Method = require('../method'); 24 | 25 | var DB = function (web3) { 26 | this._requestManager = web3._requestManager; 27 | 28 | var self = this; 29 | 30 | methods().forEach(function(method) { 31 | method.attachToObject(self); 32 | method.setRequestManager(web3._requestManager); 33 | }); 34 | }; 35 | 36 | var methods = function () { 37 | var putString = new Method({ 38 | name: 'putString', 39 | call: 'db_putString', 40 | params: 3 41 | }); 42 | 43 | var getString = new Method({ 44 | name: 'getString', 45 | call: 'db_getString', 46 | params: 2 47 | }); 48 | 49 | var putHex = new Method({ 50 | name: 'putHex', 51 | call: 'db_putHex', 52 | params: 3 53 | }); 54 | 55 | var getHex = new Method({ 56 | name: 'getHex', 57 | call: 'db_getHex', 58 | params: 2 59 | }); 60 | 61 | return [ 62 | putString, getString, putHex, getHex 63 | ]; 64 | }; 65 | 66 | module.exports = DB; 67 | -------------------------------------------------------------------------------- /web3js/lib/web3/methods/net.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** @file eth.js 18 | * @authors: 19 | * Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | var utils = require('../../utils/utils'); 24 | var Property = require('../property'); 25 | 26 | var Net = function (web3) { 27 | this._requestManager = web3._requestManager; 28 | 29 | var self = this; 30 | 31 | properties().forEach(function(p) { 32 | p.attachToObject(self); 33 | p.setRequestManager(web3._requestManager); 34 | }); 35 | }; 36 | 37 | /// @returns an array of objects describing web3.eth api properties 38 | var properties = function () { 39 | return [ 40 | new Property({ 41 | name: 'listening', 42 | getter: 'net_listening' 43 | }), 44 | new Property({ 45 | name: 'peerCount', 46 | getter: 'net_peerCount', 47 | outputFormatter: utils.toDecimal 48 | }) 49 | ]; 50 | }; 51 | 52 | module.exports = Net; 53 | -------------------------------------------------------------------------------- /web3js/lib/web3/methods/personal.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file eth.js 19 | * @author Marek Kotewicz 20 | * @author Fabian Vogelsteller 21 | * @date 2015 22 | */ 23 | 24 | "use strict"; 25 | 26 | var Method = require('../method'); 27 | var Property = require('../property'); 28 | var formatters = require('../formatters'); 29 | 30 | function Personal(web3) { 31 | this._requestManager = web3._requestManager; 32 | 33 | var self = this; 34 | 35 | methods().forEach(function(method) { 36 | method.attachToObject(self); 37 | method.setRequestManager(self._requestManager); 38 | }); 39 | 40 | properties().forEach(function(p) { 41 | p.attachToObject(self); 42 | p.setRequestManager(self._requestManager); 43 | }); 44 | } 45 | 46 | var methods = function () { 47 | var newAccount = new Method({ 48 | name: 'newAccount', 49 | call: 'personal_newAccount', 50 | params: 1, 51 | inputFormatter: [null] 52 | }); 53 | 54 | var unlockAccount = new Method({ 55 | name: 'unlockAccount', 56 | call: 'personal_unlockAccount', 57 | params: 3, 58 | inputFormatter: [formatters.inputAddressFormatter, null, null] 59 | }); 60 | 61 | var unlockAccountAndSendTransaction = new Method({ 62 | name: 'unlockAccountAndSendTransaction', 63 | call: 'personal_signAndSendTransaction', 64 | params: 2, 65 | inputFormatter: [formatters.inputTransactionFormatter, null] 66 | }); 67 | 68 | var lockAccount = new Method({ 69 | name: 'lockAccount', 70 | call: 'personal_lockAccount', 71 | params: 1, 72 | inputFormatter: [formatters.inputAddressFormatter] 73 | }); 74 | 75 | return [ 76 | newAccount, 77 | unlockAccount, 78 | unlockAccountAndSendTransaction, 79 | lockAccount 80 | ]; 81 | }; 82 | 83 | var properties = function () { 84 | return [ 85 | new Property({ 86 | name: 'listAccounts', 87 | getter: 'personal_listAccounts' 88 | }) 89 | ]; 90 | }; 91 | 92 | 93 | module.exports = Personal; 94 | -------------------------------------------------------------------------------- /web3js/lib/web3/methods/shh.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** @file shh.js 18 | * @authors: 19 | * Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | var Method = require('../method'); 24 | var formatters = require('../formatters'); 25 | var Filter = require('../filter'); 26 | var watches = require('./watches'); 27 | 28 | var Shh = function (web3) { 29 | this._requestManager = web3._requestManager; 30 | 31 | var self = this; 32 | 33 | methods().forEach(function(method) { 34 | method.attachToObject(self); 35 | method.setRequestManager(self._requestManager); 36 | }); 37 | }; 38 | 39 | Shh.prototype.filter = function (fil, callback) { 40 | return new Filter(this._requestManager, fil, watches.shh(), formatters.outputPostFormatter, callback); 41 | }; 42 | 43 | var methods = function () { 44 | 45 | var post = new Method({ 46 | name: 'post', 47 | call: 'shh_post', 48 | params: 1, 49 | inputFormatter: [formatters.inputPostFormatter] 50 | }); 51 | 52 | var newIdentity = new Method({ 53 | name: 'newIdentity', 54 | call: 'shh_newIdentity', 55 | params: 0 56 | }); 57 | 58 | var hasIdentity = new Method({ 59 | name: 'hasIdentity', 60 | call: 'shh_hasIdentity', 61 | params: 1 62 | }); 63 | 64 | var newGroup = new Method({ 65 | name: 'newGroup', 66 | call: 'shh_newGroup', 67 | params: 0 68 | }); 69 | 70 | var addToGroup = new Method({ 71 | name: 'addToGroup', 72 | call: 'shh_addToGroup', 73 | params: 0 74 | }); 75 | 76 | return [ 77 | post, 78 | newIdentity, 79 | hasIdentity, 80 | newGroup, 81 | addToGroup 82 | ]; 83 | }; 84 | 85 | module.exports = Shh; 86 | 87 | -------------------------------------------------------------------------------- /web3js/lib/web3/namereg.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file namereg.js 19 | * @author Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 24 | var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json'); 25 | 26 | var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 27 | var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 28 | 29 | module.exports = { 30 | global: { 31 | abi: globalRegistrarAbi, 32 | address: globalNameregAddress 33 | }, 34 | icap: { 35 | abi: icapRegistrarAbi, 36 | address: icapNameregAddress 37 | } 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /web3js/lib/web3/settings.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var Settings = function () { 4 | this.defaultBlock = 'latest'; 5 | this.defaultAccount = undefined; 6 | }; 7 | 8 | module.exports = Settings; 9 | 10 | -------------------------------------------------------------------------------- /web3js/lib/web3/syncing.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** @file syncing.js 18 | * @authors: 19 | * Fabian Vogelsteller 20 | * @date 2015 21 | */ 22 | 23 | var formatters = require('./formatters'); 24 | var utils = require('../utils/utils'); 25 | 26 | var count = 1; 27 | 28 | /** 29 | Adds the callback and sets up the methods, to iterate over the results. 30 | 31 | @method pollSyncing 32 | @param {Object} self 33 | */ 34 | var pollSyncing = function(self) { 35 | 36 | var onMessage = function (error, sync) { 37 | if (error) { 38 | return self.callbacks.forEach(function (callback) { 39 | callback(error); 40 | }); 41 | } 42 | 43 | if(utils.isObject(sync) && sync.startingBlock) 44 | sync = formatters.outputSyncingFormatter(sync); 45 | 46 | self.callbacks.forEach(function (callback) { 47 | if (self.lastSyncState !== sync) { 48 | 49 | // call the callback with true first so the app can stop anything, before receiving the sync data 50 | if(!self.lastSyncState && utils.isObject(sync)) 51 | callback(null, true); 52 | 53 | // call on the next CPU cycle, so the actions of the sync stop can be processes first 54 | setTimeout(function() { 55 | callback(null, sync); 56 | }, 0); 57 | 58 | self.lastSyncState = sync; 59 | } 60 | }); 61 | }; 62 | 63 | self.requestManager.startPolling({ 64 | method: 'eth_syncing', 65 | params: [], 66 | }, self.pollId, onMessage, self.stopWatching.bind(self)); 67 | 68 | }; 69 | 70 | var IsSyncing = function (requestManager, callback) { 71 | this.requestManager = requestManager; 72 | this.pollId = 'syncPoll_'+ count++; 73 | this.callbacks = []; 74 | this.addCallback(callback); 75 | this.lastSyncState = false; 76 | pollSyncing(this); 77 | 78 | return this; 79 | }; 80 | 81 | IsSyncing.prototype.addCallback = function (callback) { 82 | if(callback) 83 | this.callbacks.push(callback); 84 | return this; 85 | }; 86 | 87 | IsSyncing.prototype.stopWatching = function () { 88 | this.requestManager.stopPolling(this.pollId); 89 | this.callbacks = []; 90 | }; 91 | 92 | module.exports = IsSyncing; 93 | 94 | -------------------------------------------------------------------------------- /web3js/lib/web3/transfer.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of web3.js. 3 | 4 | web3.js is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | web3.js is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with web3.js. If not, see . 16 | */ 17 | /** 18 | * @file transfer.js 19 | * @author Marek Kotewicz 20 | * @date 2015 21 | */ 22 | 23 | var Iban = require('./iban'); 24 | var exchangeAbi = require('../contracts/SmartExchange.json'); 25 | 26 | /** 27 | * Should be used to make Iban transfer 28 | * 29 | * @method transfer 30 | * @param {String} from 31 | * @param {String} to iban 32 | * @param {Value} value to be tranfered 33 | * @param {Function} callback, callback 34 | */ 35 | var transfer = function (eth, from, to, value, callback) { 36 | var iban = new Iban(to); 37 | if (!iban.isValid()) { 38 | throw new Error('invalid iban address'); 39 | } 40 | 41 | if (iban.isDirect()) { 42 | return transferToAddress(eth, from, iban.address(), value, callback); 43 | } 44 | 45 | if (!callback) { 46 | var address = eth.icapNamereg().addr(iban.institution()); 47 | return deposit(eth, from, address, value, iban.client()); 48 | } 49 | 50 | eth.icapNamereg().addr(iban.institution(), function (err, address) { 51 | return deposit(eth, from, address, value, iban.client(), callback); 52 | }); 53 | 54 | }; 55 | 56 | /** 57 | * Should be used to transfer funds to certain address 58 | * 59 | * @method transferToAddress 60 | * @param {String} from 61 | * @param {String} to 62 | * @param {Value} value to be tranfered 63 | * @param {Function} callback, callback 64 | */ 65 | var transferToAddress = function (eth, from, to, value, callback) { 66 | return eth.sendTransaction({ 67 | address: to, 68 | from: from, 69 | value: value 70 | }, callback); 71 | }; 72 | 73 | /** 74 | * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 75 | * 76 | * @method deposit 77 | * @param {String} from 78 | * @param {String} to 79 | * @param {Value} value to be transfered 80 | * @param {String} client unique identifier 81 | * @param {Function} callback, callback 82 | */ 83 | var deposit = function (eth, from, to, value, client, callback) { 84 | var abi = exchangeAbi; 85 | return eth.contract(abi).at(to).deposit(client, { 86 | from: from, 87 | value: value 88 | }, callback); 89 | }; 90 | 91 | module.exports = transfer; 92 | 93 | -------------------------------------------------------------------------------- /web3js/package-init.js: -------------------------------------------------------------------------------- 1 | /* jshint ignore:start */ 2 | 3 | 4 | // Browser environment 5 | if(typeof window !== 'undefined') { 6 | Web3 = (typeof window.Web3 !== 'undefined') ? window.Web3 : require('web3'); 7 | BigNumber = (typeof window.BigNumber !== 'undefined') ? window.BigNumber : require('bignumber.js'); 8 | } 9 | 10 | 11 | // Node environment 12 | if(typeof global !== 'undefined') { 13 | Web3 = (typeof global.Web3 !== 'undefined') ? global.Web3 : require('web3'); 14 | BigNumber = (typeof global.BigNumber !== 'undefined') ? global.BigNumber : require('bignumber.js'); 15 | } 16 | 17 | /* jshint ignore:end */ -------------------------------------------------------------------------------- /web3js/package.js: -------------------------------------------------------------------------------- 1 | /* jshint ignore:start */ 2 | Package.describe({ 3 | name: 'ethereum:web3', 4 | version: '0.17.0-alpha', 5 | summary: 'Ethereum JavaScript API, middleware to talk to a ethreum node over RPC', 6 | git: 'https://github.com/ethereum/ethereum.js', 7 | // By default, Meteor will default to using README.md for documentation. 8 | // To avoid submitting documentation, set this field to null. 9 | documentation: 'README.md' 10 | }); 11 | 12 | Npm.depends({ 13 | "xmlhttprequest": "1.7.0" 14 | }); 15 | 16 | 17 | Package.onUse(function(api) { 18 | api.versionsFrom('1.0.3.2'); 19 | 20 | // api.use('3stack:bignumber@2.0.0', 'client'); 21 | 22 | api.export(['Web3', 'BigNumber'], ['client', 'server']); 23 | 24 | api.addFiles('dist/web3.js', ['client', 'server']); 25 | api.addFiles('package-init.js', ['client', 'server']); 26 | }); 27 | 28 | // Package.onTest(function(api) { 29 | // api.use('tinytest'); 30 | // api.use('test'); 31 | // api.addFiles('test-tests.js'); 32 | // }); 33 | /* jshint ignore:end */ 34 | -------------------------------------------------------------------------------- /web3js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web3", 3 | "namespace": "ethereum", 4 | "version": "0.17.0-alpha", 5 | "description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC", 6 | "main": "./index.js", 7 | "directories": { 8 | "lib": "./lib" 9 | }, 10 | "dependencies": { 11 | "bignumber.js": "git+https://github.com/debris/bignumber.js.git#94d7146671b9719e00a09c29b01a691bc85048c2", 12 | "crypto-js": "^3.1.4", 13 | "utf8": "^2.1.1", 14 | "xmlhttprequest": "*" 15 | }, 16 | "browser": { 17 | "xmlhttprequest": "./lib/utils/browser-xhr.js" 18 | }, 19 | "devDependencies": { 20 | "bower": ">=1.4.1", 21 | "browserify": ">=10.0", 22 | "chai": "^3.0.0", 23 | "coveralls": "^2.11.2", 24 | "del": ">=2.0.2", 25 | "exorcist": "^0.4.0", 26 | "gulp": ">=3.9.0", 27 | "gulp-jshint": ">=1.5.0", 28 | "gulp-rename": ">=1.2.0", 29 | "gulp-replace": "^0.5.3", 30 | "gulp-streamify": "0.0.5", 31 | "gulp-uglify": ">=1.2.0", 32 | "istanbul": "^0.4.4", 33 | "jshint": ">=2.5.0", 34 | "mocha": ">=2.3.3", 35 | "sandboxed-module": "^2.0.2", 36 | "vinyl-source-stream": "^1.1.0" 37 | }, 38 | "scripts": { 39 | "build": "gulp", 40 | "watch": "gulp watch", 41 | "lint": "jshint *.js lib", 42 | "test": "mocha", 43 | "test-coveralls": "istanbul cover _mocha -- -R spec && cat coverage/lcov.info | coveralls --verbose" 44 | }, 45 | "repository": { 46 | "type": "git", 47 | "url": "https://github.com/ethereum/web3.js.git" 48 | }, 49 | "homepage": "https://github.com/ethereum/web3.js", 50 | "bugs": { 51 | "url": "https://github.com/ethereum/web3.js/issues" 52 | }, 53 | "keywords": [ 54 | "ethereum", 55 | "javascript", 56 | "API" 57 | ], 58 | "author": "ethdev.com", 59 | "authors": [ 60 | { 61 | "name": "Marek Kotewicz", 62 | "email": "marek@ethdev.com", 63 | "url": "https://github.com/debris" 64 | }, 65 | { 66 | "name": "Fabian Vogelsteller", 67 | "email": "fabian@ethdev.com", 68 | "homepage": "http://frozeman.de" 69 | }, 70 | { 71 | "name": "Marian Oancea", 72 | "email": "marian@ethdev.com", 73 | "url": "https://github.com/cubedro" 74 | }, 75 | { 76 | "name": "Gav Wood", 77 | "email": "g@ethdev.com", 78 | "homepage": "http://gavwood.com" 79 | }, 80 | { 81 | "name": "Jeffery Wilcke", 82 | "email": "jeff@ethdev.com", 83 | "url": "https://github.com/obscuren" 84 | } 85 | ], 86 | "license": "LGPL-3.0" 87 | } 88 | -------------------------------------------------------------------------------- /web3js/test/async.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | // use sendTransaction as dummy 8 | var method = 'sendTransaction'; 9 | 10 | var tests = [{ 11 | input: { 12 | 'from': 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', 13 | 'to': 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS' 14 | }, 15 | formattedInput: { 16 | 'from': '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 17 | 'to': '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8' 18 | }, 19 | result: '0xb', 20 | formattedResult: '0xb', 21 | call: 'eth_'+ method 22 | }]; 23 | 24 | describe('async', function () { 25 | tests.forEach(function (test, index) { 26 | it('test: ' + index, function (done) { 27 | 28 | // given 29 | var provider = new FakeHttpProvider(); 30 | web3.setProvider(provider); 31 | provider.injectResult(test.result); 32 | provider.injectValidation(function (payload) { 33 | assert.equal(payload.jsonrpc, '2.0'); 34 | assert.equal(payload.method, test.call); 35 | assert.deepEqual(payload.params, [test.formattedInput]); 36 | }); 37 | 38 | // when 39 | web3.eth[method](test.input, function(error, result){ 40 | 41 | // then 42 | assert.isNull(error); 43 | assert.strictEqual(test.formattedResult, result); 44 | 45 | done(); 46 | }); 47 | 48 | }); 49 | 50 | it('error test: ' + index, function (done) { 51 | 52 | // given 53 | var provider = new FakeHttpProvider(); 54 | web3.setProvider(provider); 55 | provider.injectError({ 56 | message: test.result, 57 | code: -32603 58 | }); 59 | provider.injectValidation(function (payload) { 60 | assert.equal(payload.jsonrpc, '2.0'); 61 | assert.equal(payload.method, test.call); 62 | assert.deepEqual(payload.params, [test.formattedInput]); 63 | }); 64 | 65 | // when 66 | web3.eth[method](test.input, function(error, result){ 67 | 68 | // then 69 | assert.isUndefined(result); 70 | assert.strictEqual(test.formattedResult, error.message); 71 | 72 | done(); 73 | }); 74 | 75 | }); 76 | }); 77 | }); 78 | 79 | -------------------------------------------------------------------------------- /web3js/test/errors.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var errors = require('../lib/web3/errors'); 4 | 5 | describe('lib/web3/method', function () { 6 | describe('getCall', function () { 7 | 8 | for(var key in errors) { 9 | it('should return and error', function () { 10 | 11 | assert.instanceOf(errors[key](), Error); 12 | }); 13 | } 14 | 15 | }); 16 | }); 17 | 18 | -------------------------------------------------------------------------------- /web3js/test/formatters.inputAddressFormatter.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var formatters = require('../lib/web3/formatters.js'); 4 | var BigNumber = require('bignumber.js'); 5 | 6 | var tests = [ 7 | { input: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8' }, 8 | { input: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'}, 9 | { input: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'}, 10 | { input: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae', result: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae' } 11 | ]; 12 | 13 | var errorTests = [ 14 | '0x0c5496aee77c1ba1f0854206a26dda82a81d6d8', 15 | '0x0c5496aee77c1ba1f0854206a26dda82a81d6d8', 16 | '00c5496aee77c1ba1f0854206a26dda82a81d6d', 17 | 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZE', 18 | '0x' 19 | ] 20 | 21 | describe('formatters', function () { 22 | describe('inputAddressFormatter', function () { 23 | tests.forEach(function(test){ 24 | it('should return the correct value', function () { 25 | assert.deepEqual(formatters.inputAddressFormatter(test.input), test.result); 26 | }); 27 | }); 28 | }); 29 | }); 30 | 31 | 32 | describe('formatters', function () { 33 | describe('inputAddressFormatter', function () { 34 | errorTests.forEach(function(test){ 35 | it('should throw an exception', function () { 36 | assert.throws(function () { 37 | formatters.inputAddressFormatter(test); 38 | }); 39 | }); 40 | }); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /web3js/test/formatters.inputDefaultBlockFormatter.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var formatters = require('../lib/web3/formatters'); 4 | 5 | var tests = [ 6 | { value: 'latest', expected: 'latest' }, 7 | { value: 'pending', expected: 'pending' }, 8 | { value: 'earliest', expected: 'earliest' }, 9 | { value: 1, expected: '0x1' }, 10 | { value: '0x1', expected: '0x1' } 11 | ]; 12 | 13 | describe('lib/web3/formatters', function () { 14 | describe('inputDefaultBlockNumberFormatter', function () { 15 | tests.forEach(function (test) { 16 | it('should turn ' + test.value + ' to ' + test.expected, function () { 17 | assert.strictEqual(formatters.inputDefaultBlockNumberFormatter(test.value), test.expected); 18 | }); 19 | }); 20 | }); 21 | }); 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /web3js/test/formatters.inputPostFormatter.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var formatters = require('../lib/web3/formatters.js'); 4 | 5 | describe('formatters', function () { 6 | describe('inputPostFormatter', function () { 7 | it('should return the correct value', function () { 8 | 9 | // input as strings and numbers 10 | assert.deepEqual(formatters.inputPostFormatter({ 11 | from: '0x00000', 12 | to: '0x00000', 13 | payload: '0x7b2274657374223a2274657374227d',//{test: 'test'}, 14 | ttl: 200, 15 | priority: 1000, 16 | topics: ['hello','mytopics'] 17 | }), { 18 | from: '0x00000', 19 | to: '0x00000', 20 | payload: '0x7b2274657374223a2274657374227d', 21 | ttl: '0xc8', 22 | priority: '0x3e8', 23 | topics: ['0x68656c6c6f','0x6d79746f70696373'], 24 | workToProve: '0x0' 25 | }); 26 | 27 | }); 28 | }); 29 | }); 30 | 31 | -------------------------------------------------------------------------------- /web3js/test/formatters.inputTransactionFormatter.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var formatters = require('../lib/web3/formatters.js'); 4 | var BigNumber = require('bignumber.js'); 5 | 6 | var tests = [{ 7 | input: { 8 | data: '0x34234bf23bf4234', 9 | value: new BigNumber(100), 10 | from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 11 | to: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 12 | nonce: 1000, 13 | gas: 1000, 14 | gasPrice: new BigNumber(1000) 15 | }, 16 | result: { 17 | data: '0x34234bf23bf4234', 18 | value: '0x64', 19 | from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 20 | to: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 21 | nonce: '0x3e8', 22 | gas: '0x3e8', 23 | gasPrice: '0x3e8' 24 | } 25 | },{ 26 | input: { 27 | data: '0x34234bf23bf4234', 28 | value: new BigNumber(100), 29 | from: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', 30 | to: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', 31 | }, 32 | result: { 33 | data: '0x34234bf23bf4234', 34 | value: '0x64', 35 | from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 36 | to: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 37 | } 38 | },{ 39 | input: { 40 | data: '0x34234bf23bf4234', 41 | value: new BigNumber(100), 42 | from: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', 43 | to: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', 44 | gas: '1000', 45 | gasPrice: new BigNumber(1000) 46 | }, 47 | result: { 48 | data: '0x34234bf23bf4234', 49 | value: '0x64', 50 | from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 51 | to: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 52 | gas: '0x3e8', 53 | gasPrice: '0x3e8' 54 | }, 55 | }, { 56 | input: { 57 | data: '0x34234bf23bf4234', 58 | value: new BigNumber(100), 59 | from: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', 60 | to: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', 61 | gas: '1000', 62 | gasPrice: new BigNumber(1000) 63 | }, 64 | result: { 65 | data: '0x34234bf23bf4234', 66 | value: '0x64', 67 | from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 68 | to: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 69 | gas: '0x3e8', 70 | gasPrice: '0x3e8' 71 | }, 72 | }, { 73 | input: { 74 | data: '0x34234bf23bf4234', 75 | value: new BigNumber(100), 76 | from: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', 77 | gas: '1000', 78 | gasPrice: new BigNumber(1000) 79 | }, 80 | result: { 81 | data: '0x34234bf23bf4234', 82 | value: '0x64', 83 | from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 84 | gas: '0x3e8', 85 | gasPrice: '0x3e8' 86 | } 87 | }]; 88 | 89 | describe('formatters', function () { 90 | describe('inputTransactionFormatter', function () { 91 | tests.forEach(function(test){ 92 | it('should return the correct value', function () { 93 | assert.deepEqual(formatters.inputTransactionFormatter(test.input), test.result); 94 | }); 95 | }); 96 | }); 97 | }); 98 | -------------------------------------------------------------------------------- /web3js/test/formatters.outputLogFormatter.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var formatters = require('../lib/web3/formatters.js'); 3 | 4 | describe('formatters', function () { 5 | describe('outputLogFormatter', function () { 6 | it('should return the correct value', function () { 7 | 8 | assert.deepEqual(formatters.outputLogFormatter({ 9 | transactionIndex: '0x3e8', 10 | logIndex: '0x3e8', 11 | blockNumber: '0x3e8', 12 | transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', 13 | blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', 14 | data: '0x7b2274657374223a2274657374227', 15 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 16 | }), { 17 | transactionIndex: 1000, 18 | logIndex: 1000, 19 | blockNumber: 1000, 20 | transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', 21 | blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', 22 | data: '0x7b2274657374223a2274657374227', 23 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 24 | }); 25 | }); 26 | it('should return the correct value, when null values are present', function () { 27 | 28 | assert.deepEqual(formatters.outputLogFormatter({ 29 | transactionIndex: null, 30 | logIndex: null, 31 | blockNumber: null, 32 | transactionHash: null, 33 | blockHash: null, 34 | data: '0x7b2274657374223a2274657374227', 35 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 36 | }), { 37 | transactionIndex: null, 38 | logIndex: null, 39 | blockNumber: null, 40 | transactionHash: null, 41 | blockHash: null, 42 | data: '0x7b2274657374223a2274657374227', 43 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 44 | }); 45 | }); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /web3js/test/formatters.outputPostFormatter.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var formatters = require('../lib/web3/formatters.js'); 3 | 4 | describe('formatters', function () { 5 | describe('outputPostFormatter', function () { 6 | it('should return the correct value', function () { 7 | 8 | assert.deepEqual(formatters.outputPostFormatter({ 9 | expiry: '0x3e8', 10 | sent: '0x3e8', 11 | ttl: '0x3e8', 12 | workProved: '0x3e8', 13 | payload: '0x7b2274657374223a2274657374227d', 14 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 15 | }), { 16 | expiry: 1000, 17 | sent: 1000, 18 | ttl: 1000, 19 | workProved: 1000, 20 | payload: '0x7b2274657374223a2274657374227d',//{test: 'test'}, 21 | //payloadRaw: '0x7b2274657374223a2274657374227d', 22 | topics: ['hello','mytopics'] 23 | }); 24 | }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /web3js/test/formatters.outputTransactionFormatter.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var formatters = require('../lib/web3/formatters.js'); 3 | var BigNumber = require('bignumber.js'); 4 | 5 | describe('formatters', function () { 6 | describe('outputTransactionFormatter', function () { 7 | it('should return the correct value', function () { 8 | 9 | assert.deepEqual(formatters.outputTransactionFormatter({ 10 | input: '0x3454645634534', 11 | from: '0x00000', 12 | to: '0x00000', 13 | value: '0x3e8', 14 | gas: '0x3e8', 15 | gasPrice: '0x3e8', 16 | nonce: '0xb', 17 | transactionIndex: '0x1', 18 | blockNumber: '0x3e8', 19 | blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9' 20 | }), { 21 | input: '0x3454645634534', 22 | from: '0x00000', 23 | to: '0x00000', 24 | value: new BigNumber(1000), 25 | gas: 1000, 26 | gasPrice: new BigNumber(1000), 27 | nonce: 11, 28 | blockNumber: 1000, 29 | blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9', 30 | transactionIndex: 1 31 | }); 32 | }); 33 | 34 | it('should return the correct value, when null values are present', function () { 35 | 36 | assert.deepEqual(formatters.outputTransactionFormatter({ 37 | input: '0x3454645634534', 38 | from: '0x00000', 39 | to: null, 40 | value: '0x3e8', 41 | gas: '0x3e8', 42 | gasPrice: '0x3e8', 43 | nonce: '0xb', 44 | transactionIndex: null, 45 | blockNumber: null, 46 | blockHash: null 47 | }), { 48 | input: '0x3454645634534', 49 | from: '0x00000', 50 | to: null, 51 | value: new BigNumber(1000), 52 | gas: 1000, 53 | gasPrice: new BigNumber(1000), 54 | nonce: 11, 55 | blockNumber: null, 56 | blockHash: null, 57 | transactionIndex: null 58 | }); 59 | }); 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /web3js/test/helpers/FakeHttpProvider2.js: -------------------------------------------------------------------------------- 1 | var FakeHttpProvider = require('./FakeHttpProvider'); 2 | 3 | var FakeHttpProvider2 = function () { 4 | this.counter = 0; 5 | this.resultList = []; 6 | }; 7 | 8 | FakeHttpProvider2.prototype = new FakeHttpProvider(); 9 | FakeHttpProvider2.prototype.constructor = FakeHttpProvider2; 10 | 11 | FakeHttpProvider2.prototype.injectResultList = function (list) { 12 | this.resultList = list; 13 | }; 14 | 15 | FakeHttpProvider2.prototype.getResponse = function () { 16 | var result = this.resultList[this.counter]; 17 | this.counter++; 18 | 19 | // add fallback result value 20 | if(!result) 21 | result = { 22 | result: undefined 23 | }; 24 | 25 | if (result.type === 'batch') { 26 | this.injectBatchResults(result.result); 27 | } else { 28 | this.injectResult(result.result); 29 | } 30 | 31 | this.counter = 0; 32 | 33 | return this.response; 34 | }; 35 | 36 | module.exports = FakeHttpProvider2; 37 | 38 | -------------------------------------------------------------------------------- /web3js/test/helpers/FakeIpcRequest.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | 4 | var FakeIpcRequest = function () { 5 | this._handle = {fd: {}}; 6 | this.callbacks = []; 7 | 8 | return this 9 | }; 10 | 11 | FakeIpcRequest.prototype.connect = function (path) { 12 | assert.notEqual(path, undefined); 13 | 14 | return this; 15 | }; 16 | 17 | FakeIpcRequest.prototype.on = function(name, callback) { 18 | if(name === 'data'){ 19 | this.callbacks.push(callback); 20 | } 21 | }; 22 | 23 | FakeIpcRequest.prototype.writeSync = function (payload) { 24 | assert.equal(typeof payload, 'string'); 25 | return payload; 26 | }; 27 | 28 | FakeIpcRequest.prototype.write = function (payload) { 29 | assert.equal(typeof payload, 'string'); 30 | 31 | this.callbacks.forEach(function(cb){ 32 | setTimeout(function(){ 33 | cb(payload); 34 | }, 100); 35 | }); 36 | 37 | }; 38 | 39 | module.exports = FakeIpcRequest; 40 | 41 | -------------------------------------------------------------------------------- /web3js/test/helpers/FakeQtNavigator.js: -------------------------------------------------------------------------------- 1 | 2 | var navigator = { 3 | qt: { 4 | callMethod: function (payload) { 5 | return "{}"; 6 | } 7 | } 8 | }; 9 | 10 | module.exports = navigator; 11 | 12 | -------------------------------------------------------------------------------- /web3js/test/helpers/FakeXMLHttpRequest.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | 4 | var FakeXMLHttpRequest = function () { 5 | this.responseText = "{}"; 6 | this.readyState = 4; 7 | this.onreadystatechange = null; 8 | this.async = false; 9 | this.headers = { 10 | 'Content-Type': 'text/plain' 11 | }; 12 | }; 13 | 14 | FakeXMLHttpRequest.prototype.open = function (method, host, async) { 15 | assert.equal(method, 'POST'); 16 | assert.notEqual(host, null); 17 | assert.equal(async === false || async === true, true); 18 | this.async = async; 19 | }; 20 | 21 | FakeXMLHttpRequest.prototype.setRequestHeader = function(name, value) { 22 | this.headers[name] = value; 23 | }; 24 | 25 | FakeXMLHttpRequest.prototype.send = function (payload) { 26 | assert.equal(typeof payload, 'string'); 27 | if (this.async) { 28 | assert.equal(typeof this.onreadystatechange, 'function'); 29 | this.onreadystatechange(); 30 | return; 31 | } 32 | return this.responseText; 33 | }; 34 | 35 | module.exports = { 36 | XMLHttpRequest: FakeXMLHttpRequest 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /web3js/test/helpers/test.method.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../../index'); 4 | 5 | var FakeHttpProvider = require('./FakeHttpProvider'); 6 | var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; 7 | 8 | var runTests = function (obj, method, tests) { 9 | 10 | var testName = obj ? 'web3.' + obj : 'web'; 11 | 12 | describe(testName, function () { 13 | describe(method, function () { 14 | tests.forEach(function (test, index) { 15 | it('sync test: ' + index, function () { 16 | 17 | // given 18 | var provider = new FakeHttpProvider(); 19 | var web3 = new Web3(provider); 20 | provider.injectResult(test.result); 21 | provider.injectValidation(function (payload) { 22 | assert.equal(payload.jsonrpc, '2.0'); 23 | assert.equal(payload.method, test.call); 24 | assert.deepEqual(payload.params, test.formattedArgs); 25 | }); 26 | 27 | var args = clone(test.args) 28 | 29 | // when 30 | if (obj) { 31 | var result = web3[obj][method].apply(web3[obj], args); 32 | } else { 33 | var result = web3[method].apply(web3, args); 34 | } 35 | // when 36 | //var result = (obj) 37 | //? web3[obj][method].apply(null, test.args.slice(0)) 38 | //: web3[method].apply(null, test.args.slice(0)); 39 | 40 | // then 41 | assert.deepEqual(test.formattedResult, result); 42 | }); 43 | 44 | it('async test: ' + index, function (done) { 45 | 46 | // given 47 | var provider = new FakeHttpProvider(); 48 | var web3 = new Web3(provider); 49 | provider.injectResult(test.result); 50 | provider.injectValidation(function (payload) { 51 | assert.equal(payload.jsonrpc, '2.0'); 52 | assert.equal(payload.method, test.call); 53 | assert.deepEqual(payload.params, test.formattedArgs); 54 | }); 55 | 56 | var args = clone(test.args); 57 | 58 | // add callback 59 | args.push(function (err, result) { 60 | assert.deepEqual(test.formattedResult, result); 61 | done(); 62 | }); 63 | 64 | // when 65 | if (obj) { 66 | web3[obj][method].apply(web3[obj], args); 67 | } else { 68 | web3[method].apply(web3, args); 69 | } 70 | }); 71 | }); 72 | }); 73 | }); 74 | 75 | }; 76 | 77 | module.exports = { 78 | runTests: runTests 79 | } 80 | 81 | -------------------------------------------------------------------------------- /web3js/test/helpers/test.utils.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | //var web3 = require('../../index'); 4 | 5 | var FakeHttpProvider = require('./FakeHttpProvider'); 6 | 7 | var methodExists = function (object, method) { 8 | it('should have method ' + method + ' implemented', function() { 9 | //web3.setProvider(null); 10 | assert.equal('function', typeof object[method], 'method ' + method + ' is not implemented'); 11 | }); 12 | }; 13 | 14 | var propertyExists = function (object, property) { 15 | it('should have property ' + property + ' implemented', function() { 16 | // set dummy providor, to prevent error 17 | //web3.setProvider(new FakeHttpProvider()); 18 | assert.notEqual('undefined', typeof object[property], 'property ' + property + ' is not implemented'); 19 | }); 20 | }; 21 | 22 | module.exports = { 23 | methodExists: methodExists, 24 | propertyExists: propertyExists 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /web3js/test/httpprovider.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var SandboxedModule = require('sandboxed-module'); 4 | 5 | SandboxedModule.registerBuiltInSourceTransformer('istanbul'); 6 | var HttpProvider = SandboxedModule.require('../lib/web3/httpprovider', { 7 | requires: { 8 | 'xmlhttprequest': require('./helpers/FakeXMLHttpRequest') 9 | }, 10 | singleOnly: true 11 | }); 12 | 13 | describe('lib/web3/httpprovider', function () { 14 | describe('send', function () { 15 | it('should send basic request', function () { 16 | var provider = new HttpProvider(); 17 | var result = provider.send({}); 18 | 19 | assert.equal(typeof result, 'object'); 20 | }); 21 | }); 22 | 23 | describe('sendAsync', function () { 24 | it('should send basic async request', function (done) { 25 | var provider = new HttpProvider(); 26 | 27 | provider.sendAsync({}, function (err, result) { 28 | assert.equal(typeof result, 'object'); 29 | done(); 30 | }); 31 | }); 32 | }); 33 | 34 | describe('isConnected', function () { 35 | it('should return a boolean', function () { 36 | var provider = new HttpProvider(); 37 | 38 | assert.isBoolean(provider.isConnected()); 39 | }); 40 | }); 41 | }); 42 | 43 | -------------------------------------------------------------------------------- /web3js/test/iban.createIndirect.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Iban = require('../lib/web3/iban.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { institution: 'XREG', identifier: 'GAVOFYORK', expected: 'XE81ETHXREGGAVOFYORK'} 7 | ]; 8 | 9 | describe('lib/web3/iban', function () { 10 | describe('createIndirect', function () { 11 | tests.forEach(function (test) { 12 | it('shoud create indirect iban: ' + test.expected, function () { 13 | assert.deepEqual(Iban.createIndirect({ 14 | institution: test.institution, 15 | identifier: test.identifier 16 | }), new Iban(test.expected)); 17 | }); 18 | }); 19 | }); 20 | }); 21 | 22 | -------------------------------------------------------------------------------- /web3js/test/iban.fromAddress.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Iban = require('../lib/web3/iban.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { address: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'}, 7 | { address: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'}, 8 | { address: '0x11c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE1222Q908LN1QBBU6XUQSO1OHWJIOS46OO'}, 9 | { address: '0x52dc504a422f0e2a9e7632a34a50f1a82f8224c7', expected: 'XE499OG1EH8ZZI0KXC6N83EKGT1BM97P2O7'}, 10 | { address: '0x0000a5327eab78357cbf2ae8f3d49fd9d90c7d22', expected: 'XE0600DQK33XDTYUCRI0KYM5ELAKXDWWF6'} 11 | ]; 12 | 13 | describe('lib/web3/iban', function () { 14 | describe('fromAddress', function () { 15 | tests.forEach(function (test) { 16 | it('shoud create indirect iban: ' + test.expected, function () { 17 | assert.deepEqual(Iban.fromAddress(test.address), new Iban(test.expected)); 18 | }); 19 | }); 20 | }); 21 | }); 22 | 23 | -------------------------------------------------------------------------------- /web3js/test/iban.isValid.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Iban = require('../lib/web3/iban.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { obj: function () {}, is: false}, 7 | { obj: new Function(), is: false}, 8 | { obj: 'function', is: false}, 9 | { obj: {}, is: false}, 10 | { obj: '[]', is: false}, 11 | { obj: '[1, 2]', is: false}, 12 | { obj: '{}', is: false}, 13 | { obj: '{"a": 123, "b" :3,}', is: false}, 14 | { obj: '{"c" : 2}', is: false}, 15 | { obj: 'XE81ETHXREGGAVOFYORK', is: true}, 16 | { obj: 'XE82ETHXREGGAVOFYORK', is: false}, // control number is invalid 17 | { obj: 'XE81ETCXREGGAVOFYORK', is: false}, 18 | { obj: 'XE81ETHXREGGAVOFYORKD', is: false}, 19 | { obj: 'XE81ETHXREGGaVOFYORK', is: false}, 20 | { obj: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: true}, 21 | { obj: 'XE7438O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: false}, // control number is invalid 22 | { obj: 'XD7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: false}, 23 | { obj: 'XE1222Q908LN1QBBU6XUQSO1OHWJIOS46OO', is: true} 24 | ]; 25 | 26 | describe('lib/web3/iban', function () { 27 | describe('isValid', function () { 28 | tests.forEach(function (test) { 29 | it('shoud test if value ' + test.obj + ' is iban: ' + test.is, function () { 30 | assert.equal(Iban.isValid(test.obj), test.is); 31 | }); 32 | }); 33 | }); 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /web3js/test/iban.toAddress.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Iban = require('../lib/web3/iban.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { direct: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', address: '00c5496aee77c1ba1f0854206a26dda82a81d6d8'} 7 | ]; 8 | 9 | describe('lib/web3/iban', function () { 10 | describe('toAddress', function () { 11 | tests.forEach(function (test) { 12 | it('shoud transform iban to address: ' + test.address, function () { 13 | var iban = new Iban(test.direct); 14 | assert.deepEqual(iban.address(), test.address); 15 | }); 16 | }); 17 | }); 18 | }); 19 | 20 | -------------------------------------------------------------------------------- /web3js/test/ipcprovider.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var SandboxedModule = require('sandboxed-module'); 4 | var FakeIpcRequest = require('./helpers/FakeIpcRequest') 5 | var net = new FakeIpcRequest(); 6 | 7 | SandboxedModule.registerBuiltInSourceTransformer('istanbul'); 8 | var IpcProvider = SandboxedModule.require('../lib/web3/ipcprovider', { 9 | requires: { 10 | 'bignumber.js': require('bignumber.js'), 11 | }, 12 | singleOnly: true 13 | }); 14 | 15 | describe('lib/web3/ipcprovider', function () { 16 | describe('send', function () { 17 | it('should send basic request', function () { 18 | var provider = new IpcProvider('', net); 19 | var result = provider.send({id: 1, method: 'eth_test'}); 20 | 21 | assert.isObject(result); 22 | }); 23 | }); 24 | 25 | describe('sendAsync', function () { 26 | it('should send basic async request', function (done) { 27 | var provider = new IpcProvider('', net); 28 | provider.sendAsync({id: 1, method: 'eth_test'}, function (err, result) { 29 | assert.isObject(result); 30 | done(); 31 | }); 32 | }); 33 | }); 34 | 35 | describe('isConnected', function () { 36 | it('should return a boolean', function () { 37 | var provider = new IpcProvider('', net); 38 | 39 | assert.isBoolean(provider.isConnected()); 40 | }); 41 | 42 | it('should return false', function () { 43 | var provider = new IpcProvider('', net); 44 | 45 | provider.connection.writable = false; 46 | 47 | assert.isFalse(provider.isConnected()); 48 | }); 49 | 50 | it('should return true, when a net handle is set', function () { 51 | var provider = new IpcProvider('', net); 52 | 53 | provider.connection.writable = true; 54 | 55 | assert.isTrue(provider.isConnected()); 56 | }); 57 | }); 58 | }); 59 | 60 | -------------------------------------------------------------------------------- /web3js/test/jsonrpc.id.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Jsonrpc = require('../lib/web3/jsonrpc'); 4 | 5 | describe('lib/web3/jsonrpc', function () { 6 | describe('id', function () { 7 | it('should increment the id', function () { 8 | 9 | // given 10 | var a = Jsonrpc.getInstance(); 11 | var b = Jsonrpc.getInstance(); 12 | var method = 'm'; 13 | 14 | // when 15 | var p1 = a.toPayload(method); 16 | var p2 = b.toPayload(method); 17 | 18 | // then 19 | assert.equal(p2.id, p1.id + 1); 20 | }); 21 | }); 22 | }); 23 | 24 | -------------------------------------------------------------------------------- /web3js/test/jsonrpc.toBatchPayload.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var jsonrpc = require('../lib/web3/jsonrpc'); 3 | jsonrpc = new jsonrpc(); 4 | 5 | describe('jsonrpc', function () { 6 | describe('toBatchPayload', function () { 7 | it('should create basic batch payload', function () { 8 | 9 | // given 10 | var messages = [{ 11 | method: 'helloworld' 12 | }, { 13 | method: 'test2', 14 | params: [1] 15 | }]; 16 | 17 | // when 18 | var payload = jsonrpc.toBatchPayload(messages); 19 | 20 | // then 21 | assert.equal(payload instanceof Array, true); 22 | assert.equal(payload.length, 2); 23 | assert.equal(payload[0].jsonrpc, '2.0'); 24 | assert.equal(payload[1].jsonrpc, '2.0'); 25 | assert.equal(payload[0].method, 'helloworld'); 26 | assert.equal(payload[1].method, 'test2'); 27 | assert.equal(payload[0].params instanceof Array, true); 28 | assert.equal(payload[1].params.length, 1); 29 | assert.equal(payload[1].params[0], 1); 30 | assert.equal(typeof payload[0].id, 'number'); 31 | assert.equal(typeof payload[1].id, 'number'); 32 | assert.equal(payload[0].id + 1, payload[1].id); 33 | }); 34 | 35 | it('should create batch payload for empty input array', function () { 36 | 37 | // given 38 | var messages = []; 39 | 40 | // when 41 | var payload = jsonrpc.toBatchPayload(messages); 42 | 43 | // then 44 | assert.equal(payload instanceof Array, true); 45 | assert.equal(payload.length, 0); 46 | }); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /web3js/test/jsonrpc.toPayload.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var jsonrpc = require('../lib/web3/jsonrpc'); 4 | jsonrpc = new jsonrpc(); 5 | 6 | describe('jsonrpc', function () { 7 | describe('toPayload', function () { 8 | it('should create basic payload', function () { 9 | 10 | // given 11 | var method = 'helloworld'; 12 | 13 | // when 14 | var payload = jsonrpc.toPayload(method); 15 | 16 | // then 17 | assert.equal(payload.jsonrpc, '2.0'); 18 | assert.equal(payload.method, method); 19 | assert.equal(payload.params instanceof Array, true); 20 | assert.equal(payload.params.length, 0); 21 | assert.equal(typeof payload.id, 'number'); 22 | }); 23 | 24 | it('should create payload with params', function () { 25 | 26 | // given 27 | var method = 'helloworld1'; 28 | var params = [123, 'test']; 29 | 30 | // when 31 | var payload = jsonrpc.toPayload(method, params); 32 | 33 | // then 34 | assert.equal(payload.jsonrpc, '2.0'); 35 | assert.equal(payload.method, method); 36 | assert.equal(payload.params.length, 2); 37 | assert.equal(payload.params[0], params[0]); 38 | assert.equal(payload.params[1], params[1]); 39 | assert.equal(typeof payload.id, 'number'); 40 | }); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /web3js/test/method.extractCallback.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Method = require('../lib/web3/method'); 4 | 5 | describe('lib/web3/method', function () { 6 | describe('extractCallback', function () { 7 | it('should extract callback', function () { 8 | 9 | // given 10 | var method = new Method({}); 11 | var callback = function () { }; 12 | var args = [1, callback] 13 | 14 | // when 15 | var result = method.extractCallback(args); 16 | 17 | // then 18 | assert.equal(args.length, 1); 19 | assert.equal(callback, result); 20 | }); 21 | 22 | it('should extract callback created using newFunction', function () { 23 | 24 | // given 25 | var method = new Method({}); 26 | var callback = new Function (); 27 | var args = [1, callback] 28 | 29 | // when 30 | var result = method.extractCallback(args); 31 | 32 | // then 33 | assert.equal(args.length, 1); 34 | assert.equal(callback, result); 35 | }); 36 | 37 | it('should not extract the callback', function () { 38 | 39 | // given 40 | var method = new Method({}); 41 | var args = [1, 2] 42 | 43 | // when 44 | var result = method.extractCallback(args); 45 | 46 | // then 47 | assert.equal(args.length, 2); 48 | assert.equal(result, null); 49 | }); 50 | }); 51 | }); 52 | 53 | -------------------------------------------------------------------------------- /web3js/test/method.formatInput.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Method = require('../lib/web3/method'); 4 | 5 | describe('lib/web3/method', function () { 6 | describe('formatInput', function () { 7 | it('should format plain input', function () { 8 | 9 | // given 10 | var star = function (arg) { 11 | return arg + '*'; 12 | }; 13 | 14 | var method = new Method({ 15 | inputFormatter: [star, star, star] 16 | }); 17 | var args = ['1','2','3']; 18 | var expectedArgs = ['1*', '2*', '3*']; 19 | 20 | // when 21 | var result = method.formatInput(args); 22 | 23 | // then 24 | assert.deepEqual(result, expectedArgs); 25 | }); 26 | 27 | it('should do nothing if there is no formatter', function () { 28 | 29 | // given 30 | var method = new Method({}); 31 | var args = [1,2,3]; 32 | 33 | // when 34 | var result = method.formatInput(args); 35 | 36 | // then 37 | assert.deepEqual(result, args); 38 | }); 39 | }); 40 | }); 41 | 42 | -------------------------------------------------------------------------------- /web3js/test/method.formatOutput.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Method = require('../lib/web3/method'); 4 | 5 | describe('lib/web3/method', function () { 6 | describe('formatOutput', function () { 7 | it('should format plain output', function () { 8 | 9 | // given 10 | var formatter = function (args) { 11 | return args.map(function (arg) { 12 | return arg + '*'; 13 | }); 14 | }; 15 | 16 | var method = new Method({ 17 | outputFormatter: formatter 18 | }); 19 | var args = ['1','2','3']; 20 | var expectedArgs = ['1*', '2*', '3*']; 21 | 22 | // when 23 | var result = method.formatOutput(args); 24 | 25 | // then 26 | assert.deepEqual(result, expectedArgs); 27 | }); 28 | 29 | it('should do nothing if there is no formatter', function () { 30 | 31 | // given 32 | var method = new Method({}); 33 | var args = [1,2,3]; 34 | 35 | // when 36 | var result = method.formatOutput(args); 37 | 38 | // then 39 | assert.deepEqual(result, args); 40 | }); 41 | }); 42 | }); 43 | 44 | -------------------------------------------------------------------------------- /web3js/test/method.getCall.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Method = require('../lib/web3/method'); 4 | 5 | describe('lib/web3/method', function () { 6 | describe('getCall', function () { 7 | it('should return call name', function () { 8 | 9 | // given 10 | var call = 'hello_call_world'; 11 | var method = new Method({ 12 | call: call 13 | }); 14 | 15 | // when 16 | var result = method.getCall(); 17 | 18 | // then 19 | assert.equal(call, result); 20 | }); 21 | 22 | it('should return call based on args', function () { 23 | 24 | // given 25 | var call = function (args) { 26 | return args ? args.length.toString() : '0'; 27 | }; 28 | 29 | var method = new Method({ 30 | call: call 31 | }); 32 | 33 | // when 34 | var r0 = method.getCall(); 35 | var r1 = method.getCall([1]); 36 | var r2 = method.getCall([1, 2]); 37 | 38 | // then 39 | assert.equal(r0, '0'); 40 | assert.equal(r1, '1'); 41 | assert.equal(r2, '2'); 42 | 43 | }); 44 | }); 45 | }); 46 | 47 | -------------------------------------------------------------------------------- /web3js/test/method.validateArgs.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Method = require('../lib/web3/method'); 4 | var errors = require('../lib/web3/errors'); 5 | 6 | describe('lib/web3/method', function () { 7 | describe('validateArgs', function () { 8 | it('should pass', function () { 9 | 10 | // given 11 | var method = new Method({ 12 | params: 1 13 | }); 14 | 15 | var args = [1]; 16 | var args2 = ['heloas']; 17 | 18 | // when 19 | var test = function () { method.validateArgs(args); }; 20 | var test2 = function () { method.validateArgs(args2); }; 21 | 22 | // then 23 | assert.doesNotThrow(test); 24 | assert.doesNotThrow(test2); 25 | }); 26 | 27 | it('should return call based on args', function () { 28 | 29 | // given 30 | var method = new Method({ 31 | params: 2 32 | }); 33 | 34 | var args = [1]; 35 | var args2 = ['heloas', '12', 3]; 36 | 37 | // when 38 | var test = function () { method.validateArgs(args); }; 39 | var test2 = function () { method.validateArgs(args2); }; 40 | 41 | // then 42 | assert.throws(test, errors.InvalidNumberOfParams().message); 43 | assert.throws(test2, errors.InvalidNumberOfParams().message); 44 | }); 45 | }); 46 | }); 47 | 48 | -------------------------------------------------------------------------------- /web3js/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec 2 | -------------------------------------------------------------------------------- /web3js/test/node/app.js: -------------------------------------------------------------------------------- 1 | var web3 = require('web3'); 2 | 3 | console.log(web3.version.api); 4 | 5 | 6 | -------------------------------------------------------------------------------- /web3js/test/node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "web3": "ethereum/web3.js#master" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /web3js/test/requestmanager.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var RequestManager = require('../lib/web3/requestmanager'); 4 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 5 | 6 | // TODO: handling errors! 7 | // TODO: validation of params! 8 | 9 | describe('lib/web3/requestmanager', function () { 10 | describe('send', function () { 11 | it('should return expected result synchronously', function () { 12 | var provider = new FakeHttpProvider(); 13 | var manager = new RequestManager(provider); 14 | var expected = 'hello_world'; 15 | provider.injectResult(expected); 16 | 17 | var result = manager.send({ 18 | method: 'test', 19 | params: [1,2,3] 20 | }); 21 | 22 | assert.equal(expected, result); 23 | }); 24 | 25 | it('should return expected result asynchronously', function (done) { 26 | var provider = new FakeHttpProvider(); 27 | var manager = new RequestManager(provider); 28 | var expected = 'hello_world'; 29 | provider.injectResult(expected); 30 | 31 | manager.sendAsync({ 32 | method: 'test', 33 | params: [1,2,3] 34 | }, function (error, result) { 35 | assert.equal(error, null); 36 | assert.equal(expected, result); 37 | done(); 38 | }); 39 | }); 40 | }); 41 | }); 42 | 43 | -------------------------------------------------------------------------------- /web3js/test/sha3.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var sha3 = require('../lib/utils/sha3'); 4 | var web3 = require('../index'); 5 | 6 | describe('lib/utils/sha3', function () { 7 | var test = function (v, e, o) { 8 | it('should encode ' + v + ' to ' + e, function () { 9 | assert.equal(sha3(v, o), e); 10 | }); 11 | }; 12 | 13 | test('test123', 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad'); 14 | test('test(int)', 'f4d03772bec1e62fbe8c5691e1a9101e520e8f8b5ca612123694632bf3cb51b1'); 15 | test('0x80', '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', { encoding: 'hex' }); 16 | test('0x80', '6b03a5eef7706e3fb52a61c19ab1122fad7237726601ac665bd4def888f0e4a0'); 17 | test('0x3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1', '82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28', { encoding: 'hex' }); 18 | }); 19 | 20 | -------------------------------------------------------------------------------- /web3js/test/utils.extractDisplayName.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var utils = require('../lib/utils/utils.js'); 3 | 4 | describe('lib/utils/utils', function () { 5 | describe('extractDisplayName', function () { 6 | it('should extract display name from method with no params', function () { 7 | 8 | // given 9 | var test = 'helloworld()'; 10 | 11 | // when 12 | var displayName = utils.extractDisplayName(test); 13 | 14 | // then 15 | assert.equal(displayName, 'helloworld'); 16 | }); 17 | 18 | it('should extract display name from method with one param' , function () { 19 | 20 | // given 21 | var test = 'helloworld1(int)'; 22 | 23 | // when 24 | var displayName = utils.extractDisplayName(test); 25 | 26 | // then 27 | assert.equal(displayName, 'helloworld1'); 28 | }); 29 | 30 | it('should extract display name from method with two params' , function () { 31 | 32 | // given 33 | var test = 'helloworld2(int,string)'; 34 | 35 | // when 36 | var displayName = utils.extractDisplayName(test); 37 | 38 | // then 39 | assert.equal(displayName, 'helloworld2'); 40 | }); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /web3js/test/utils.extractTypeName.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var utils = require('../lib/utils/utils.js'); 3 | 4 | describe('lib/utils/utils', function () { 5 | describe('extractTypeName', function () { 6 | it('should extract type name from method with no params', function () { 7 | 8 | // given 9 | var test = 'helloworld()'; 10 | 11 | // when 12 | var typeName = utils.extractTypeName(test); 13 | 14 | // then 15 | assert.equal(typeName, ''); 16 | }); 17 | 18 | it('should extract type name from method with one param', function () { 19 | 20 | // given 21 | var test = 'helloworld1(int)'; 22 | 23 | // when 24 | var typeName = utils.extractTypeName(test); 25 | 26 | // then 27 | assert.equal(typeName, 'int'); 28 | }); 29 | 30 | it('should extract type name from method with two params', function () { 31 | 32 | // given 33 | var test = 'helloworld2(int,string)'; 34 | 35 | // when 36 | var typeName = utils.extractTypeName(test); 37 | 38 | // then 39 | assert.equal(typeName, 'int,string'); 40 | }); 41 | 42 | it('should extract type name from method with spaces between params', function () { 43 | 44 | // given 45 | var test = 'helloworld3(int, string)'; 46 | 47 | // when 48 | var typeName = utils.extractTypeName(test); 49 | 50 | // then 51 | assert.equal(typeName, 'int,string'); 52 | }); 53 | 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /web3js/test/utils.fromAscii.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var BigNumber = require('bignumber.js'); 3 | var utils = require('../lib/utils/utils.js'); 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: 'myString', expected: '0x6d79537472696e67'}, 8 | { value: 'myString\x00', expected: '0x6d79537472696e6700'}, 9 | { value: '\u0003\u0000\u0000\u00005èÆÕL]\u0012|Î¾ž\u001a7«›\u00052\u0011(ЗY\n<\u0010\u0000\u0000\u0000\u0000\u0000\u0000e!ßd/ñõì\f:z¦Î¦±ç·÷Í¢Ëß\u00076*…\bŽ—ñžùC1ÉUÀé2\u001aӆBŒ', 10 | expected: '0x0300000035e8c6d54c5d127c9dcebe9e1a37ab9b05321128d097590a3c100000000000006521df642ff1f5ec0c3a7aa6cea6b1e7b7f7cda2cbdf07362a85088e97f19ef94331c955c0e9321ad386428c'} 11 | ]; 12 | 13 | describe('lib/utils/utils', function () { 14 | describe('fromAscii', function () { 15 | tests.forEach(function (test) { 16 | it('should turn ' + test.value + ' to ' + test.expected, function () { 17 | assert.strictEqual(utils.fromAscii(test.value), test.expected); 18 | }); 19 | }); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /web3js/test/utils.fromDecimal.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { value: 1, expected: '0x1' }, 7 | { value: '1', expected: '0x1' }, 8 | { value: '0x1', expected: '0x1'}, 9 | { value: '0x01', expected: '0x1'}, 10 | { value: 15, expected: '0xf'}, 11 | { value: '15', expected: '0xf'}, 12 | { value: '0xf', expected: '0xf'}, 13 | { value: '0x0f', expected: '0xf'}, 14 | { value: -1, expected: '-0x1'}, 15 | { value: '-1', expected: '-0x1'}, 16 | { value: '-0x1', expected: '-0x1'}, 17 | { value: '-0x01', expected: '-0x1'}, 18 | { value: -15, expected: '-0xf'}, 19 | { value: '-15', expected: '-0xf'}, 20 | { value: '-0xf', expected: '-0xf'}, 21 | { value: '-0x0f', expected: '-0xf'}, 22 | { value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, 23 | { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, 24 | { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, 25 | { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, 26 | { value: 0, expected: '0x0'}, 27 | { value: '0', expected: '0x0'}, 28 | { value: '0x0', expected: '0x0'}, 29 | { value: -0, expected: '0x0'}, 30 | { value: '-0', expected: '0x0'}, 31 | { value: '-0x0', expected: '0x0'} 32 | ]; 33 | 34 | describe('lib/utils/utils', function () { 35 | describe('fromDecimal', function () { 36 | tests.forEach(function (test) { 37 | it('should turn ' + test.value + ' to ' + test.expected, function () { 38 | assert.equal(utils.fromDecimal(test.value), test.expected); 39 | }); 40 | }); 41 | }); 42 | }); 43 | 44 | -------------------------------------------------------------------------------- /web3js/test/utils.fromUtf8.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var BigNumber = require('bignumber.js'); 3 | var utils = require('../lib/utils/utils.js'); 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: 'myString', expected: '0x6d79537472696e67'}, 8 | { value: 'myString\x00', expected: '0x6d79537472696e67'}, 9 | { value: 'expected value\u0000\u0000\u0000', expected: '0x65787065637465642076616c7565'} 10 | ]; 11 | 12 | describe('lib/utils/utils', function () { 13 | describe('fromUtf8', function () { 14 | tests.forEach(function (test) { 15 | it('should turn ' + test.value + ' to ' + test.expected, function () { 16 | assert.strictEqual(utils.fromUtf8(test.value), test.expected); 17 | }); 18 | }); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /web3js/test/utils.fromWei.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var utils = require('../lib/utils/utils.js'); 3 | 4 | describe('lib/utils/utils', function () { 5 | describe('fromWei', function () { 6 | it('should return the correct value', function () { 7 | 8 | assert.equal(utils.fromWei(1000000000000000000, 'wei'), '1000000000000000000'); 9 | assert.equal(utils.fromWei(1000000000000000000, 'kwei'), '1000000000000000'); 10 | assert.equal(utils.fromWei(1000000000000000000, 'mwei'), '1000000000000'); 11 | assert.equal(utils.fromWei(1000000000000000000, 'gwei'), '1000000000'); 12 | assert.equal(utils.fromWei(1000000000000000000, 'szabo'), '1000000'); 13 | assert.equal(utils.fromWei(1000000000000000000, 'finney'), '1000'); 14 | assert.equal(utils.fromWei(1000000000000000000, 'ether'), '1'); 15 | assert.equal(utils.fromWei(1000000000000000000, 'kether'), '0.001'); 16 | assert.equal(utils.fromWei(1000000000000000000, 'grand'), '0.001'); 17 | assert.equal(utils.fromWei(1000000000000000000, 'mether'), '0.000001'); 18 | assert.equal(utils.fromWei(1000000000000000000, 'gether'), '0.000000001'); 19 | assert.equal(utils.fromWei(1000000000000000000, 'tether'), '0.000000000001'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /web3js/test/utils.isAddress.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { value: function () {}, is: false}, 7 | { value: new Function(), is: false}, 8 | { value: 'function', is: false}, 9 | { value: {}, is: false}, 10 | { value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true }, 11 | { value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: true } 12 | ]; 13 | 14 | describe('lib/utils/utils', function () { 15 | describe('isAddress', function () { 16 | tests.forEach(function (test) { 17 | it('shoud test if value ' + test.value + ' is address: ' + test.is, function () { 18 | assert.equal(utils.isAddress(test.value), test.is); 19 | }); 20 | }); 21 | }); 22 | }); 23 | 24 | -------------------------------------------------------------------------------- /web3js/test/utils.isBigNumber.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils.js'); 3 | var BigNumber = require('bignumber.js'); 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: function () {}, is: false}, 8 | { value: new Function(), is: false}, 9 | { value: 'function', is: false}, 10 | { value: {}, is: false}, 11 | { value: new String('hello'), is: false}, 12 | { value: new BigNumber(0), is: true}, 13 | { value: 132, is: false}, 14 | { value: '0x12', is: false}, 15 | 16 | ]; 17 | 18 | describe('lib/utils/utils', function () { 19 | describe('isBigNumber', function () { 20 | tests.forEach(function (test) { 21 | it('shoud test if value ' + test.func + ' is BigNumber: ' + test.is, function () { 22 | assert.equal(utils.isBigNumber(test.value), test.is); 23 | }); 24 | }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /web3js/test/utils.isChecksumAddress.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { value: '0x52908400098527886E0F7030069857D2E4169EE7', is: true }, 7 | { value: '0x8617E340B3D01FA5F11F306F4090FD50E238070D', is: true }, 8 | { value: '0xde709f2102306220921060314715629080e2fb77', is: true }, 9 | { value: '0x27b1fdb04752bbc536007a920d24acb045561c26', is: true }, 10 | { value: '0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed', is: true }, 11 | { value: '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359', is: true }, 12 | { value: '0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB', is: true }, 13 | { value: '0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', is: true }, 14 | { value: '0XD1220A0CF47C7B9BE7A2E6BA89F429762E7B9ADB', is: false }, 15 | { value: '0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb', is: false } 16 | ]; 17 | 18 | describe('lib/utils/utils', function () { 19 | describe('isChecksumAddress', function () { 20 | tests.forEach(function (test) { 21 | it('shoud test if address ' + test.value + ' passes checksum: ' + test.is, function () { 22 | assert.equal(utils.isChecksumAddress(test.value), test.is); 23 | }); 24 | }); 25 | }); 26 | }); 27 | 28 | -------------------------------------------------------------------------------- /web3js/test/utils.isFunction.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { func: function () {}, is: true}, 7 | { func: new Function(), is: true}, 8 | { func: 'function', is: false}, 9 | { func: {}, is: false} 10 | ]; 11 | 12 | describe('lib/utils/utils', function () { 13 | describe('isFunction', function () { 14 | tests.forEach(function (test) { 15 | it('shoud test if value ' + test.func + ' is function: ' + test.is, function () { 16 | assert.equal(utils.isFunction(test.func), test.is); 17 | }); 18 | }); 19 | }); 20 | }); 21 | 22 | -------------------------------------------------------------------------------- /web3js/test/utils.isJson.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { obj: function () {}, is: false}, 7 | { obj: new Function(), is: false}, 8 | { obj: 'function', is: false}, 9 | { obj: {}, is: false}, 10 | { obj: '[]', is: true}, 11 | { obj: '[1, 2]', is: true}, 12 | { obj: '{}', is: true}, 13 | { obj: '{"a": 123, "b" :3,}', is: false}, 14 | { obj: '{"c" : 2}', is: true} 15 | ]; 16 | 17 | describe('lib/utils/utils', function () { 18 | describe('isJson', function () { 19 | tests.forEach(function (test) { 20 | it('shoud test if value ' + test.obj + ' is json: ' + test.is, function () { 21 | assert.equal(utils.isJson(test.obj), test.is); 22 | }); 23 | }); 24 | }); 25 | }); 26 | 27 | -------------------------------------------------------------------------------- /web3js/test/utils.isStrictAddress.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { value: function () {}, is: false}, 7 | { value: new Function(), is: false}, 8 | { value: 'function', is: false}, 9 | { value: {}, is: false}, 10 | { value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true }, 11 | { value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: false } 12 | ]; 13 | 14 | describe('lib/utils/utils', function () { 15 | describe('isStrictAddress', function () { 16 | tests.forEach(function (test) { 17 | it('shoud test if value ' + test.value + ' is address: ' + test.is, function () { 18 | assert.equal(utils.isStrictAddress(test.value), test.is); 19 | }); 20 | }); 21 | }); 22 | }); 23 | 24 | -------------------------------------------------------------------------------- /web3js/test/utils.isString.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils.js'); 3 | var assert = chai.assert; 4 | 5 | var tests = [ 6 | { value: function () {}, is: false}, 7 | { value: new Function(), is: false}, 8 | { value: 'function', is: true}, 9 | { value: {}, is: false}, 10 | { value: new String('hello'), is: true} 11 | ]; 12 | 13 | describe('lib/utils/utils', function () { 14 | describe('isString', function () { 15 | tests.forEach(function (test) { 16 | it('shoud test if value ' + test.func + ' is string: ' + test.is, function () { 17 | assert.equal(utils.isString(test.value), test.is); 18 | }); 19 | }); 20 | }); 21 | }); 22 | 23 | -------------------------------------------------------------------------------- /web3js/test/utils.toAscii.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var BigNumber = require('bignumber.js'); 3 | var utils = require('../lib/utils/utils.js'); 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: '0x6d79537472696e67', expected: 'myString'}, 8 | { value: '0x6d79537472696e6700', expected: 'myString\u0000'}, 9 | { value: "0x0300000035e8c6d54c5d127c9dcebe9e1a37ab9b05321128d097590a3c100000000000006521df642ff1f5ec0c3a7aa6cea6b1e7b7f7cda2cbdf07362a85088e97f19ef94331c955c0e9321ad386428c", 10 | expected: '\u0003\u0000\u0000\u00005èÆÕL]\u0012|Î¾ž\u001a7«›\u00052\u0011(ЗY\n<\u0010\u0000\u0000\u0000\u0000\u0000\u0000e!ßd/ñõì\f:z¦Î¦±ç·÷Í¢Ëß\u00076*…\bŽ—ñžùC1ÉUÀé2\u001aӆBŒ'} 11 | ]; 12 | 13 | describe('lib/utils/utils', function () { 14 | describe('toAscii', function () { 15 | tests.forEach(function (test) { 16 | it('should turn ' + test.value + ' to ' + test.expected, function () { 17 | assert.strictEqual(utils.toAscii(test.value), test.expected); 18 | }); 19 | }); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /web3js/test/utils.toBigNumber.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils.js'); 3 | var BigNumber = require('bignumber.js'); 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: 1, expected: '1' }, 8 | { value: '1', expected: '1' }, 9 | { value: '0x1', expected: '1'}, 10 | { value: '0x01', expected: '1'}, 11 | { value: 15, expected: '15'}, 12 | { value: '15', expected: '15'}, 13 | { value: '0xf', expected: '15'}, 14 | { value: '0x0f', expected: '15'}, 15 | { value: new BigNumber('f', 16), expected: '15'}, 16 | { value: -1, expected: '-1'}, 17 | { value: '-1', expected: '-1'}, 18 | { value: '-0x1', expected: '-1'}, 19 | { value: '-0x01', expected: '-1'}, 20 | { value: -15, expected: '-15'}, 21 | { value: '-15', expected: '-15'}, 22 | { value: '-0xf', expected: '-15'}, 23 | { value: '-0x0f', expected: '-15'}, 24 | { value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639935'}, 25 | { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639933'}, 26 | { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639935'}, 27 | { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639933'}, 28 | { value: 0, expected: '0'}, 29 | { value: '0', expected: '0'}, 30 | { value: '0x0', expected: '0'}, 31 | { value: -0, expected: '0'}, 32 | { value: '-0', expected: '0'}, 33 | { value: '-0x0', expected: '0'}, 34 | { value: new BigNumber(0), expected: '0'} 35 | ]; 36 | 37 | describe('lib/utils/utils', function () { 38 | describe('toBigNumber', function () { 39 | tests.forEach(function (test) { 40 | it('should turn ' + test.value + ' to ' + test.expected, function () { 41 | assert.equal(utils.toBigNumber(test.value).toString(10), test.expected); 42 | }); 43 | }); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /web3js/test/utils.toDecimal.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var utils = require('../lib/utils/utils.js'); 3 | 4 | describe('lib/utils/utils', function () { 5 | describe('toDecimal', function () { 6 | it('should return the correct value', function () { 7 | 8 | assert.equal(utils.toDecimal("0x3e8"), '1000'); 9 | // allow compatiblity 10 | assert.equal(utils.toDecimal(100000), '100000'); 11 | assert.equal(utils.toDecimal('100000'), '100000'); 12 | }); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /web3js/test/utils.toHex.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils'); 3 | var BigNumber = require('bignumber.js'); 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: 1, expected: '0x1' }, 8 | { value: '1', expected: '0x1' }, 9 | { value: '0x1', expected: '0x1'}, 10 | { value: '15', expected: '0xf'}, 11 | { value: '0xf', expected: '0xf'}, 12 | { value: -1, expected: '-0x1'}, 13 | { value: '-1', expected: '-0x1'}, 14 | { value: '-0x1', expected: '-0x1'}, 15 | { value: '-15', expected: '-0xf'}, 16 | { value: '-0xf', expected: '-0xf'}, 17 | { value: '0x657468657265756d', expected: '0x657468657265756d'}, 18 | { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, 19 | { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, 20 | { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, 21 | { value: 0, expected: '0x0'}, 22 | { value: '0', expected: '0x0'}, 23 | { value: '0x0', expected: '0x0'}, 24 | { value: -0, expected: '0x0'}, 25 | { value: '-0', expected: '0x0'}, 26 | { value: '-0x0', expected: '0x0'}, 27 | { value: [1,2,3,{test: 'data'}], expected: '0x5b312c322c332c7b2274657374223a2264617461227d5d'}, 28 | { value: {test: 'test'}, expected: '0x7b2274657374223a2274657374227d'}, 29 | { value: '{"test": "test"}', expected: '0x7b2274657374223a202274657374227d'}, 30 | { value: 'myString', expected: '0x6d79537472696e67'}, 31 | { value: new BigNumber(15), expected: '0xf'}, 32 | { value: true, expected: '0x1'}, 33 | { value: false, expected: '0x0'}, 34 | { value: '\u0003\u0000\u0000\u00005èÆÕL]\u0012|Î¾ž\u001a7«›\u00052\u0011(ЗY\n<\u0010\u0000\u0000\u0000\u0000\u0000\u0000e!ßd/ñõì\f:z¦Î¦±ç·÷Í¢Ëß\u00076*…\bŽ—ñžùC1ÉUÀé2\u001aӆBŒ', 35 | expected: '0x0300000035e8c6d54c5d127c9dcebe9e1a37ab9b05321128d097590a3c100000000000006521df642ff1f5ec0c3a7aa6cea6b1e7b7f7cda2cbdf07362a85088e97f19ef94331c955c0e9321ad386428c'} 36 | ]; 37 | 38 | describe('lib/utils/utils', function () { 39 | describe('toHex', function () { 40 | tests.forEach(function (test) { 41 | it('should turn ' + test.value + ' to ' + test.expected, function () { 42 | assert.strictEqual(utils.toHex(test.value), test.expected); 43 | }); 44 | }); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /web3js/test/utils.toUtf8.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var BigNumber = require('bignumber.js'); 3 | var utils = require('../lib/utils/utils.js'); 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { value: '0x6d79537472696e67', expected: 'myString'}, 8 | { value: '0x6d79537472696e6700', expected: 'myString'}, 9 | { value: '0x65787065637465642076616c7565000000000000000000000000000000000000', expected: 'expected value'} 10 | ]; 11 | 12 | describe('lib/utils/utils', function () { 13 | describe('toUtf8', function () { 14 | tests.forEach(function (test) { 15 | it('should turn ' + test.value + ' to ' + test.expected, function () { 16 | assert.strictEqual(utils.toUtf8(test.value), test.expected); 17 | }); 18 | }); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /web3js/test/utils.toWei.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var utils = require('../lib/utils/utils'); 3 | var assert = chai.assert; 4 | 5 | describe('lib/utils/utils', function () { 6 | describe('toWei', function () { 7 | it('should return the correct value', function () { 8 | 9 | assert.equal(utils.toWei(1, 'wei'), '1'); 10 | assert.equal(utils.toWei(1, 'kwei'), '1000'); 11 | assert.equal(utils.toWei(1, 'Kwei'), '1000'); 12 | assert.equal(utils.toWei(1, 'babbage'), '1000'); 13 | assert.equal(utils.toWei(1, 'mwei'), '1000000'); 14 | assert.equal(utils.toWei(1, 'Mwei'), '1000000'); 15 | assert.equal(utils.toWei(1, 'lovelace'), '1000000'); 16 | assert.equal(utils.toWei(1, 'gwei'), '1000000000'); 17 | assert.equal(utils.toWei(1, 'Gwei'), '1000000000'); 18 | assert.equal(utils.toWei(1, 'shannon'), '1000000000'); 19 | assert.equal(utils.toWei(1, 'szabo'), '1000000000000'); 20 | assert.equal(utils.toWei(1, 'finney'), '1000000000000000'); 21 | assert.equal(utils.toWei(1, 'ether'), '1000000000000000000'); 22 | assert.equal(utils.toWei(1, 'kether'), '1000000000000000000000'); 23 | assert.equal(utils.toWei(1, 'grand'), '1000000000000000000000'); 24 | assert.equal(utils.toWei(1, 'mether'), '1000000000000000000000000'); 25 | assert.equal(utils.toWei(1, 'gether'), '1000000000000000000000000000'); 26 | assert.equal(utils.toWei(1, 'tether'), '1000000000000000000000000000000'); 27 | 28 | assert.equal(utils.toWei(1, 'kwei'), utils.toWei(1, 'femtoether')); 29 | assert.equal(utils.toWei(1, 'szabo'), utils.toWei(1, 'microether')); 30 | assert.equal(utils.toWei(1, 'finney'), utils.toWei(1, 'milliether')); 31 | assert.equal(utils.toWei(1, 'milli'), utils.toWei(1, 'milliether')); 32 | assert.equal(utils.toWei(1, 'milli'), utils.toWei(1000, 'micro')); 33 | 34 | assert.throws(function () {utils.toWei(1, 'wei1');}, Error); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /web3js/test/web3.db.getHex.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'getHex'; 4 | 5 | var tests = [{ 6 | args: ['myDB', 'myKey'], 7 | formattedArgs: ['myDB', 'myKey'], 8 | result: '0xf', 9 | formattedResult: '0xf', 10 | call: 'db_'+ method 11 | }]; 12 | 13 | testMethod.runTests('db', method, tests); 14 | 15 | -------------------------------------------------------------------------------- /web3js/test/web3.db.getString.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var testMethod = require('./helpers/test.method.js'); 3 | 4 | var method = 'getString'; 5 | 6 | var tests = [{ 7 | args: ['myDB', 'myKey'], 8 | formattedArgs: ['myDB', 'myKey'], 9 | result: 'myValue', 10 | formattedResult: 'myValue', 11 | call: 'db_'+ method 12 | }]; 13 | 14 | testMethod.runTests('db', method, tests); 15 | 16 | -------------------------------------------------------------------------------- /web3js/test/web3.db.methods.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index.js'); 4 | var web3 = new Web3(); 5 | var u = require('./helpers/test.utils.js'); 6 | 7 | describe('web3.db', function() { 8 | describe('methods', function() { 9 | u.methodExists(web3.db, 'putHex'); 10 | u.methodExists(web3.db, 'getHex'); 11 | u.methodExists(web3.db, 'putString'); 12 | u.methodExists(web3.db, 'getString'); 13 | }); 14 | }); 15 | 16 | -------------------------------------------------------------------------------- /web3js/test/web3.db.putHex.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var testMethod = require('./helpers/test.method.js'); 4 | 5 | var method = 'putHex'; 6 | 7 | var tests = [{ 8 | args: ['myDB', 'myKey', '0xb'], 9 | formattedArgs: ['myDB', 'myKey', '0xb'], 10 | result: true, 11 | formattedResult: true, 12 | call: 'db_'+ method 13 | }]; 14 | 15 | testMethod.runTests('db', method, tests); 16 | 17 | -------------------------------------------------------------------------------- /web3js/test/web3.db.putString.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var testMethod = require('./helpers/test.method.js'); 4 | 5 | var method = 'putString'; 6 | 7 | var tests = [{ 8 | args: ['myDB', 'myKey', 'myValue'], 9 | formattedArgs: ['myDB', 'myKey', 'myValue'], 10 | result: true, 11 | formattedResult: true, 12 | call: 'db_'+ method 13 | }]; 14 | 15 | testMethod.runTests('db', method, tests); 16 | 17 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.accounts.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | var method = 'accounts'; 8 | 9 | var tests = [{ 10 | result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 11 | formattedResult: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 12 | call: 'eth_'+ method 13 | }]; 14 | 15 | describe('web3.eth', function () { 16 | describe(method, function () { 17 | tests.forEach(function (test, index) { 18 | it('property test: ' + index, function () { 19 | 20 | // given 21 | var provider = new FakeHttpProvider(); 22 | web3.setProvider(provider); 23 | provider.injectResult(test.result); 24 | provider.injectValidation(function (payload) { 25 | assert.equal(payload.jsonrpc, '2.0'); 26 | assert.equal(payload.method, test.call); 27 | assert.deepEqual(payload.params, []); 28 | }); 29 | 30 | // when 31 | var result = web3.eth[method]; 32 | 33 | // then 34 | assert.deepEqual(test.formattedResult, result); 35 | }); 36 | }); 37 | }); 38 | }); 39 | 40 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.blockNumber.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | var method = 'blockNumber'; 8 | 9 | var tests = [{ 10 | result: '0xb', 11 | formattedResult: 11, 12 | call: 'eth_'+ method 13 | }]; 14 | 15 | describe('web3.eth', function () { 16 | describe(method, function () { 17 | tests.forEach(function (test, index) { 18 | it('property test: ' + index, function () { 19 | 20 | // given 21 | var provider = new FakeHttpProvider(); 22 | web3.setProvider(provider); 23 | provider.injectResult(test.result); 24 | provider.injectValidation(function (payload) { 25 | assert.equal(payload.jsonrpc, '2.0'); 26 | assert.equal(payload.method, test.call); 27 | assert.deepEqual(payload.params, []); 28 | }); 29 | 30 | // when 31 | var result = web3.eth[method]; 32 | 33 | // then 34 | assert.strictEqual(test.formattedResult, result); 35 | }); 36 | 37 | it('async get property test: ' + index, function (done) { 38 | 39 | // given 40 | var provider = new FakeHttpProvider(); 41 | web3.setProvider(provider); 42 | provider.injectResult(test.result); 43 | provider.injectValidation(function (payload) { 44 | assert.equal(payload.jsonrpc, '2.0'); 45 | assert.equal(payload.method, test.call); 46 | assert.deepEqual(payload.params, []); 47 | }); 48 | 49 | // when 50 | web3.eth.getBlockNumber(function (err, result) { 51 | assert.strictEqual(test.formattedResult, result); 52 | done(); 53 | }); 54 | 55 | }); 56 | }); 57 | }); 58 | }); 59 | 60 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.call.js: -------------------------------------------------------------------------------- 1 | var testMethod = require('./helpers/test.method.js'); 2 | 3 | var method = 'call'; 4 | 5 | var tests = [{ 6 | args: [{ 7 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 8 | data: '0x23455654', 9 | gas: 11, 10 | gasPrice: 11 11 | }], 12 | formattedArgs: [{ 13 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 14 | data: '0x23455654', 15 | gas: '0xb', 16 | gasPrice: '0xb' 17 | }, 'latest'], 18 | result: '0x31981', 19 | formattedResult: '0x31981', 20 | call: 'eth_'+ method 21 | },{ 22 | args: [{ 23 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 24 | data: '0x23455654', 25 | gas: 11, 26 | gasPrice: 11 27 | }, 11], 28 | formattedArgs: [{ 29 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 30 | data: '0x23455654', 31 | gas: '0xb', 32 | gasPrice: '0xb' 33 | }, '0xb'], 34 | result: '0x31981', 35 | formattedResult: '0x31981', 36 | call: 'eth_'+ method 37 | }]; 38 | 39 | testMethod.runTests('eth', method, tests); 40 | 41 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.coinbase.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | var method = 'coinbase'; 8 | 9 | var tests = [{ 10 | result: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 11 | formattedResult: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 12 | call: 'eth_'+ method 13 | }]; 14 | 15 | describe('web3.eth', function () { 16 | describe(method, function () { 17 | tests.forEach(function (test, index) { 18 | it('property test: ' + index, function () { 19 | 20 | // given 21 | var provider = new FakeHttpProvider(); 22 | web3.setProvider(provider); 23 | provider.injectResult(test.result); 24 | provider.injectValidation(function (payload) { 25 | assert.equal(payload.jsonrpc, '2.0'); 26 | assert.equal(payload.method, test.call); 27 | assert.deepEqual(payload.params, []); 28 | }); 29 | 30 | // when 31 | var result = web3.eth[method]; 32 | 33 | // then 34 | assert.deepEqual(test.formattedResult, result); 35 | }); 36 | }); 37 | }); 38 | }); 39 | 40 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.defaultBlock.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | 6 | describe('web3.eth', function () { 7 | describe('defaultBlock', function () { 8 | it('should check if defaultBlock is set to proper value', function () { 9 | assert.equal(web3.eth.defaultBlock, 'latest'); 10 | }); 11 | }); 12 | }); 13 | 14 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.estimateGas.js: -------------------------------------------------------------------------------- 1 | var web3 = require('../index'); 2 | var testMethod = require('./helpers/test.method.js'); 3 | 4 | var method = 'estimateGas'; 5 | 6 | var tests = [{ 7 | args: [{ 8 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 9 | data: '0x23455654', 10 | gas: 11, 11 | gasPrice: 11 12 | }], 13 | formattedArgs: [{ 14 | to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', 15 | data: '0x23455654', 16 | gas: '0xb', 17 | gasPrice: '0xb' 18 | }], 19 | result: '0x31981', 20 | formattedResult: 203137, 21 | call: 'eth_'+ method 22 | }]; 23 | 24 | testMethod.runTests('eth', method, tests); 25 | 26 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.gasPrice.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var BigNumber = require('bignumber.js'); 6 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 7 | 8 | var method = 'gasPrice'; 9 | 10 | var tests = [{ 11 | result: '0x15f90', 12 | formattedResult: new BigNumber(90000), 13 | call: 'eth_'+ method 14 | }]; 15 | 16 | describe('web3.eth', function () { 17 | describe(method, function () { 18 | tests.forEach(function (test, index) { 19 | it('property test: ' + index, function () { 20 | 21 | // given 22 | var provider = new FakeHttpProvider(); 23 | web3.setProvider(provider); 24 | provider.injectResult(test.result); 25 | provider.injectValidation(function (payload) { 26 | assert.equal(payload.jsonrpc, '2.0'); 27 | assert.equal(payload.method, test.call); 28 | assert.deepEqual(payload.params, []); 29 | }); 30 | 31 | // when 32 | var result = web3.eth[method]; 33 | 34 | // then 35 | assert.deepEqual(test.formattedResult, result); 36 | }); 37 | }); 38 | }); 39 | }); 40 | 41 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getBalance.js: -------------------------------------------------------------------------------- 1 | var BigNumber = require('bignumber.js'); 2 | var Web3 = require('../index'); 3 | var web3 = new Web3(); 4 | var testMethod = require('./helpers/test.method.js'); 5 | 6 | var method = 'getBalance'; 7 | 8 | var tests = [{ 9 | args: ['0x000000000000000000000000000000000000012d', 2], 10 | formattedArgs: ['0x000000000000000000000000000000000000012d', '0x2'], 11 | result: '0x31981', 12 | formattedResult: new BigNumber('0x31981', 16), 13 | call: 'eth_'+ method 14 | },{ 15 | args: ['0x000000000000000000000000000000000000012d', '0x1'], 16 | formattedArgs: ['0x000000000000000000000000000000000000012d', '0x1'], 17 | result: '0x31981', 18 | formattedResult: new BigNumber('0x31981', 16), 19 | call: 'eth_'+ method 20 | }, { 21 | args: ['0x000000000000000000000000000000000000012d', 0x1], 22 | formattedArgs: ['0x000000000000000000000000000000000000012d', '0x1'], 23 | result: '0x31981', 24 | formattedResult: new BigNumber('0x31981', 16), 25 | call: 'eth_'+ method 26 | }, { 27 | args: ['0x000000000000000000000000000000000000012d'], 28 | formattedArgs: ['0x000000000000000000000000000000000000012d', web3.eth.defaultBlock], 29 | result: '0x31981', 30 | formattedResult: new BigNumber('0x31981', 16), 31 | call: 'eth_'+ method 32 | }, { 33 | args: ['0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', 0x1], 34 | formattedArgs: ['0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', '0x1'], 35 | result: '0x31981', 36 | formattedResult: new BigNumber('0x31981', 16), 37 | call: 'eth_'+ method 38 | }, { 39 | args: ['dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', 0x1], 40 | formattedArgs: ['0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', '0x1'], 41 | result: '0x31981', 42 | formattedResult: new BigNumber('0x31981', 16), 43 | call: 'eth_'+ method 44 | }, { 45 | args: ['0x000000000000000000000000000000000000012d', 0x1], 46 | formattedArgs: ['0x000000000000000000000000000000000000012d', '0x1'], 47 | result: '0x31981', 48 | formattedResult: new BigNumber('0x31981', 16), 49 | call: 'eth_'+ method 50 | }, { 51 | args: ['0x000000000000000000000000000000000000012d'], 52 | formattedArgs: ['0x000000000000000000000000000000000000012d', 'latest'], 53 | result: '0x31981', 54 | formattedResult: new BigNumber('0x31981', 16), 55 | call: 'eth_'+ method 56 | }, { 57 | args: ['000000000000000000000000000000000000012d'], 58 | formattedArgs: ['0x000000000000000000000000000000000000012d', 'latest'], 59 | result: '0x31981', 60 | formattedResult: new BigNumber('0x31981', 16), 61 | call: 'eth_'+ method 62 | }, { 63 | args: ['XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'], 64 | formattedArgs: ['0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', 'latest'], 65 | result: '0x31981', 66 | formattedResult: new BigNumber('0x31981', 16), 67 | call: 'eth_'+ method 68 | }]; 69 | 70 | testMethod.runTests('eth', method, tests); 71 | 72 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getBlockTransactionCount.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var testMethod = require('./helpers/test.method.js'); 4 | 5 | var method = 'getBlockTransactionCount'; 6 | 7 | 8 | var tests = [{ 9 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 10 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 11 | result: '0xb', 12 | formattedResult: 11, 13 | call: 'eth_getBlockTransactionCountByHash' 14 | },{ 15 | args: [436], 16 | formattedArgs: ['0x1b4'], 17 | result: '0xb', 18 | formattedResult: 11, 19 | call: 'eth_getBlockTransactionCountByNumber' 20 | },{ 21 | args: ['pending'], 22 | formattedArgs: ['pending'], 23 | result: '0xb', 24 | formattedResult: 11, 25 | call: 'eth_getBlockTransactionCountByNumber' 26 | }]; 27 | 28 | testMethod.runTests('eth', method, tests); 29 | 30 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getBlockUncleCount.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var method = 'getBlockUncleCount'; 4 | var testMethod = require('./helpers/test.method.js'); 5 | 6 | 7 | var tests = [{ 8 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 9 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 10 | result: '0xb', 11 | formattedResult: 11, 12 | call: 'eth_getUncleCountByBlockHash' 13 | },{ 14 | args: [436], 15 | formattedArgs: ['0x1b4'], 16 | result: '0xb', 17 | formattedResult: 11, 18 | call: 'eth_getUncleCountByBlockNumber' 19 | },{ 20 | args: ['pending'], 21 | formattedArgs: ['pending'], 22 | result: '0xb', 23 | formattedResult: 11, 24 | call: 'eth_getUncleCountByBlockNumber' 25 | }]; 26 | 27 | testMethod.runTests('eth', method, tests); 28 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getCode.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Web3 = require('../index'); 3 | var web3 = new Web3(); 4 | var testMethod = require('./helpers/test.method.js'); 5 | 6 | var method = 'getCode'; 7 | 8 | 9 | var tests = [{ 10 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 11 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', web3.eth.defaultBlock], 12 | result: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 13 | formattedResult: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 14 | call: 'eth_'+ method 15 | },{ 16 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 2], 17 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x2'], 18 | result: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 19 | formattedResult: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 20 | call: 'eth_'+ method 21 | }]; 22 | 23 | testMethod.runTests('eth', method, tests); 24 | 25 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getCompilers.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var testMethod = require('./helpers/test.method.js'); 4 | 5 | var method = 'getCompilers'; 6 | 7 | 8 | var tests = [{ 9 | args: [], 10 | formattedArgs: [], 11 | result: ['solidity'], 12 | formattedResult: ['solidity'], 13 | call: 'eth_'+ method 14 | },{ 15 | args: [], 16 | formattedArgs: [], 17 | result: ['solidity'], 18 | formattedResult: ['solidity'], 19 | call: 'eth_'+ method 20 | }]; 21 | 22 | testMethod.runTests('eth', method, tests); 23 | 24 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getStorageAt.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Web3 = require('../index'); 3 | var web3 = new Web3(); 4 | var testMethod = require('./helpers/test.method.js'); 5 | 6 | var method = 'getStorageAt'; 7 | 8 | 9 | var tests = [{ 10 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 2], 11 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x2', web3.eth.defaultBlock], 12 | result: '0x47d33b2', 13 | formattedResult: '0x47d33b2', 14 | call: 'eth_'+ method 15 | },{ 16 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 2, 0], 17 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x2', '0x0'], 18 | result: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 19 | formattedResult: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 20 | call: 'eth_'+ method 21 | },{ 22 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 0xb, 0x0], 23 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0xb', '0x0'], 24 | result: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 25 | formattedResult: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 26 | call: 'eth_'+ method 27 | }, { 28 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 0xb, 'latest'], 29 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0xb', 'latest'], 30 | result: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 31 | formattedResult: '0x47d33b27bb249a2dbab4c0612bf9caf4747d33b27bb249a2dbab4c0612bf9cafd33b27bb249a2dbab4c0612bf9caf4c1950855', 32 | call: 'eth_'+ method 33 | }]; 34 | 35 | testMethod.runTests('eth', method, tests); 36 | 37 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getTransaction.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var BigNumber = require('bignumber.js'); 4 | var testMethod = require('./helpers/test.method.js'); 5 | 6 | var method = 'getTransaction'; 7 | 8 | var txResult = { 9 | "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", 10 | "nonce":"0x5", 11 | "blockHash": "0x6fd9e2a26ab", 12 | "blockNumber": "0x15df", 13 | "transactionIndex": "0x1", 14 | "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 15 | "to":"0x85h43d8a49eeb85d32cf465507dd71d507100c1", 16 | "value":"0x7f110", 17 | "gas": "0x7f110", 18 | "gasPrice":"0x09184e72a000", 19 | "input":"0x603880600c6000396000f30060" 20 | }; 21 | var formattedTxResult = { 22 | "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", 23 | "nonce":5, 24 | "blockHash": "0x6fd9e2a26ab", 25 | "blockNumber": 5599, 26 | "transactionIndex": 1, 27 | "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 28 | "to":"0x85h43d8a49eeb85d32cf465507dd71d507100c1", 29 | "value": new BigNumber(520464), 30 | "gas": 520464, 31 | "gasPrice": new BigNumber(10000000000000), 32 | "input":"0x603880600c6000396000f30060" 33 | }; 34 | 35 | var tests = [{ 36 | args: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'], 37 | formattedArgs: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'], 38 | result: txResult, 39 | formattedResult: formattedTxResult, 40 | call: 'eth_'+ method + 'ByHash' 41 | }]; 42 | 43 | testMethod.runTests('eth', method, tests); 44 | 45 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getTransactionFromBlock.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var BigNumber = require('bignumber.js'); 4 | var testMethod = require('./helpers/test.method.js'); 5 | 6 | var method = 'getTransactionFromBlock'; 7 | 8 | var txResult = { 9 | "status": "mined", 10 | "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", 11 | "nonce":"0xb", 12 | "blockHash": "0x6fd9e2a26ab", 13 | "blockNumber": "0x15df", 14 | "transactionIndex": "0x1", 15 | "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 16 | "to":"0x85h43d8a49eeb85d32cf465507dd71d507100c1", 17 | "value":"0x7f110", 18 | "gas": "0x7f110", 19 | "gasPrice":"0x09184e72a000", 20 | "input":"0x603880600c6000396000f30060" 21 | }; 22 | var formattedTxResult = { 23 | "status": "mined", 24 | "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", 25 | "nonce":11, 26 | "blockHash": "0x6fd9e2a26ab", 27 | "blockNumber": 5599, 28 | "transactionIndex": 1, 29 | "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 30 | "to":"0x85h43d8a49eeb85d32cf465507dd71d507100c1", 31 | "value": new BigNumber(520464), 32 | "gas": 520464, 33 | "gasPrice": new BigNumber(10000000000000), 34 | "input":"0x603880600c6000396000f30060" 35 | }; 36 | 37 | var tests = [{ 38 | args: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855', 2], 39 | formattedArgs: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855', '0x2'], 40 | result: txResult, 41 | formattedResult: formattedTxResult, 42 | call: 'eth_getTransactionByBlockHashAndIndex' 43 | },{ 44 | args: [436, 11], 45 | formattedArgs: ['0x1b4', '0xb'], 46 | result: txResult, 47 | formattedResult: formattedTxResult, 48 | call: 'eth_getTransactionByBlockNumberAndIndex' 49 | }]; 50 | 51 | testMethod.runTests('eth', method, tests); 52 | 53 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getTransactionReceipt.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var BigNumber = require('bignumber.js'); 4 | var testMethod = require('./helpers/test.method.js'); 5 | 6 | var method = 'getTransactionReceipt'; 7 | 8 | var txResult = { 9 | "blockHash": "0x6fd9e2a26ab", 10 | "blockNumber": "0x15df", 11 | "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", 12 | "transactionIndex": "0x1", 13 | "contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 14 | "cumulativeGasUsed":"0x7f110", 15 | "gasUsed": "0x7f110", 16 | "logs": [{ 17 | transactionIndex: '0x3e8', 18 | logIndex: '0x3e8', 19 | blockNumber: '0x3e8', 20 | transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', 21 | blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', 22 | data: '0x7b2274657374223a2274657374227', 23 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 24 | },{ 25 | transactionIndex: null, 26 | logIndex: null, 27 | blockNumber: null, 28 | transactionHash: null, 29 | blockHash: null, 30 | data: '0x7b2274657374223a2274657374227', 31 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 32 | }] 33 | }; 34 | var formattedTxResult = { 35 | "blockHash": "0x6fd9e2a26ab", 36 | "blockNumber": 5599, 37 | "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", 38 | "transactionIndex": 1, 39 | "contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 40 | "cumulativeGasUsed": 520464, 41 | "gasUsed": 520464, 42 | "logs": [{ 43 | transactionIndex: 1000, 44 | logIndex: 1000, 45 | blockNumber: 1000, 46 | transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', 47 | blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', 48 | data: '0x7b2274657374223a2274657374227', 49 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 50 | },{ 51 | transactionIndex: null, 52 | logIndex: null, 53 | blockNumber: null, 54 | transactionHash: null, 55 | blockHash: null, 56 | data: '0x7b2274657374223a2274657374227', 57 | topics: ['0x68656c6c6f','0x6d79746f70696373'] 58 | }] 59 | }; 60 | 61 | var tests = [{ 62 | args: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'], 63 | formattedArgs: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'], 64 | result: txResult, 65 | formattedResult: formattedTxResult, 66 | call: 'eth_'+ method 67 | }]; 68 | 69 | testMethod.runTests('eth', method, tests); 70 | 71 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.getWork.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var testMethod = require('./helpers/test.method.js'); 4 | 5 | var method = 'getWork'; 6 | 7 | var tests = [{ 8 | args: [], 9 | formattedArgs: [], 10 | result: true, 11 | formattedResult: true, 12 | call: 'eth_'+ method 13 | }]; 14 | 15 | testMethod.runTests('eth', method, tests); 16 | 17 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.hashRate.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | var method = 'hashrate'; 8 | 9 | var tests = [{ 10 | result: '0x788a8', 11 | formattedResult: 493736, 12 | call: 'eth_'+ method 13 | }]; 14 | 15 | describe('web3.eth', function () { 16 | describe(method, function () { 17 | tests.forEach(function (test, index) { 18 | it('property test: ' + index, function () { 19 | 20 | // given 21 | var provider = new FakeHttpProvider(); 22 | web3.setProvider(provider); 23 | provider.injectResult(test.result); 24 | provider.injectValidation(function (payload) { 25 | assert.equal(payload.jsonrpc, '2.0'); 26 | assert.equal(payload.method, test.call); 27 | assert.deepEqual(payload.params, []); 28 | }); 29 | 30 | // when 31 | var result = web3.eth[method]; 32 | 33 | // then 34 | assert.strictEqual(test.formattedResult, result); 35 | 36 | // clear the validation 37 | provider.injectValidation(function () {}); 38 | web3.reset(); 39 | }); 40 | }); 41 | }); 42 | }); 43 | 44 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.isSyncing.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Web3 = require('../index'); 3 | var assert = chai.assert; 4 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 5 | 6 | var method = 'isSyncing'; 7 | 8 | var tests = [{ 9 | args: [], 10 | formattedArgs: [], 11 | result: [{ 12 | startingBlock: '0xb', 13 | currentBlock: '0xb', 14 | highestBlock: '0xb' 15 | }], 16 | formattedResult: { 17 | startingBlock: 11, 18 | currentBlock: 11, 19 | highestBlock: 11 20 | }, 21 | call: 'eth_syncing' 22 | }]; 23 | 24 | describe('eth', function () { 25 | describe(method, function () { 26 | tests.forEach(function (test, index) { 27 | it('property test: ' + index, function (done) { 28 | // given 29 | var provider = new FakeHttpProvider(); 30 | var web3 = new Web3(provider); 31 | provider.injectBatchResults(test.result); 32 | provider.injectValidation(function(payload) { 33 | assert.equal(payload[0].jsonrpc, '2.0', 'failed'); 34 | assert.equal(payload[0].method, test.call); 35 | assert.deepEqual(payload[0].params, test.formattedArgs); 36 | }); 37 | 38 | var count = 1; 39 | 40 | // TODO results seem to be overwritten 41 | 42 | 43 | // call 44 | var syncing = web3.eth[method](function(e, res){ 45 | if(count === 1) { 46 | assert.isTrue(res); 47 | count++; 48 | } else { 49 | assert.deepEqual(res, test.formattedResult); 50 | syncing.stopWatching(); 51 | done(); 52 | } 53 | }); 54 | 55 | }); 56 | }); 57 | }); 58 | }); 59 | 60 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.methods.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index.js'); 4 | var web3 = new Web3(); 5 | var u = require('./helpers/test.utils.js'); 6 | 7 | describe('web3.eth', function() { 8 | describe('methods', function() { 9 | u.methodExists(web3.eth, 'getBalance'); 10 | u.methodExists(web3.eth, 'getStorageAt'); 11 | u.methodExists(web3.eth, 'getTransactionCount'); 12 | u.methodExists(web3.eth, 'getCode'); 13 | u.methodExists(web3.eth, 'sendTransaction'); 14 | u.methodExists(web3.eth, 'call'); 15 | u.methodExists(web3.eth, 'getBlock'); 16 | u.methodExists(web3.eth, 'getTransaction'); 17 | u.methodExists(web3.eth, 'getUncle'); 18 | u.methodExists(web3.eth, 'getCompilers'); 19 | u.methodExists(web3.eth.compile, 'lll'); 20 | u.methodExists(web3.eth.compile, 'solidity'); 21 | u.methodExists(web3.eth.compile, 'serpent'); 22 | u.methodExists(web3.eth, 'getBlockTransactionCount'); 23 | u.methodExists(web3.eth, 'getBlockUncleCount'); 24 | u.methodExists(web3.eth, 'filter'); 25 | u.methodExists(web3.eth, 'contract'); 26 | 27 | u.propertyExists(web3.eth, 'coinbase'); 28 | u.propertyExists(web3.eth, 'mining'); 29 | u.propertyExists(web3.eth, 'gasPrice'); 30 | u.propertyExists(web3.eth, 'accounts'); 31 | u.propertyExists(web3.eth, 'defaultBlock'); 32 | u.propertyExists(web3.eth, 'blockNumber'); 33 | }); 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.mining.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | var method = 'mining'; 8 | 9 | var tests = [{ 10 | result: true, 11 | formattedResult: true, 12 | call: 'eth_'+ method 13 | }]; 14 | 15 | describe('web3.eth', function () { 16 | describe(method, function () { 17 | tests.forEach(function (test, index) { 18 | it('property test: ' + index, function () { 19 | 20 | // given 21 | var provider = new FakeHttpProvider(); 22 | web3.setProvider(provider); 23 | provider.injectResult(test.result); 24 | provider.injectValidation(function (payload) { 25 | assert.equal(payload.jsonrpc, '2.0'); 26 | assert.equal(payload.method, test.call); 27 | assert.deepEqual(payload.params, []); 28 | }); 29 | 30 | // when 31 | var result = web3.eth[method]; 32 | 33 | // then 34 | assert.deepEqual(test.formattedResult, result); 35 | }); 36 | }); 37 | }); 38 | }); 39 | 40 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.sendIBANTransaction.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider2 = require('./helpers/FakeHttpProvider2'); 6 | 7 | describe('web3.eth.sendIBANTransaction', function () { 8 | it('should send transaction', function () { 9 | 10 | var iban = 'XE81ETHXREGGAVOFYORK'; 11 | var address = '0x1234567890123456789012345678901234500000'; 12 | var exAddress = '0x1234567890123456789012345678901234567890' 13 | 14 | var provider = new FakeHttpProvider2(); 15 | web3.setProvider(provider); 16 | web3.reset(); 17 | 18 | provider.injectResultList([{ 19 | result: exAddress 20 | }, { 21 | result: '' 22 | }]); 23 | 24 | var step = 0; 25 | provider.injectValidation(function (payload) { 26 | if (step === 0) { 27 | step++; 28 | assert.equal(payload.method, 'eth_call'); 29 | assert.deepEqual(payload.params, [{ 30 | data: "0x3b3b57de5852454700000000000000000000000000000000000000000000000000000000", 31 | to: web3.eth.icapNamereg().address 32 | }, "latest"]); 33 | 34 | return; 35 | } 36 | assert.equal(payload.method, 'eth_sendTransaction'); 37 | assert.deepEqual(payload.params, [{ 38 | data: '0xb214faa54741564f46594f524b0000000000000000000000000000000000000000000000', 39 | from: address, 40 | to: exAddress, 41 | value: payload.params[0].value // don't check this 42 | }]); 43 | }); 44 | 45 | web3.eth.sendIBANTransaction(address, iban, 10000); 46 | 47 | }); 48 | }); 49 | 50 | -------------------------------------------------------------------------------- /web3js/test/web3.eth.submitWork.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var testMethod = require('./helpers/test.method.js'); 4 | 5 | var method = 'submitWork'; 6 | 7 | var tests = [ 8 | { 9 | args: ['0x567890abcdef5555', '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', '0xcdef1234567890abcdef1234567890abcdef0x1234567890abcf1234567890ab'], 10 | formattedArgs: ['0x567890abcdef5555', '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', '0xcdef1234567890abcdef1234567890abcdef0x1234567890abcf1234567890ab'], 11 | result: true, 12 | formattedResult: true, 13 | call: 'eth_'+ method 14 | }]; 15 | 16 | testMethod.runTests('eth', method, tests); 17 | 18 | -------------------------------------------------------------------------------- /web3js/test/web3.extend.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 4 | var Web3 = require('../lib/web3'); 5 | var web3 = new Web3(); 6 | 7 | 8 | var tests = [{ 9 | properties: [new web3._extend.Property({ 10 | name: 'gasPrice', 11 | getter: 'eth_gasPrice', 12 | outputFormatter: web3._extend.formatters.outputBigNumberFormatter 13 | })] 14 | },{ 15 | methods: [new web3._extend.Method({ 16 | name: 'getBalance', 17 | call: 'eth_getBalance', 18 | params: 2, 19 | inputFormatter: [web3._extend.utils.toAddress, web3._extend.formatters.inputDefaultBlockNumberFormatter], 20 | outputFormatter: web3._extend.formatters.outputBigNumberFormatter 21 | })] 22 | },{ 23 | property: 'admin', 24 | properties: [new web3._extend.Property({ 25 | name: 'gasPrice', 26 | getter: 'eth_gasPrice', 27 | outputFormatter: web3._extend.formatters.outputBigNumberFormatter 28 | })], 29 | methods: [new web3._extend.Method({ 30 | name: 'getBalance', 31 | call: 'eth_getBalance', 32 | params: 2, 33 | inputFormatter: [web3._extend.utils.toAddress, web3._extend.formatters.inputDefaultBlockNumberFormatter], 34 | outputFormatter: web3._extend.formatters.outputBigNumberFormatter 35 | })] 36 | }]; 37 | 38 | describe('web3', function () { 39 | describe('_extend', function () { 40 | tests.forEach(function (test, index) { 41 | it('test no: ' + index, function () { 42 | web3._extend(test); 43 | 44 | 45 | if(test.properties) 46 | test.properties.forEach(function(property){ 47 | 48 | var provider = new FakeHttpProvider(); 49 | web3.setProvider(provider); 50 | provider.injectResult(''); 51 | provider.injectValidation(function (payload) { 52 | assert.equal(payload.jsonrpc, '2.0'); 53 | assert.equal(payload.method, property.getter); 54 | }); 55 | 56 | if(test.property) { 57 | assert.isObject(web3[test.property][property.name]); 58 | assert.isFunction(web3[test.property]['get'+ property.name.charAt(0).toUpperCase() + property.name.slice(1)]); 59 | } else { 60 | assert.isObject(web3[property.name]); 61 | assert.isFunction(web3['get'+ property.name.charAt(0).toUpperCase() + property.name.slice(1)]); 62 | } 63 | }); 64 | 65 | if(test.methods) 66 | test.methods.forEach(function(property){ 67 | if(test.property) 68 | assert.isFunction(web3[test.property][property.name]); 69 | else 70 | assert.isFunction(web3[property.name]); 71 | }); 72 | 73 | }); 74 | }); 75 | }); 76 | }); 77 | 78 | -------------------------------------------------------------------------------- /web3js/test/web3.fromICAP.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Web3 = require('../index'); 3 | var web3 = new Web3(); 4 | var assert = chai.assert; 5 | 6 | var tests = [ 7 | { direct: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', address: '00c5496aee77c1ba1f0854206a26dda82a81d6d8'} 8 | ]; 9 | 10 | describe('web3', function () { 11 | describe('fromICAP', function () { 12 | tests.forEach(function (test) { 13 | it('shoud transform iban to address: ' + test.address, function () { 14 | assert.deepEqual(web3.fromICAP(test.direct), test.address); 15 | }); 16 | }); 17 | }); 18 | }); 19 | 20 | -------------------------------------------------------------------------------- /web3js/test/web3.methods.js: -------------------------------------------------------------------------------- 1 | var Web3 = require('../index.js'); 2 | var web3 = new Web3(); 3 | var u = require('./helpers/test.utils.js'); 4 | 5 | describe('web3', function() { 6 | describe('methods', function () { 7 | u.methodExists(web3, 'sha3'); 8 | u.methodExists(web3, 'toAscii'); 9 | u.methodExists(web3, 'fromAscii'); 10 | u.methodExists(web3, 'toDecimal'); 11 | u.methodExists(web3, 'fromDecimal'); 12 | u.methodExists(web3, 'fromWei'); 13 | u.methodExists(web3, 'toWei'); 14 | u.methodExists(web3, 'toBigNumber'); 15 | u.methodExists(web3, 'isAddress'); 16 | u.methodExists(web3, 'setProvider'); 17 | u.methodExists(web3, 'reset'); 18 | 19 | u.propertyExists(web3, 'providers'); 20 | u.propertyExists(web3, 'eth'); 21 | u.propertyExists(web3, 'db'); 22 | u.propertyExists(web3, 'shh'); 23 | }); 24 | }); 25 | 26 | -------------------------------------------------------------------------------- /web3js/test/web3.net.listening.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | var method = 'listening'; 8 | 9 | var tests = [{ 10 | result: true, 11 | formattedResult: true, 12 | call: 'net_'+ method 13 | }]; 14 | 15 | describe('web3.net', function () { 16 | describe(method, function () { 17 | tests.forEach(function (test, index) { 18 | it('property test: ' + index, function () { 19 | 20 | // given 21 | var provider = new FakeHttpProvider(); 22 | web3.setProvider(provider); 23 | provider.injectResult(test.result); 24 | provider.injectValidation(function (payload) { 25 | assert.equal(payload.jsonrpc, '2.0'); 26 | assert.equal(payload.method, test.call); 27 | assert.deepEqual(payload.params, []); 28 | }); 29 | 30 | // when 31 | var result = web3.net[method]; 32 | 33 | // then 34 | assert.deepEqual(test.formattedResult, result); 35 | }); 36 | }); 37 | }); 38 | }); 39 | 40 | -------------------------------------------------------------------------------- /web3js/test/web3.net.methods.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index.js'); 4 | var web3 = new Web3(); 5 | var u = require('./helpers/test.utils.js'); 6 | 7 | describe('web3.net', function() { 8 | describe('methods', function() { 9 | u.propertyExists(web3.net, 'listening'); 10 | u.propertyExists(web3.net, 'peerCount'); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /web3js/test/web3.net.peerCount.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | var method = 'peerCount'; 8 | 9 | var tests = [{ 10 | result: '0xf', 11 | formattedResult: 15, 12 | call: 'net_'+ method 13 | }]; 14 | 15 | describe('web3.net', function () { 16 | describe(method, function () { 17 | tests.forEach(function (test, index) { 18 | it('property test: ' + index, function () { 19 | 20 | // given 21 | var provider = new FakeHttpProvider(); 22 | web3.setProvider(provider); 23 | provider.injectResult(test.result); 24 | provider.injectValidation(function (payload) { 25 | assert.equal(payload.jsonrpc, '2.0'); 26 | assert.equal(payload.method, test.call); 27 | assert.deepEqual(payload.params, []); 28 | }); 29 | 30 | // when 31 | var result = web3.net[method]; 32 | 33 | // then 34 | assert.deepEqual(test.formattedResult, result); 35 | }); 36 | }); 37 | }); 38 | }); 39 | 40 | -------------------------------------------------------------------------------- /web3js/test/web3.personal.listAccounts.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var web3 = new Web3(); 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | var method = 'listAccounts'; 8 | 9 | var tests = [{ 10 | result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 11 | formattedResult: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 12 | call: 'personal_'+ method 13 | }]; 14 | 15 | describe('web3.personal', function () { 16 | describe(method, function () { 17 | tests.forEach(function (test, index) { 18 | it('property test: ' + index, function () { 19 | 20 | // given 21 | var provider = new FakeHttpProvider(); 22 | web3.setProvider(provider); 23 | provider.injectResult(test.result); 24 | provider.injectValidation(function (payload) { 25 | assert.equal(payload.jsonrpc, '2.0'); 26 | assert.equal(payload.method, test.call); 27 | assert.deepEqual(payload.params, []); 28 | }); 29 | 30 | // when 31 | var result = web3.personal[method]; 32 | 33 | // then 34 | assert.deepEqual(test.formattedResult, result); 35 | }); 36 | }); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /web3js/test/web3.personal.methods.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index.js'); 4 | var web3 = new Web3(); 5 | var u = require('./helpers/test.utils.js'); 6 | 7 | describe('web3.net', function() { 8 | describe('methods', function() { 9 | u.propertyExists(web3.personal, 'listAccounts'); 10 | u.methodExists(web3.personal, 'newAccount'); 11 | u.methodExists(web3.personal, 'unlockAccount'); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /web3js/test/web3.personal.newAccount.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var testMethod = require('./helpers/test.method.js'); 4 | 5 | var method = 'newAccount'; 6 | 7 | var tests = [{ 8 | args: ['P@ssw0rd!'], 9 | formattedArgs: ['P@ssw0rd!'], 10 | result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 11 | formattedResult: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'], 12 | call: 'personal_'+ method 13 | }]; 14 | 15 | testMethod.runTests('personal', method, tests); 16 | -------------------------------------------------------------------------------- /web3js/test/web3.personal.unlockAccount.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var testMethod = require('./helpers/test.method.js'); 4 | 5 | var method = 'unlockAccount'; 6 | 7 | var tests = [{ 8 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 'P@ssw0rd!'], 9 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 'P@ssw0rd!', null], 10 | result: true, 11 | formattedResult: true, 12 | call: 'personal_'+ method 13 | },{ 14 | args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 'P@ssw0rd!', 10], 15 | formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 'P@ssw0rd!', 10], 16 | result: true, 17 | formattedResult: true, 18 | call: 'personal_'+ method 19 | }]; 20 | 21 | testMethod.runTests('personal', method, tests); 22 | -------------------------------------------------------------------------------- /web3js/test/web3.sha3.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index'); 4 | var sha3 = require('../lib/utils/sha3'); 5 | var web3 = new Web3(); 6 | 7 | var method = 'sha3'; 8 | 9 | describe('web3.sha3', function () { 10 | it('should return sha3 with hex prefix', function() { 11 | test1 = web3.sha3('test123'); 12 | test2 = web3.sha3('test(int)'); 13 | test3 = web3.sha3('0x80', {encoding: 'hex'}); 14 | test4 = web3.sha3('0x3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1', {encoding: 'hex'}); 15 | assert.deepEqual(test1, '0x' + sha3('test123')); 16 | assert.deepEqual(test2, '0x' + sha3('test(int)')); 17 | assert.deepEqual(test3, '0x' + sha3('0x80', {encoding: 'hex'})); 18 | assert.deepEqual(test4, '0x' + sha3('0x3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1', {encoding: 'hex'})); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /web3js/test/web3.shh.filter.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Web3 = require('../index'); 3 | var web3 = new Web3(); 4 | var assert = chai.assert; 5 | var FakeHttpProvider = require('./helpers/FakeHttpProvider'); 6 | 7 | var method = 'filter'; 8 | 9 | var tests = [{ 10 | args: [{ 11 | to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 12 | topics: ['0x324f5435', '0x564b4566f3453'] 13 | }], 14 | formattedArgs: [{ 15 | to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 16 | topics: ['0x324f5435', '0x564b4566f3453'] 17 | }], 18 | result: '0xf', 19 | formattedResult: '0xf', 20 | call: 'shh_newFilter' 21 | }, 22 | { 23 | args: [{ 24 | to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 25 | topics: ['0x324f5435', ['0x564b4566f3453', '0x345345343453']] 26 | }], 27 | formattedArgs: [{ 28 | to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 29 | topics: ['0x324f5435', ['0x564b4566f3453', '0x345345343453']] 30 | }], 31 | result: '0xf', 32 | formattedResult: '0xf', 33 | call: 'shh_newFilter' 34 | }, 35 | { 36 | args: [{ 37 | to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 38 | topics: ['0x324f5435', null, ['0x564b4566f3453', '0x345345343453']] 39 | }], 40 | formattedArgs: [{ 41 | to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 42 | topics: ['0x324f5435', null, ['0x564b4566f3453', '0x345345343453']] 43 | }], 44 | result: '0xf', 45 | formattedResult: '0xf', 46 | call: 'shh_newFilter' 47 | }, 48 | { 49 | args: [{ 50 | to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 51 | topics: ['myString', 11, '23', null] 52 | }], 53 | formattedArgs: [{ 54 | to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 55 | topics: ['0x6d79537472696e67', '0x3131', '0x3233', null] 56 | }], 57 | result: '0xf', 58 | formattedResult: '0xf', 59 | call: 'shh_newFilter' 60 | }]; 61 | 62 | describe('shh', function () { 63 | describe(method, function () { 64 | tests.forEach(function (test, index) { 65 | it('property test: ' + index, function () { 66 | 67 | // given 68 | var provider = new FakeHttpProvider(); 69 | web3.setProvider(provider); 70 | web3.reset(); 71 | provider.injectResult(test.result); 72 | provider.injectValidation(function (payload) { 73 | assert.equal(payload.jsonrpc, '2.0'); 74 | assert.equal(payload.method, test.call); 75 | assert.deepEqual(payload.params, test.formattedArgs); 76 | }); 77 | 78 | // call 79 | web3.shh[method].apply(web3.shh, test.args); 80 | 81 | }); 82 | }); 83 | }); 84 | }); 85 | 86 | -------------------------------------------------------------------------------- /web3js/test/web3.shh.hasIdentity.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var web3 = require('../index'); 3 | var testMethod = require('./helpers/test.method.js'); 4 | 5 | var method = 'hasIdentity'; 6 | 7 | var tests = [{ 8 | args: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'], 9 | formattedArgs: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'], 10 | result: true, 11 | formattedResult: true, 12 | call: 'shh_'+ method 13 | }]; 14 | 15 | testMethod.runTests('shh', method, tests); 16 | 17 | -------------------------------------------------------------------------------- /web3js/test/web3.shh.methods.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var assert = chai.assert; 3 | var Web3 = require('../index.js'); 4 | var web3 = new Web3(); 5 | var u = require('./helpers/test.utils.js'); 6 | 7 | describe('web3.shh', function() { 8 | describe('methods', function() { 9 | u.methodExists(web3.shh, 'post'); 10 | u.methodExists(web3.shh, 'newIdentity'); 11 | u.methodExists(web3.shh, 'hasIdentity'); 12 | u.methodExists(web3.shh, 'newGroup'); 13 | u.methodExists(web3.shh, 'addToGroup'); 14 | u.methodExists(web3.shh, 'filter'); 15 | }); 16 | }); 17 | 18 | -------------------------------------------------------------------------------- /web3js/test/web3.shh.post.js: -------------------------------------------------------------------------------- 1 | var chai = require('chai'); 2 | var Web3 = require('../index'); 3 | var web3 = new Web3(); 4 | var testMethod = require('./helpers/test.method.js'); 5 | 6 | var method = 'post'; 7 | 8 | var tests = [{ 9 | args: [{ 10 | from: '0x123123123', 11 | topics: ['hello_world'], 12 | payload: web3.toHex('12345'), 13 | ttl: 100, 14 | workToProve: 101 15 | }], 16 | formattedArgs: [{ 17 | from: '0x123123123', 18 | topics: [web3.fromAscii('hello_world')], 19 | payload: web3.toHex('12345'), 20 | ttl: web3.toHex('100'), 21 | workToProve: web3.toHex('101'), 22 | priority: '0x0' 23 | }], 24 | result: true, 25 | formattedResult: true, 26 | call: 'shh_'+ method 27 | }, { 28 | args: [{ 29 | from: '0x21312', 30 | topics: ['hello_world'], 31 | payload: '0x12345', 32 | ttl: 0x100, 33 | workToProve: 0x101, 34 | priority: 0x15 35 | }], 36 | formattedArgs: [{ 37 | from: '0x21312', 38 | topics: [web3.fromAscii('hello_world')], 39 | payload: '0x12345', 40 | ttl: '0x100', 41 | workToProve: '0x101', 42 | priority: '0x15' 43 | }], 44 | result: true, 45 | formattedResult: true, 46 | call: 'shh_'+ method 47 | }]; 48 | 49 | testMethod.runTests('shh', method, tests); 50 | 51 | --------------------------------------------------------------------------------