diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-06-07 15:29:46 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-06-07 15:29:46 +0800 |
commit | 58f2e59e2aa8c20b09cc4e1da0dcb0fd8caea12b (patch) | |
tree | bb6b191aad4911122fc4984fcec7af72ce5c6174 | |
parent | 710a1463c18dea96bd1f03d7ea62a95702d92d72 (diff) | |
download | dexon-solidity-58f2e59e2aa8c20b09cc4e1da0dcb0fd8caea12b.tar.gz dexon-solidity-58f2e59e2aa8c20b09cc4e1da0dcb0fd8caea12b.tar.zst dexon-solidity-58f2e59e2aa8c20b09cc4e1da0dcb0fd8caea12b.zip |
Squashed 'libjsqrc/ethereumjs/' changes from 16861fc..ca46cb5
ca46cb5 updated examples
aff3497 updated icap example
9fa9b16 gulp
61f1ba6 Merge pull request #224 from alexvandesande/prefix-name-reorg
448dd30 Merge branch 'master' into develop
7753724 build files
fc3dc7a build files
c9ebd7e version 0.5.0
448cf03 Merge branch 'master' into develop
43e8f0e Merge pull request #207 from ethereum/icap
0a56733 updated icap example
e67e705 Merge pull request #223 from ethereum/revert-222-master
f229f4e Revert "sync sendTransaction returning tx address"
ca58837 Merge pull request #222 from jesuscript/master
66a2b6c sync sendTransaction returning tx address
b19e46c updated "deposit" method description, updated icap example contract abi
fbb9a41 Merge branch 'develop' into icap
3bb6e4f sha3 backward compatibility. #205
d0be181 fixed const functions calls handling errors
858d0c6 lint
95aabe3 sendIBANTransaction && tests
5866f08 milli should have two l's
bacb03c Rename Kwei to kwei, added support for some SI base units for ether
dfd5060 use "official" namereg, updated examples
d8ad2b7 Merge branch 'develop' into icap
3fb420f Merge branch 'master' into develop
ea4d66e updated examples
e6209c6 Merge branch 'master' into develop
71ae809 version 0.4.3
92e2a2f Merge branch 'master' into develop
d03bec6 decoding of empty array, fixed #210, fixed #211
9abf38a fixed encoding of empty arrays
2ad458c Merge pull request #212 from ethereum/estimateGas
be2e93f build
d4bf850 fixed typo
0594e7f add estimateGas to contract methods and fixed sendTransaction return value
55c4653 test/isIBAN.js
e9483a6 icap.html example
6fb04d8 namereg example allows to register custom names
60c9bf8 removed natspec example, added namereg example
cd773fc updated docs
4af0085 web3.eth.namereg contract, icap in progress
02556ea removed unnecessary file
d320552 crypto-js integrated into project
adf91df sha3 init
git-subtree-dir: libjsqrc/ethereumjs
git-subtree-split: ca46cb5c94da4d37e9f4a5b8f6c0d117b72668d7
-rw-r--r-- | batch.js | 4 | ||||
-rw-r--r-- | coder.decodeParam.js | 2 | ||||
-rw-r--r-- | coder.encodeParam.js | 2 | ||||
-rw-r--r-- | contract.js | 308 | ||||
-rw-r--r-- | sha3.js | 17 | ||||
-rw-r--r-- | utils.isIBAN.js | 32 | ||||
-rw-r--r-- | utils.toWei.js | 8 | ||||
-rw-r--r-- | web3.eth.sendIBANTransaction.js | 49 | ||||
-rw-r--r-- | web3.sha3.js | 16 |
9 files changed, 240 insertions, 198 deletions
@@ -58,10 +58,6 @@ describe('lib/web3/batch', function () { var address = '0x0000000000000000000000000000000000000000'; var result = '0x126'; var result2 = '0x0000000000000000000000000000000000000000000000000000000000000123'; - var signature = '0x001122334455'; - - // TODO: fix this, maybe in browser sha3? - provider.injectResult(signature); var counter = 0; var callback = function (err, r) { diff --git a/coder.decodeParam.js b/coder.decodeParam.js index 23b0228e..959e96cf 100644 --- a/coder.decodeParam.js +++ b/coder.decodeParam.js @@ -24,6 +24,8 @@ describe('lib/solidity/coder', function () { test({ type: 'bytes', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); + test({ type: 'int[]', expected: [], value: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000000'}); test({ type: 'int[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003'}); diff --git a/coder.encodeParam.js b/coder.encodeParam.js index 60d1c618..55ff657c 100644 --- a/coder.encodeParam.js +++ b/coder.encodeParam.js @@ -24,6 +24,8 @@ describe('lib/solidity/coder', function () { test({ type: 'bytes', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); + test({ type: 'int[]', value: [], expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000000'}); test({ type: 'int[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000003'}); diff --git a/contract.js b/contract.js index a46a8cab..00f9cbcc 100644 --- a/contract.js +++ b/contract.js @@ -5,6 +5,7 @@ var FakeHttpProvider = require('./helpers/FakeHttpProvider'); var FakeHttpProvider2 = require('./helpers/FakeHttpProvider2'); var utils = require('../lib/utils/utils'); var BigNumber = require('bignumber.js'); +var sha3 = require('../lib/utils/sha3'); var desc = [{ "name": "balance(address)", @@ -60,34 +61,28 @@ describe('web3.eth.contract', function () { var provider = new FakeHttpProvider(); web3.setProvider(provider); web3.reset(); // reset different polls - var sha3 = '0x5131231231231231231231'; - provider.injectResult(sha3); + var signature = 'Changed(address,uint256,uint256,uint256)'; var step = 0; provider.injectValidation(function (payload) { if (step === 0) { step = 1; - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'web3_sha3'); - assert.equal(payload.params[0], web3.fromAscii('Changed(address,uint256,uint256,uint256)')); - } else if (step === 1) { - step = 2; provider.injectResult(3); assert.equal(payload.jsonrpc, '2.0'); assert.equal(payload.method, 'eth_newFilter'); assert.deepEqual(payload.params[0], { topics: [ - sha3, + '0x' + sha3(signature), '0x0000000000000000000000001234567890123456789012345678901234567890', null ], address: '0x1234567890123456789012345678901234567890' }); - } else if (step === 2) { - step = 3; + } else if (step === 1) { + step = 2; provider.injectResult([{ address: address, topics: [ - sha3, + '0x' + sha3(signature), '0x0000000000000000000000001234567890123456789012345678901234567890', '0x0000000000000000000000000000000000000000000000000000000000000001' ], @@ -97,11 +92,11 @@ describe('web3.eth.contract', function () { }]); assert.equal(payload.jsonrpc, '2.0'); assert.equal(payload.method, 'eth_getFilterLogs'); - } else if (step === 3 && utils.isArray(payload)) { + } else if (step === 2 && utils.isArray(payload)) { provider.injectBatchResults([[{ address: address, topics: [ - sha3, + '0x' + sha3(signature), '0x0000000000000000000000001234567890123456789012345678901234567890', '0x0000000000000000000000000000000000000000000000000000000000000001' ], @@ -135,53 +130,37 @@ describe('web3.eth.contract', function () { var provider = new FakeHttpProvider(); web3.setProvider(provider); web3.reset(); - var sha3 = '0x5131231231231231231231'; + provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032'); + var signature = 'balance(address)' var address = '0x1234567890123456789012345678901234567890'; - provider.injectResult(sha3); - var step = 0; provider.injectValidation(function (payload) { - if (step === 0) { - step = 1; - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'web3_sha3'); - assert.equal(payload.params[0], web3.fromAscii('balance(address)')); - } else if (step === 1) { - assert.equal(payload.method, 'eth_call'); - assert.deepEqual(payload.params, [{ - data: sha3.slice(0, 10) + '0000000000000000000000001234567890123456789012345678901234567890', - to: address - }, 'latest']); - } + assert.equal(payload.method, 'eth_call'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890', + to: address + }, 'latest']); }); var contract = web3.eth.contract(desc).at(address); - contract.balance(address); + var r = contract.balance(address); + assert.deepEqual(new BigNumber(0x32), r); }); it('should sendTransaction to contract function', function () { var provider = new FakeHttpProvider(); web3.setProvider(provider); web3.reset(); - var sha3 = '0x5131231231231231231231'; + var signature = 'send(address,uint256)'; var address = '0x1234567890123456789012345678901234567890'; - provider.injectResult(sha3); - var step = 0; provider.injectValidation(function (payload) { - if (step === 0) { - step = 1; - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'web3_sha3'); - assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)')); - } else if (step === 1) { - assert.equal(payload.method, 'eth_sendTransaction'); - assert.deepEqual(payload.params, [{ - data: sha3.slice(0, 10) + - '0000000000000000000000001234567890123456789012345678901234567890' + - '0000000000000000000000000000000000000000000000000000000000000011' , - to: address - }]); - } + assert.equal(payload.method, 'eth_sendTransaction'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + + '0000000000000000000000001234567890123456789012345678901234567890' + + '0000000000000000000000000000000000000000000000000000000000000011' , + to: address + }]); }); var contract = web3.eth.contract(desc).at(address); @@ -194,30 +173,23 @@ describe('web3.eth.contract', function () { var provider = new FakeHttpProvider(); web3.setProvider(provider); web3.reset(); - var sha3 = '0x5131231231231231231231'; + provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032'); + var signature = 'balance(address)'; var address = '0x1234567890123456789012345678901234567890'; - provider.injectResult(sha3); - var step = 0; provider.injectValidation(function (payload) { - if (step === 0) { - step = 1; - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'web3_sha3'); - assert.equal(payload.params[0], web3.fromAscii('balance(address)')); - } else if (step === 1) { - assert.equal(payload.method, 'eth_call'); - assert.deepEqual(payload.params, [{ - data: sha3.slice(0, 10) + '0000000000000000000000001234567890123456789012345678901234567890', - to: address, - from: address, - gas: '0xc350' - }, 'latest']); - } + assert.equal(payload.method, 'eth_call'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890', + to: address, + from: address, + gas: '0xc350' + }, 'latest']); }); var contract = web3.eth.contract(desc).at(address); - contract.balance(address, {from: address, gas: 50000}); + var r = contract.balance(address, {from: address, gas: 50000}); + assert.deepEqual(new BigNumber(0x32), r); }); @@ -226,30 +198,23 @@ describe('web3.eth.contract', function () { var provider = new FakeHttpProvider(); web3.setProvider(provider); web3.reset(); - var sha3 = '0x5131231231231231231231'; + provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000032'); + var signature = 'balance(address)'; var address = '0x1234567890123456789012345678901234567890'; - provider.injectResult(sha3); - var step = 0; provider.injectValidation(function (payload) { - if (step === 0) { - step = 1; - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'web3_sha3'); - assert.equal(payload.params[0], web3.fromAscii('balance(address)')); - } else if (step === 1) { - assert.equal(payload.method, 'eth_call'); - assert.deepEqual(payload.params, [{ - data: sha3.slice(0, 10) + '0000000000000000000000001234567890123456789012345678901234567890', - to: address, - from: address, - gas: '0xc350' - }, 'latest']); - } + assert.equal(payload.method, 'eth_call'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + '0000000000000000000000001234567890123456789012345678901234567890', + to: address, + from: address, + gas: '0xc350' + }, 'latest']); }); var contract = web3.eth.contract(desc).at(address); - contract.balance.call(address, {from: address, gas: 50000}); + var r = contract.balance.call(address, {from: address, gas: 50000}); + assert.deepEqual(new BigNumber(0x32), r); }); @@ -257,29 +222,20 @@ describe('web3.eth.contract', function () { var provider = new FakeHttpProvider(); web3.setProvider(provider); web3.reset(); - var sha3 = '0x5131231231231231231231'; + var signature = 'send(address,uint256)'; var address = '0x1234567890123456789012345678901234567890'; - provider.injectResult(sha3); - var step = 0; provider.injectValidation(function (payload) { - if (step === 0) { - step = 1; - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'web3_sha3'); - assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)')); - } else if (step === 1) { - assert.equal(payload.method, 'eth_sendTransaction'); - assert.deepEqual(payload.params, [{ - data: sha3.slice(0, 10) + - '0000000000000000000000001234567890123456789012345678901234567890' + - '0000000000000000000000000000000000000000000000000000000000000011' , - to: address, - from: address, - gas: '0xc350', - gasPrice: '0xbb8', - value: '0x2710' - }]); - } + assert.equal(payload.method, 'eth_sendTransaction'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + + '0000000000000000000000001234567890123456789012345678901234567890' + + '0000000000000000000000000000000000000000000000000000000000000011' , + to: address, + from: address, + gas: '0xc350', + gasPrice: '0xbb8', + value: '0x2710' + }]); }); var contract = web3.eth.contract(desc).at(address); @@ -291,29 +247,20 @@ describe('web3.eth.contract', function () { var provider = new FakeHttpProvider(); web3.setProvider(provider); web3.reset(); - var sha3 = '0x5131231231231231231231'; + var signature = 'send(address,uint256)'; var address = '0x1234567890123456789012345678901234567890'; - provider.injectResult(sha3); - var step = 0; provider.injectValidation(function (payload) { - if (step === 0) { - step = 1; - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'web3_sha3'); - assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)')); - } else if (step === 1) { - assert.equal(payload.method, 'eth_sendTransaction'); - assert.deepEqual(payload.params, [{ - data: sha3.slice(0, 10) + - '0000000000000000000000001234567890123456789012345678901234567890' + - '0000000000000000000000000000000000000000000000000000000000000011' , - to: address, - from: address, - gas: '0xc350', - gasPrice: '0xbb8', - value: '0x2710' - }]); - } + assert.equal(payload.method, 'eth_sendTransaction'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + + '0000000000000000000000001234567890123456789012345678901234567890' + + '0000000000000000000000000000000000000000000000000000000000000011' , + to: address, + from: address, + gas: '0xc350', + gasPrice: '0xbb8', + value: '0x2710' + }]); }); var contract = web3.eth.contract(desc).at(address); @@ -325,29 +272,20 @@ describe('web3.eth.contract', function () { var provider = new FakeHttpProvider(); web3.setProvider(provider); web3.reset(); - var sha3 = '0x5131231231231231231231'; var address = '0x1234567890123456789012345678901234567890'; - provider.injectResult(sha3); - var step = 0; + var signature = 'send(address,uint256)'; provider.injectValidation(function (payload) { - if (step === 0) { - step = 1; - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'web3_sha3'); - assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)')); - } else if (step === 1) { - assert.equal(payload.method, 'eth_sendTransaction'); - assert.deepEqual(payload.params, [{ - data: sha3.slice(0, 10) + - '0000000000000000000000001234567890123456789012345678901234567890' + - '0000000000000000000000000000000000000000000000000000000000000011' , - to: address, - from: address, - gas: '0xc350', - gasPrice: '0xbb8', - value: '0x2710' - }]); - } + assert.equal(payload.method, 'eth_sendTransaction'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + + '0000000000000000000000001234567890123456789012345678901234567890' + + '0000000000000000000000000000000000000000000000000000000000000011' , + to: address, + from: address, + gas: '0xc350', + gasPrice: '0xbb8', + value: '0x2710' + }]); }); var contract = web3.eth.contract(desc).at(address); @@ -358,32 +296,52 @@ describe('web3.eth.contract', function () { }); }); + it('should explicitly estimateGas with optional params', function () { + var provider = new FakeHttpProvider(); + web3.setProvider(provider); + web3.reset(); + var signature = 'send(address,uint256)'; + var address = '0x1234567890123456789012345678901234567890'; + provider.injectValidation(function (payload) { + assert.equal(payload.method, 'eth_estimateGas'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + + '0000000000000000000000001234567890123456789012345678901234567890' + + '0000000000000000000000000000000000000000000000000000000000000011' , + to: address, + from: address, + gas: '0xc350', + gasPrice: '0xbb8', + value: '0x2710' + }]); + }); + + var contract = web3.eth.contract(desc).at(address); + + contract.send.estimateGas(address, 17, {from: address, gas: 50000, gasPrice: 3000, value: 10000}); + }); + it('should call testArr method and properly parse result', function () { var provider = new FakeHttpProvider2(); web3.setProvider(provider); web3.reset(); - var sha3 = '0x5131231231231231231231'; + var signature = 'testArr(int[])'; var address = '0x1234567890123456789012345678901234567890'; provider.injectResultList([{ - result: sha3 - }, { result: '0x0000000000000000000000000000000000000000000000000000000000000005' }]); - var step = 0; + provider.injectValidation(function (payload) { - if (step === 1) { // getting sha3 is first - assert.equal(payload.method, 'eth_call'); - assert.deepEqual(payload.params, [{ - data: sha3.slice(0, 10) + - '0000000000000000000000000000000000000000000000000000000000000020' + - '0000000000000000000000000000000000000000000000000000000000000001' + - '0000000000000000000000000000000000000000000000000000000000000003', - to: address - }, - 'latest' + assert.equal(payload.method, 'eth_call'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + + '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000003', + to: address + }, + 'latest' ]); - } - step++; }); var contract = web3.eth.contract(desc).at(address); @@ -396,28 +354,22 @@ describe('web3.eth.contract', function () { var provider = new FakeHttpProvider2(); web3.setProvider(provider); web3.reset(); - var sha3 = '0x5131231231231231231231'; + var signature = 'testArr(int[])'; var address = '0x1234567890123456789012345678901234567890'; provider.injectResultList([{ - result: sha3 - }, { result: '0x0000000000000000000000000000000000000000000000000000000000000005' }]); - var step = 0; provider.injectValidation(function (payload) { - if (step === 1) { // getting sha3 is first - assert.equal(payload.method, 'eth_call'); - assert.deepEqual(payload.params, [{ - data: sha3.slice(0, 10) + - '0000000000000000000000000000000000000000000000000000000000000020' + - '0000000000000000000000000000000000000000000000000000000000000001' + - '0000000000000000000000000000000000000000000000000000000000000003', - to: address - }, - 'latest' - ]); - } - step++; + assert.equal(payload.method, 'eth_call'); + assert.deepEqual(payload.params, [{ + data: '0x' + sha3(signature).slice(0, 8) + + '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000003', + to: address + }, + 'latest' + ]); }); var contract = web3.eth.contract(desc).at(address); diff --git a/sha3.js b/sha3.js new file mode 100644 index 00000000..e349887e --- /dev/null +++ b/sha3.js @@ -0,0 +1,17 @@ +var chai = require('chai'); +var assert = chai.assert; +var sha3 = require('../lib/utils/sha3'); +var web3 = require('../index'); + +describe('lib/utils/sha3', function () { + var test = function (v, e) { + it('should encode ' + v + ' to ' + e, function () { + assert.equal(sha3(v), e); + }); + }; + + test('test123', 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad'); + test('test(int)', 'f4d03772bec1e62fbe8c5691e1a9101e520e8f8b5ca612123694632bf3cb51b1'); + test(web3.fromAscii('test123'), 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad'); +}); + diff --git a/utils.isIBAN.js b/utils.isIBAN.js new file mode 100644 index 00000000..194ccaa2 --- /dev/null +++ b/utils.isIBAN.js @@ -0,0 +1,32 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var assert = chai.assert; + +var tests = [ + { obj: function () {}, is: false}, + { obj: new Function(), is: false}, + { obj: 'function', is: false}, + { obj: {}, is: false}, + { obj: '[]', is: false}, + { obj: '[1, 2]', is: false}, + { obj: '{}', is: false}, + { obj: '{"a": 123, "b" :3,}', is: false}, + { obj: '{"c" : 2}', is: false}, + { obj: 'XE81ETHXREGGAVOFYORK', is: true}, + { obj: 'XE81ETCXREGGAVOFYORK', is: false}, + { obj: 'XE81ETHXREGGAVOFYORKD', is: false}, + { obj: 'XE81ETHXREGGaVOFYORK', is: false}, + { obj: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: true}, + { obj: 'XD7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: false} +]; + +describe('lib/utils/utils', function () { + describe('isIBAN', function () { + tests.forEach(function (test) { + it('shoud test if value ' + test.obj + ' is iban: ' + test.is, function () { + assert.equal(utils.isIBAN(test.obj), test.is); + }); + }); + }); +}); + diff --git a/utils.toWei.js b/utils.toWei.js index 3bb0997c..55b6c932 100644 --- a/utils.toWei.js +++ b/utils.toWei.js @@ -19,6 +19,14 @@ describe('lib/utils/utils', function () { assert.equal(utils.toWei(1, 'gether'), '1000000000000000000000000000'); assert.equal(utils.toWei(1, 'tether'), '1000000000000000000000000000000'); + assert.equal(utils.toWei(1, 'kwei'), utils.toWei(1, 'femtoether')); + assert.equal(utils.toWei(1, 'babbage'), utils.toWei(1, 'picoether')); + assert.equal(utils.toWei(1, 'shannon'), utils.toWei(1, 'nanoether')); + assert.equal(utils.toWei(1, 'szabo'), utils.toWei(1, 'microether')); + assert.equal(utils.toWei(1, 'finney'), utils.toWei(1, 'milliether')); + assert.equal(utils.toWei(1, 'milli'), utils.toWei(1, 'milliether')); + assert.equal(utils.toWei(1, 'milli'), utils.toWei(1000, 'micro')); + assert.throws(function () {utils.toWei(1, 'wei1');}, Error); }); }); diff --git a/web3.eth.sendIBANTransaction.js b/web3.eth.sendIBANTransaction.js new file mode 100644 index 00000000..9d478e13 --- /dev/null +++ b/web3.eth.sendIBANTransaction.js @@ -0,0 +1,49 @@ +var chai = require('chai'); +var assert = chai.assert; +var web3 = require('../index'); +var FakeHttpProvider = require('./helpers/FakeHttpProvider'); +var FakeHttpProvider2 = require('./helpers/FakeHttpProvider2'); + +describe('web3.eth.sendIBANTransaction', function () { + it('should send transaction', function () { + + var iban = 'XE81ETHXREGGAVOFYORK'; + var address = '0x1234567890123456789012345678901234500000'; + var exAddress = '0x1234567890123456789012345678901234567890' + + var provider = new FakeHttpProvider2(); + web3.setProvider(provider); + web3.reset(); + + provider.injectResultList([{ + result: exAddress + }, { + result: '' + }]); + + var step = 0; + provider.injectValidation(function (payload) { + if (step === 0) { + step++; + assert.equal(payload.method, 'eth_call'); + assert.deepEqual(payload.params, [{ + data: '0x3b3b57de5852454700000000000000000000000000000000000000000000000000000000', + to: web3.eth.namereg.address + }, "latest"]); + + return; + } + assert.equal(payload.method, 'eth_sendTransaction'); + assert.deepEqual(payload.params, [{ + data: '0xb214faa54741564f46594f524b0000000000000000000000000000000000000000000000', + from: address, + to: exAddress, + value: payload.params[0].value // don't check this + }]); + }); + + web3.eth.sendIBANTransaction(address, iban, 10000); + + }); +}); + diff --git a/web3.sha3.js b/web3.sha3.js deleted file mode 100644 index 0ae10496..00000000 --- a/web3.sha3.js +++ /dev/null @@ -1,16 +0,0 @@ -var BigNumber = require('bignumber.js'); -var web3 = require('../index'); -var testMethod = require('./helpers/test.method.js'); - -var method = 'sha3'; - -var tests = [{ - args: ['myString'], - formattedArgs: ['myString'], - result: '0x319319f831983198319881', - formattedResult: '0x319319f831983198319881', - call: 'web3_'+ method -}]; - -testMethod.runTests(null, method, tests); - |