<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/jsonrpc.id.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var Jsonrpc = require('../lib/web3/jsonrpc');

describe('lib/web3/jsonrpc', function () {
    describe('id', function () {
        it('should increment the id', function () {
            
            // given
            var a = Jsonrpc.getInstance();
            var b = Jsonrpc.getInstance();
            var method = 'm';

            // when
            var p1 = a.toPayload(method);
            var p2 = b.toPayload(method);

            // then
            assert.equal(p2.id, p1.id + 1); 
        });
    });
});



<|start_filename|>Implementations/Storage/demo-homepage/bootstrap-custom.css<|end_filename|>
textarea { resize:none; }

video {
   width:100%;
   max-width:500px;
   height:auto;
}


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/utils.toAscii.js<|end_filename|>
var chai = require('chai');
var BigNumber = require('bignumber.js');
var utils = require('../lib/utils/utils.js');
var assert = chai.assert;

var tests = [
    { value: '0x6d79537472696e67', expected: 'myString'},
    { value: '0x6d79537472696e6700', expected: 'myString\u0000'},
    { value: "0x0300000035e8c6d54c5d127c9dcebe9e1a37ab9b05321128d097590a3c100000000000006521df642ff1f5ec0c3a7aa6cea6b1e7b7f7cda2cbdf07362a85088e97f19ef94331c955c0e9321ad386428c",
      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'}
];

describe('lib/utils/utils', function () {
    describe('toAscii', function () {
        tests.forEach(function (test) {
            it('should turn ' + test.value + ' to ' + test.expected, function () {
                assert.strictEqual(utils.toAscii(test.value), test.expected);
            });
        });
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.fromICAP.js<|end_filename|>
var chai = require('chai');
var Web3 = require('../index');
var web3 = new Web3();
var assert = chai.assert;

var tests = [
    { direct: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', address: '00c5496aee77c1ba1f0854206a26dda82a81d6d8'}
];

describe('web3', function () {
    describe('fromICAP', function () {
        tests.forEach(function (test) {
            it('shoud transform iban to address: ' +  test.address, function () {
                assert.deepEqual(web3.fromICAP(test.direct), test.address);
            });
        });   
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/method.extractCallback.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var Method = require('../lib/web3/method');

describe('lib/web3/method', function () {
    describe('extractCallback', function () {
        it('should extract callback', function () {
            
            // given
            var method = new Method({});
            var callback = function () { };
            var args = [1, callback]

            // when
            var result = method.extractCallback(args);

            // then
            assert.equal(args.length, 1);
            assert.equal(callback, result);
        });
        
        it('should extract callback created using newFunction', function () {
            
            // given
            var method = new Method({});
            var callback = new Function ();
            var args = [1, callback]

            // when
            var result = method.extractCallback(args);

            // then
            assert.equal(args.length, 1);
            assert.equal(callback, result);
        });

        it('should not extract the callback', function () {
            
            // given
            var method = new Method({});
            var args = [1, 2]

            // when
            var result = method.extractCallback(args);

            // then
            assert.equal(args.length, 2);
            assert.equal(result, null);
        });
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.eth.getBlockUncleCount.js<|end_filename|>
var chai = require('chai');
var web3 = require('../index');
var method = 'getBlockUncleCount';
var testMethod = require('./helpers/test.method.js');


var tests = [{
    args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'],
    formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'],
    result: '0xb',
    formattedResult: 11,
    call: 'eth_getUncleCountByBlockHash'
},{
    args: [436],
    formattedArgs: ['0x1b4'],
    result: '0xb',
    formattedResult: 11,
    call: 'eth_getUncleCountByBlockNumber'
},{
    args: ['pending'],
    formattedArgs: ['pending'],
    result: '0xb',
    formattedResult: 11,
    call: 'eth_getUncleCountByBlockNumber'
}];

testMethod.runTests('eth', method, tests);


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/node/app.js<|end_filename|>
var web3 = require('web3');

console.log(web3.version.api);




<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/utils.toDecimal.js<|end_filename|>
var assert = require('assert');
var utils = require('../lib/utils/utils.js');

describe('lib/utils/utils', function () {
    describe('toDecimal', function () {
        it('should return the correct value', function () {
            
            assert.equal(utils.toDecimal("0x3e8"), '1000');
            // allow compatiblity
            assert.equal(utils.toDecimal(100000), '100000');
            assert.equal(utils.toDecimal('100000'), '100000');
        });
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.db.getHex.js<|end_filename|>
var testMethod = require('./helpers/test.method.js');

var method = 'getHex';

var tests = [{
    args: ['myDB', 'myKey'],
    formattedArgs: ['myDB', 'myKey'],
    result: '0xf',
    formattedResult: '0xf',
    call: 'db_'+ method
}];

testMethod.runTests('db', method, tests);



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/formatters.outputTransactionFormatter.js<|end_filename|>
var assert = require('assert');
var formatters = require('../lib/web3/formatters.js');
var BigNumber = require('bignumber.js');

describe('formatters', function () {
    describe('outputTransactionFormatter', function () {
        it('should return the correct value', function () {
            
            assert.deepEqual(formatters.outputTransactionFormatter({
                input: '0x3454645634534',
                from: '0x00000',
                to: '0x00000',
                value: '0x3e8',
                gas: '0x3e8',
                gasPrice: '0x3e8',
                nonce: '0xb',
                transactionIndex: '0x1',
                blockNumber: '0x3e8',
                blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9'
            }), {
                input: '0x3454645634534',
                from: '0x00000',
                to: '0x00000',
                value: new BigNumber(1000),
                gas: 1000,
                gasPrice: new BigNumber(1000),
                nonce: 11,
                blockNumber: 1000,
                blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9',
                transactionIndex: 1
            });
        });

        it('should return the correct value, when null values are present', function () {
            
            assert.deepEqual(formatters.outputTransactionFormatter({
                input: '0x3454645634534',
                from: '0x00000',
                to: null,
                value: '0x3e8',
                gas: '0x3e8',
                gasPrice: '0x3e8',
                nonce: '0xb',
                transactionIndex: null,
                blockNumber: null,
                blockHash: null
            }), {
                input: '0x3454645634534',
                from: '0x00000',
                to: null,
                value: new BigNumber(1000),
                gas: 1000,
                gasPrice: new BigNumber(1000),
                nonce: 11,
                blockNumber: null,
                blockHash: null,
                transactionIndex: null
            });
        });
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/formatters.inputAddressFormatter.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var formatters = require('../lib/web3/formatters.js');
var BigNumber = require('bignumber.js');

var tests = [
    { input: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8' }, 
    { input: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'},
    { input: '00c5496aee77c1ba1f0854206a26dda82a81d6d8', result: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'},
    { input: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae', result: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae' }
];

var errorTests = [
    '0x0c5496aee77c1ba1f0854206a26dda82a81d6d8',
    '0x0c5496aee77c1ba1f0854206a26dda82a81d6d8',
    '00c5496aee77c1ba1f0854206a26dda82a81d6d',
    'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZE',
    '0x'
]

describe('formatters', function () {
    describe('inputAddressFormatter', function () {
        tests.forEach(function(test){
            it('should return the correct value', function () {
                assert.deepEqual(formatters.inputAddressFormatter(test.input), test.result);
            });
        });
    });
});


describe('formatters', function () {
    describe('inputAddressFormatter', function () {
        errorTests.forEach(function(test){
            it('should throw an exception', function () {
                assert.throws(function () {
                    formatters.inputAddressFormatter(test);
                });
            });
        });
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.sha3.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var Web3 = require('../index');
var sha3 = require('../lib/utils/sha3');
var web3 = new Web3();

var method = 'sha3';

describe('web3.sha3', function () {
    it('should return sha3 with hex prefix', function() {
	test1 = web3.sha3('test123');
	test2 = web3.sha3('test(int)');
	test3 = web3.sha3('0x80', {encoding: 'hex'});
	test4 = web3.sha3('0x3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1', {encoding: 'hex'});
	assert.deepEqual(test1, '0x' + sha3('test123'));
	assert.deepEqual(test2, '0x' + sha3('test(int)'));
	assert.deepEqual(test3, '0x' + sha3('0x80', {encoding: 'hex'}));
	assert.deepEqual(test4, '0x' + sha3('0x3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1', {encoding: 'hex'}));
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.eth.estimateGas.js<|end_filename|>
var web3 = require('../index');
var testMethod = require('./helpers/test.method.js');

var method = 'estimateGas';

var tests = [{
    args: [{
        to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
        data: '0x23455654',
        gas: 11,
        gasPrice: 11
    }],
    formattedArgs: [{
        to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
        data: '0x23455654',
        gas: '0xb',
        gasPrice: '0xb'
    }],
    result: '0x31981',
    formattedResult: 203137,
    call: 'eth_'+ method
}];

testMethod.runTests('eth', method, tests);



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.eth.submitWork.js<|end_filename|>
var chai = require('chai');
var web3 = require('../index');
var testMethod = require('./helpers/test.method.js');

var method = 'submitWork';

var tests = [
{
    args: ['0x567890abcdef5555', '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', '<KEY>'],
    formattedArgs: ['0x567890abcdef5555', '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', '0xcdef1234567890abcdef1234567890abcdef0x1234567890abcf1234567890ab'],
    result: true,
    formattedResult: true,
    call: 'eth_'+ method
}];

testMethod.runTests('eth', method, tests);



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/utils.fromDecimal.js<|end_filename|>
var chai = require('chai');
var utils = require('../lib/utils/utils.js');
var assert = chai.assert;

var tests = [
    { value: 1, expected: '0x1' },
    { value: '1', expected: '0x1' },
    { value: '0x1', expected: '0x1'},
    { value: '0x01', expected: '0x1'},
    { value: 15, expected: '0xf'},
    { value: '15', expected: '0xf'},
    { value: '0xf', expected: '0xf'},
    { value: '0x0f', expected: '0xf'},
    { value: -1, expected: '-0x1'},
    { value: '-1', expected: '-0x1'},
    { value: '-0x1', expected: '-0x1'},
    { value: '-0x01', expected: '-0x1'},
    { value: -15, expected: '-0xf'},
    { value: '-15', expected: '-0xf'},
    { value: '-0xf', expected: '-0xf'},
    { value: '-0x0f', expected: '-0xf'},
    { value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'},
    { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},
    { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'},
    { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},
    { value: 0, expected: '0x0'},
    { value: '0', expected: '0x0'},
    { value: '0x0', expected: '0x0'},
    { value: -0, expected: '0x0'},
    { value: '-0', expected: '0x0'},
    { value: '-0x0', expected: '0x0'}
];

describe('lib/utils/utils', function () {
    describe('fromDecimal', function () {
        tests.forEach(function (test) {
            it('should turn ' + test.value + ' to ' + test.expected, function () {
                assert.equal(utils.fromDecimal(test.value), test.expected);
            });
        });
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.shh.hasIdentity.js<|end_filename|>
var chai = require('chai');
var web3 = require('../index');
var testMethod = require('./helpers/test.method.js');

var method = 'hasIdentity';

var tests = [{
    args: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'],
    formattedArgs: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'],
    result: true,
    formattedResult: true,
    call: 'shh_'+ method
}];

testMethod.runTests('shh', method, tests);



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.eth.getBlock.js<|end_filename|>
var Web3 = require('../index');
var web3 = new Web3();
var BigNumber = require('bignumber.js');
var testMethod = require('./helpers/test.method.js');

var method = 'getBlock';

var blockResult = {
    "number": "0x1b4",
    "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5",
    "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff",
    "miner": "0x4e65fda2159562a496f9f3522f89122a3088497a",
    "difficulty": "0x027f07",
    "totalDifficulty":  "0x027f07",
    "size":  "0x027f07",
    "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "gasLimit": "0x9f759",
    "gasUsed": "0x9f759",
    "timestamp": "0x54e34e8e",
    "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'],
    "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"]
};
var formattedBlockResult = {
    "number": 436,
    "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5",
    "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff",
    "miner": "0x4e65fda2159562a496f9f3522f89122a3088497a",
    "difficulty": new BigNumber(163591),
    "totalDifficulty":  new BigNumber(163591),
    "size":  163591,
    "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "gasLimit": 653145,
    "gasUsed": 653145,
    "timestamp": 1424182926,
    "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'],
    "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"]
};
var blockResultWithTx = {
    "number": "0x1b4",
    "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5",
    "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff",
    "miner": "0x4e65fda2159562a496f9f3522f89122a3088497a",
    "difficulty": "0x027f07",
    "totalDifficulty":  "0x027f07",
    "size":  "0x027f07",
    "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "gasLimit": "0x9f759",
    "gasUsed": "0x9f759",
    "timestamp": "0x54e34e8e",
    "transactions": [{
        "status": "mined",
        "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
        "nonce":"0x2",
        "blockHash": "0x6fd9e2a26ab",
        "blockNumber": "0x15df",
        "transactionIndex":  "0x1",
        "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
        "to":"0x85h43d8a49eeb85d32cf465507dd71d507100c1",
        "value":"0x7f110",
        "gas": "0x7f110",
        "gasPrice":"0x09184e72a000",
        "input":"0x603880600c6000396000f30060",
    }],
    "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"]
};
var formattedBlockResultWithTx = {
    "number": 436,
    "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5",
    "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff",
    "miner": "0x4e65fda2159562a496f9f3522f89122a3088497a",
    "difficulty": new BigNumber(163591),
    "totalDifficulty":  new BigNumber(163591),
    "size":  163591,
    "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "gasLimit": 653145,
    "gasUsed": 653145,
    "timestamp": 1424182926,
    "transactions": [{
        "status": "mined",
        "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
        "nonce": 2,
        "blockHash": "0x6fd9e2a26ab",
        "blockNumber": 5599,
        "transactionIndex":  1,
        "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
        "to":"0x85h43d8a49eeb85d32cf465507dd71d507100c1",
        "value": new BigNumber(520464),
        "gas": 520464,
        "gasPrice": new BigNumber(10000000000000),
        "input":"0x603880600c6000396000f30060",
    }],
    "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"]
};

var tests = [{
    args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'],
    formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', false],
    result: blockResult,
    formattedResult: formattedBlockResult,
    call: 'eth_'+ method + 'ByHash'
},{
    args: [436],
    formattedArgs: ['0x1b4', false],
    result: blockResult,
    formattedResult: formattedBlockResult,
    call: 'eth_'+ method + 'ByNumber'
},{
    args: [436, true],
    formattedArgs: ['0x1b4', true],
    result: blockResultWithTx,
    formattedResult: formattedBlockResultWithTx,
    call: 'eth_'+ method + 'ByNumber'
}];

testMethod.runTests('eth', method, tests);



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/iban.toAddress.js<|end_filename|>
var chai = require('chai');
var Iban = require('../lib/web3/iban.js');
var assert = chai.assert;

var tests = [
    { direct: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', address: '00c5496aee77c1ba1f0854206a26dda82a81d6d8'}
];

describe('lib/web3/iban', function () {
    describe('toAddress', function () {
        tests.forEach(function (test) {
            it('shoud transform iban to address: ' +  test.address, function () {
                var iban = new Iban(test.direct);
                assert.deepEqual(iban.address(), test.address);
            });
        });   
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/iban.isValid.js<|end_filename|>
var chai = require('chai');
var Iban = require('../lib/web3/iban.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: 'XE82ETHXREGGAVOFYORK', is: false}, // control number is invalid
    { obj: 'XE81ETCXREGGAVOFYORK', is: false},
    { obj: 'XE81ETHXREGGAVOFYORKD', is: false},
    { obj: 'XE81ETHXREGGaVOFYORK', is: false},
    { obj: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: true},
    { obj: 'XE7438O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: false}, // control number is invalid
    { obj: 'XD7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS', is: false},
    { obj: 'XE1222Q908LN1QBBU6XUQSO1OHWJIOS46OO', is: true}
];

describe('lib/web3/iban', function () {
    describe('isValid', function () {
        tests.forEach(function (test) {
            it('shoud test if value ' + test.obj + ' is iban: ' + test.is, function () {
                assert.equal(Iban.isValid(test.obj), test.is);
            });
        });   
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/helpers/test.method.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var Web3 = require('../../index');

var FakeHttpProvider = require('./FakeHttpProvider');
var clone = function (object) { return JSON.parse(JSON.stringify(object)); };

var runTests = function (obj, method, tests) {

    var testName = obj ? 'web3.' + obj : 'web';

    describe(testName, function () {
        describe(method, function () {
            tests.forEach(function (test, index) {
                it('sync test: ' + index, function () {
                    
                    // given
                    var provider = new FakeHttpProvider();
                    var web3 = new Web3(provider);
                    provider.injectResult(test.result);
                    provider.injectValidation(function (payload) {
                        assert.equal(payload.jsonrpc, '2.0');
                        assert.equal(payload.method, test.call);
                        assert.deepEqual(payload.params, test.formattedArgs);
                    });

                    var args = clone(test.args)

                    // when
                    if (obj) {
                        var result = web3[obj][method].apply(web3[obj], args);
                    } else {
                        var result = web3[method].apply(web3, args);
                    }
                    // when
                    //var result = (obj)
                        //? web3[obj][method].apply(null, test.args.slice(0))
                        //: web3[method].apply(null, test.args.slice(0));
                    
                    // then 
                    assert.deepEqual(test.formattedResult, result);
                });
                
                it('async test: ' + index, function (done) {
                    
                    // given
                    var provider = new FakeHttpProvider();
                    var web3 = new Web3(provider);
                    provider.injectResult(test.result);
                    provider.injectValidation(function (payload) {
                        assert.equal(payload.jsonrpc, '2.0');
                        assert.equal(payload.method, test.call);
                        assert.deepEqual(payload.params, test.formattedArgs);
                    });

                    var args = clone(test.args);
                   
                    // add callback
                    args.push(function (err, result) {
                        assert.deepEqual(test.formattedResult, result);
                        done();
                    });

                    // when
                    if (obj) {
                        web3[obj][method].apply(web3[obj], args);
                    } else {
                        web3[method].apply(web3, args);
                    }
                });
            });
        });
    });

};

module.exports = {
    runTests: runTests
}



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/helpers/FakeIpcRequest.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;

var FakeIpcRequest = function () {
    this._handle = {fd: {}};
    this.callbacks = [];

    return this
};

FakeIpcRequest.prototype.connect = function (path) {
    assert.notEqual(path, undefined);

    return this;
};

FakeIpcRequest.prototype.on = function(name, callback) {
    if(name === 'data'){
        this.callbacks.push(callback);
    }
};

FakeIpcRequest.prototype.writeSync = function (payload) {
    assert.equal(typeof payload, 'string');
    return payload;
};

FakeIpcRequest.prototype.write = function (payload) {
    assert.equal(typeof payload, 'string');

    this.callbacks.forEach(function(cb){
        setTimeout(function(){
            cb(payload);
        }, 100);
    });

};

module.exports = FakeIpcRequest;



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/jsonrpc.isValidResponse.js<|end_filename|>
var assert = require('assert');
var jsonrpc = require('../lib/web3/jsonrpc');
jsonrpc = new jsonrpc();

describe('jsonrpc', function () {
    describe('isValidResponse', function () {
        it('should validate basic jsonrpc response', function () {
            
            // given 
            var response = {
                jsonrpc: '2.0',
                id: 1,
                result: []
            };

            // when
            var valid = jsonrpc.isValidResponse(response);

            // then
            assert.equal(valid, true);
        });

        it('should validate basic undefined response', function () {
            
            // given 
            var response = undefined;

            // when
            var valid = jsonrpc.isValidResponse(response);

            // then
            assert.equal(valid, false);
        });
        
        it('should validate jsonrpc response without jsonrpc field', function () {
            
            // given 
            var response = {
                id: 1,
                result: []
            };

            // when
            var valid = jsonrpc.isValidResponse(response);

            // then
            assert.equal(valid, false);
        });
        
        it('should validate jsonrpc response with wrong jsonrpc version', function () {
            
            // given 
            var response = {
                jsonrpc: '1.0',
                id: 1,
                result: []
            };

            // when
            var valid = jsonrpc.isValidResponse(response);

            // then
            assert.equal(valid, false);
        });
        
        it('should validate jsonrpc response without id number', function () {
            
            // given 
            var response = {
                jsonrpc: '2.0',
                result: []
            };

            // when
            var valid = jsonrpc.isValidResponse(response);

            // then
            assert.equal(valid, false);
        });

        it('should validate jsonrpc response with wrong id field', function () {
            
            // given 
            var response = {
                jsonrpc: '2.0',
                id: 'x',
                result: []
            };

            // when
            var valid = jsonrpc.isValidResponse(response);

            // then
            assert.equal(valid, false);
        });

        it('should validate jsonrpc response without result field', function () {
            
            // given 
            var response = {
                jsonrpc: '2.0',
                id: 1
            };

            // when
            var valid = jsonrpc.isValidResponse(response);

            // then
            assert.equal(valid, false);
        });

        it('should validate jsonrpc response with result field === false', function () {
            
            // given 
            var response = {
                jsonrpc: '2.0',
                id: 1,
                result: false 
            };

            // when
            var valid = jsonrpc.isValidResponse(response);

            // then
            assert.equal(valid, true);
        });

        it('should validate jsonrpc response with result field === 0', function () {
            
            // given 
            var response = {
                jsonrpc: '2.0',
                id: 1,
                result: 0 
            };

            // when
            var valid = jsonrpc.isValidResponse(response);

            // then
            assert.equal(valid, true);
        });
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/sha3.js<|end_filename|>
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, o) {
        it('should encode ' + v + ' to ' + e, function () {
            assert.equal(sha3(v, o), e);
        });
    };

    test('test123', 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad');
    test('test(int)', 'f4d03772bec1e62fbe8c5691e1a9101e520e8f8b5ca612123694632bf3cb51b1');
    test('0x80', '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', { encoding: 'hex' });
    test('0x80', '6b03a5eef7706e3fb52a61c19ab1122fad7237726601ac665bd4def888f0e4a0');
    test('0x3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1', '82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28', { encoding: 'hex' });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/polling.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var Web3 = require('../index');
var web3 = new Web3();
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var utils = require('../lib/utils/utils');

var tests = [{
    protocol: 'eth',
    args: ['latest'],
    firstResult: 1,
    firstPayload: {
        method: "eth_newBlockFilter",
        params: []
    },
    secondResult: ['0x1234'],
    secondPayload: {
        method: "eth_getFilterChanges"
    }
},
{
    protocol: 'eth',
    args: ['pending'],
    firstResult: 1,
    firstPayload: {
        method: "eth_newPendingTransactionFilter",
        params: []
    },
    secondResult: ['0x1234'],
    secondPayload: {
        method: "eth_getFilterChanges"
    }
}];

var testPolling = function (tests) {
    
    describe('web3.eth.filter.polling', function () {
        tests.forEach(function (test, index) {
            it('should create && successfully poll filter', function (done) {

                // given
                var provider = new FakeHttpProvider(); 
                web3.setProvider(provider);
                web3.reset();
                provider.injectResult(test.firstResult);
                var step = 0;
                provider.injectValidation(function (payload) {
                    if (step === 0) {
                        step = 1;
                        assert.equal(payload.jsonrpc, '2.0');
                        assert.equal(payload.method, test.firstPayload.method);
                        assert.deepEqual(payload.params, test.firstPayload.params);
                    } else if (step === 1 && utils.isArray(payload)) {
                        step++;
                        var r = payload.filter(function (p) {
                            return p.jsonrpc === '2.0' && p.method === test.secondPayload.method && p.params[0] === test.firstResult;
                        });
                        assert.equal(r.length > 0, true);
                    }

                });

                // when
                var filter = web3[test.protocol].filter.apply(web3[test.protocol], test.args);
                provider.injectBatchResults([test.secondResult]);
                filter.watch(function (err, result) {
                    if (test.err) {
                        // todo
                    } else {
                        assert.equal(result, test.secondResult[0]);
                    }
                    filter.stopWatching();
                    done();

                });
            });
            it('should create && successfully poll filter when passed as callback', function (done) {

                // given
                var provider = new FakeHttpProvider(); 
                web3.setProvider(provider);
                web3.reset();
                provider.injectResult(test.firstResult);
                var step = 0;
                provider.injectValidation(function (payload) {
                    if (step === 0) {
                        step = 1;
                        assert.equal(payload.jsonrpc, '2.0');
                        assert.equal(payload.method, test.firstPayload.method);
                        assert.deepEqual(payload.params, test.firstPayload.params);
                    } else if (step === 1 && utils.isArray(payload)) {
                        step++;
                        var r = payload.filter(function (p) {
                            return p.jsonrpc === '2.0' && p.method === test.secondPayload.method && p.params[0] === test.firstResult;
                        });
                        assert.equal(r.length > 0, true);
                    }

                });

                // add callback
                test.args.push(function (err, result) {
                    if (test.err) {
                        // todo
                    } else {
                        assert.equal(result, test.secondResult[0]);
                    }
                    filter.stopWatching();
                    done();

                });

                // when
                var filter = web3[test.protocol].filter.apply(web3[test.protocol], test.args);
                provider.injectBatchResults([test.secondResult]);
            });
        }); 
    });
};

testPolling(tests);


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.eth.contract.js<|end_filename|>
var assert = require('assert');
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var Web3 = require('../index');


describe('web3.eth.contract', function() {
    it('should create simple contract with one method from abi with explicit type name', function () {
        
        // given
        var description =  [{
            "name": "test(uint256)",
            "type": "function",
            "inputs": [{
                "name": "a",
                "type": "uint256"
            }
            ],
            "outputs": [
            {
                "name": "d",
                "type": "uint256"
            }
            ]
        }];
        var address = '0x1234567890123456789012345678901234567892';
    
        // when
        var web3 = new Web3();
        var myCon = web3.eth.contract(description).at(address);

        // then
        assert.equal('function', typeof myCon.test); 
        assert.equal('function', typeof myCon.test['uint256']);
    });

    it('should create simple contract with one method from abi with implicit type name', function () {
    
        // given
        var description =  [{
            "name": "test",
            "type": "function",
            "inputs": [{
                "name": "a",
                "type": "uint256"
            }
            ],
            "outputs": [
            {
                "name": "d",
                "type": "uint256"
            }
            ]
        }];
        var address = '0x1234567890123456789012345678901234567892';

        // when
        var web3 = new Web3();
        var myCon = web3.eth.contract(description).at(address);

        // then
        assert.equal('function', typeof myCon.test); 
        assert.equal('function', typeof myCon.test['uint256']);
    }); 

    it('should create contract with multiple methods', function () {
        
        // given
        var description = [{
            "name": "test",
            "type": "function",
            "inputs": [{
                "name": "a",
                "type": "uint256"
            }
            ],
            "outputs": [
            {
                "name": "d",
                "type": "uint256"
            }
            ],
        }, {
            "name": "test2",
            "type": "function",
            "inputs": [{
                "name": "a",
                "type": "uint256"
            }
            ],
            "outputs": [
            {
                "name": "d",
                "type": "uint256"
            }
            ]
        }];
        var address = '0x1234567890123456789012345678901234567892';
        
        // when
        var web3 = new Web3();
        var myCon = web3.eth.contract(description).at(address);

        // then
        assert.equal('function', typeof myCon.test); 
        assert.equal('function', typeof myCon.test['uint256']);
        assert.equal('function', typeof myCon.test2); 
        assert.equal('function', typeof myCon.test2['uint256']);
    });

    it('should create contract with overloaded methods', function () {
    
        // given
        var description = [{
            "name": "test",
            "type": "function",
            "inputs": [{
                "name": "a",
                "type": "uint256"
            }
            ],
            "outputs": [
            {
                "name": "d",
                "type": "uint256"
            }
            ],
        }, {
            "name": "test",
            "type": "function",
            "inputs": [{
                "name": "a",
                "type": "string"
            }
            ],
            "outputs": [
            {
                "name": "d",
                "type": "uint256"
            }
            ]
        }];
        var address = '0x1234567890123456789012345678901234567892';
        
        // when
        var web3 = new Web3();
        var myCon = web3.eth.contract(description).at(address);

        // then
        assert.equal('function', typeof myCon.test); 
        assert.equal('function', typeof myCon.test['uint256']);
        assert.equal('function', typeof myCon.test['string']); 
    });

    it('should create contract with no methods', function () {
        
        // given
        var description =  [{
            "name": "test(uint256)",
            "inputs": [{
                "name": "a",
                "type": "uint256"
            }
            ],
            "outputs": [
            {
                "name": "d",
                "type": "uint256"
            }
            ]
        }];
        var address = '0x1234567890123456789012345678901234567892';

        // when
        var web3 = new Web3();
        var myCon = web3.eth.contract(description).at(address);

        // then
        assert.equal('undefined', typeof myCon.test); 

    });

    it('should create contract with one event', function () {
        
        // given
        var description =  [{
            "name": "test",
            "type": "event",
            "inputs": [{
                "name": "a",
                "type": "uint256"
            }
            ],
            "outputs": [
            {
                "name": "d",
                "type": "uint256"
            }
            ]
        }];
        var address = '0x1234567890123456789012345678901234567892';

        // when
        var web3 = new Web3();
        var myCon = web3.eth.contract(description).at(address);

        // then
        assert.equal('function', typeof myCon.test); 
        assert.equal('function', typeof myCon.test['uint256']); 

    });

    it('should create contract with nondefault constructor', function (done) {
        var provider = new FakeHttpProvider();
        var web3 = new Web3(provider);
        var address = '0x1234567890123456789012345678901234567894';
        var code = '0x31241231231123123123123121cf121212i123123123123123512312412512111111';
        var description =  [{
            "name": "test",
            "type": "constructor",
            "inputs": [{
                "name": "a",
                "type": "uint256"
            }
            ]
        }];

        var steps = 1;

        provider.injectResult(address);
        provider.injectValidation(function (payload) {
            if (steps === 1) {
                assert.equal(payload.jsonrpc, '2.0');
                assert.equal(payload.method, 'eth_sendTransaction');
                assert.equal(payload.params[0].data, code + '0000000000000000000000000000000000000000000000000000000000000002');
                steps++;

            } else if (steps === 2) {
                assert.equal(payload.jsonrpc, '2.0');
                assert.equal(payload.method, 'eth_newBlockFilter');
                steps++;
            }
        });
        
        web3.eth.contract(description).new(2, {from: address, data: code}, function(e, myCon){
                done();
                web3.stopWatching();
        });
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/formatters.inputPostFormatter.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var formatters = require('../lib/web3/formatters.js');

describe('formatters', function () {
    describe('inputPostFormatter', function () {
        it('should return the correct value', function () {
            
            // input as strings and numbers
            assert.deepEqual(formatters.inputPostFormatter({
                from: '0x00000',
                to: '0x00000',
                payload: '0x7b2274657374223a2274657374227d',//{test: 'test'},
                ttl: 200,
                priority: 1000,
                topics: ['hello','mytopics']
            }), {
                from: '0x00000',
                to: '0x00000',
                payload: '0x7b2274657374223a2274657374227d',
                ttl: '0xc8',
                priority: '0x3e8',
                topics: ['0x68656c6c6f','0x6d79746f70696373'],
                workToProve: '0x0'
            });

        });
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.personal.newAccount.js<|end_filename|>
var chai = require('chai');
var web3 = require('../index');
var testMethod = require('./helpers/test.method.js');

var method = 'newAccount';

var tests = [{
    args: ['P@ssw0rd!'],
    formattedArgs: ['P@ssw0rd!'],
    result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'],
    formattedResult: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855'],
    call: 'personal_'+ method
}];

testMethod.runTests('personal', method, tests);


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/helpers/FakeHttpProvider2.js<|end_filename|>
var FakeHttpProvider = require('./FakeHttpProvider');

var FakeHttpProvider2 = function () {
    this.counter = 0;
    this.resultList = [];
};

FakeHttpProvider2.prototype = new FakeHttpProvider();
FakeHttpProvider2.prototype.constructor = FakeHttpProvider2;

FakeHttpProvider2.prototype.injectResultList = function (list) {
    this.resultList = list;
};

FakeHttpProvider2.prototype.getResponse = function () {
    var result = this.resultList[this.counter];
    this.counter++;

    // add fallback result value
    if(!result)
        result = {
            result: undefined
        };

    if (result.type === 'batch') {
        this.injectBatchResults(result.result);
    } else {
        this.injectResult(result.result);
    }

    this.counter = 0;

    return this.response;
};

module.exports = FakeHttpProvider2;



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.eth.sendIBANTransaction.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var Web3 = require('../index');
var web3 = new Web3();
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.icapNamereg().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);

    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/formatters.inputDefaultBlockFormatter.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var formatters = require('../lib/web3/formatters');

var tests = [
    { value: 'latest', expected: 'latest' },
    { value: 'pending', expected: 'pending' },
    { value: 'earliest', expected: 'earliest' },
    { value: 1, expected: '0x1' },
    { value: '0x1', expected: '0x1' }
];

describe('lib/web3/formatters', function () {
    describe('inputDefaultBlockNumberFormatter', function () {
        tests.forEach(function (test) {
            it('should turn ' + test.value + ' to ' + test.expected, function () {
                assert.strictEqual(formatters.inputDefaultBlockNumberFormatter(test.value), test.expected);
            });
        });
    });
});





<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.eth.isSyncing.js<|end_filename|>
var chai = require('chai');
var Web3 = require('../index');
var assert = chai.assert;
var FakeHttpProvider = require('./helpers/FakeHttpProvider');

var method = 'isSyncing';

var tests = [{
    args: [],
    formattedArgs: [],
    result: [{
        startingBlock: '0xb',
        currentBlock: '0xb',
        highestBlock: '0xb'
    }],
    formattedResult: {
        startingBlock: 11,
        currentBlock: 11,
        highestBlock: 11
    },
    call: 'eth_syncing'
}];

describe('eth', function () {
    describe(method, function () {
        tests.forEach(function (test, index) {
            it('property test: ' + index, function (done) {
                // given
                var provider = new FakeHttpProvider();
                var web3 = new Web3(provider);
                provider.injectBatchResults(test.result);
                provider.injectValidation(function(payload) {
                    assert.equal(payload[0].jsonrpc, '2.0', 'failed');
                    assert.equal(payload[0].method, test.call);
                    assert.deepEqual(payload[0].params, test.formattedArgs);
                });

                var count = 1;

                // TODO results seem to be overwritten


                // call
                var syncing = web3.eth[method](function(e, res){
                    if(count === 1) {
                        assert.isTrue(res);
                        count++;
                    } else {
                        assert.deepEqual(res, test.formattedResult);
                        syncing.stopWatching();
                        done();
                    }
                });
                
            });
        });
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/errors.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var errors = require('../lib/web3/errors');

describe('lib/web3/method', function () {
    describe('getCall', function () {

        for(var key in errors) {
            it('should return and error', function () {
        
                assert.instanceOf(errors[key](), Error);
            });
        }

    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/formatters.outputLogFormatter.js<|end_filename|>
var assert = require('assert');
var formatters = require('../lib/web3/formatters.js');

describe('formatters', function () {
    describe('outputLogFormatter', function () {
        it('should return the correct value', function () {
            
            assert.deepEqual(formatters.outputLogFormatter({
                transactionIndex: '0x3e8',
                logIndex: '0x3e8',
                blockNumber: '0x3e8',
                transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                data: '0x7b2274657374223a2274657374227',
                topics: ['0x68656c6c6f','0x6d79746f70696373']                
            }), {
                transactionIndex: 1000,
                logIndex: 1000,
                blockNumber: 1000,
                transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                data: '0x7b2274657374223a2274657374227',
                topics: ['0x68656c6c6f','0x6d79746f70696373']
            });
        });
        it('should return the correct value, when null values are present', function () {
            
            assert.deepEqual(formatters.outputLogFormatter({
                transactionIndex: null,
                logIndex: null,
                blockNumber: null,
                transactionHash: null,
                blockHash: null,
                data: '0x7b2274657374223a2274657374227',
                topics: ['0x68656c6c6f','0x6d79746f70696373']                
            }), {
                transactionIndex: null,
                logIndex: null,
                blockNumber: null,
                transactionHash: null,
                blockHash: null,
                data: '0x7b2274657374223a2274657374227',
                topics: ['0x68656c6c6f','0x6d79746f70696373']
            });
        });
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.net.peerCount.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var Web3 = require('../index');
var web3 = new Web3();
var FakeHttpProvider = require('./helpers/FakeHttpProvider');

var method = 'peerCount';

var tests = [{
    result: '0xf',
    formattedResult: 15,
    call: 'net_'+ method
}];

describe('web3.net', function () {
    describe(method, function () {
        tests.forEach(function (test, index) {
            it('property test: ' + index, function () {
                
                // given
                var provider = new FakeHttpProvider();
                web3.setProvider(provider);
                provider.injectResult(test.result);
                provider.injectValidation(function (payload) {
                    assert.equal(payload.jsonrpc, '2.0');
                    assert.equal(payload.method, test.call);
                    assert.deepEqual(payload.params, []);
                });

                // when 
                var result = web3.net[method];
                
                // then
                assert.deepEqual(test.formattedResult, result);
            });
        });
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.methods.js<|end_filename|>
var Web3 = require('../index.js');
var web3 = new Web3();
var u = require('./helpers/test.utils.js');

describe('web3', function() {
    describe('methods', function () {
        u.methodExists(web3, 'sha3');
        u.methodExists(web3, 'toAscii');
        u.methodExists(web3, 'fromAscii');
        u.methodExists(web3, 'toDecimal');
        u.methodExists(web3, 'fromDecimal');
        u.methodExists(web3, 'fromWei');
        u.methodExists(web3, 'toWei');
        u.methodExists(web3, 'toBigNumber');
        u.methodExists(web3, 'isAddress');
        u.methodExists(web3, 'setProvider');
        u.methodExists(web3, 'reset');

        u.propertyExists(web3, 'providers');
        u.propertyExists(web3, 'eth');
        u.propertyExists(web3, 'db');
        u.propertyExists(web3, 'shh');
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.db.methods.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert; 
var Web3 = require('../index.js');
var web3 = new Web3();
var u = require('./helpers/test.utils.js');

describe('web3.db', function() {
    describe('methods', function() {
        u.methodExists(web3.db, 'putHex');
        u.methodExists(web3.db, 'getHex');
        u.methodExists(web3.db, 'putString');
        u.methodExists(web3.db, 'getString');
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/helpers/FakeQtNavigator.js<|end_filename|>

var navigator = {
    qt: {
        callMethod: function (payload) {
            return "{}";
        }
    }
};

module.exports = navigator;



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.shh.methods.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert; 
var Web3 = require('../index.js');
var web3 = new Web3();
var u = require('./helpers/test.utils.js');

describe('web3.shh', function() {
    describe('methods', function() {
        u.methodExists(web3.shh, 'post');
        u.methodExists(web3.shh, 'newIdentity');
        u.methodExists(web3.shh, 'hasIdentity');
        u.methodExists(web3.shh, 'newGroup');
        u.methodExists(web3.shh, 'addToGroup');
        u.methodExists(web3.shh, 'filter');
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/async.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;
var Web3 = require('../index');
var web3 = new Web3();
var FakeHttpProvider = require('./helpers/FakeHttpProvider');

// use sendTransaction as dummy
var method = 'sendTransaction';

var tests = [{
    input: {
        'from': 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
        'to': 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'
    },
    formattedInput: {
        'from': '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
        'to': '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8'
    },
    result: '0xb',
    formattedResult: '0xb',
    call: 'eth_'+ method
}];

describe('async', function () {
    tests.forEach(function (test, index) {
        it('test: ' + index, function (done) {
            
            // given
            var provider = new FakeHttpProvider();
            web3.setProvider(provider);
            provider.injectResult(test.result);
            provider.injectValidation(function (payload) {
                assert.equal(payload.jsonrpc, '2.0');
                assert.equal(payload.method, test.call);
                assert.deepEqual(payload.params, [test.formattedInput]);
            });

            // when 
            web3.eth[method](test.input, function(error, result){

                // then
                assert.isNull(error);
                assert.strictEqual(test.formattedResult, result);
                
                done();
            });
            
        });

        it('error test: ' + index, function (done) {
            
            // given
            var provider = new FakeHttpProvider();
            web3.setProvider(provider);
            provider.injectError({
                    message: test.result,
                    code: -32603
            });
            provider.injectValidation(function (payload) {
                assert.equal(payload.jsonrpc, '2.0');
                assert.equal(payload.method, test.call);
                assert.deepEqual(payload.params, [test.formattedInput]);
            });

            // when 
            web3.eth[method](test.input, function(error, result){

                // then
                assert.isUndefined(result);
                assert.strictEqual(test.formattedResult, error.message);

                done();
            });
            
        });
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.shh.filter.js<|end_filename|>
var chai = require('chai');
var Web3 = require('../index');
var web3 = new Web3();
var assert = chai.assert;
var FakeHttpProvider = require('./helpers/FakeHttpProvider');

var method = 'filter';

var tests = [{
    args: [{
        to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855',
        topics: ['0x324f5435', '0x564b4566f3453']
    }],
    formattedArgs: [{
        to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855',
        topics: ['0x324f5435', '0x564b4566f3453']
    }],
    result: '0xf',
    formattedResult: '0xf',
    call: 'shh_newFilter'
},
{
    args: [{
        to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855',
        topics: ['0x324f5435', ['0x564b4566f3453', '0x345345343453']]
    }],
    formattedArgs: [{
        to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855',
        topics: ['0x324f5435', ['0x564b4566f3453', '0x345345343453']]
    }],
    result: '0xf',
    formattedResult: '0xf',
    call: 'shh_newFilter'
},
{
    args: [{
        to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855',
        topics: ['0x324f5435', null, ['0x564b4566f3453', '0x345345343453']]
    }],
    formattedArgs: [{
        to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855',
        topics: ['0x324f5435', null, ['0x564b4566f3453', '0x345345343453']]
    }],
    result: '0xf',
    formattedResult: '0xf',
    call: 'shh_newFilter'
},
{
    args: [{
        to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855',
        topics: ['myString', 11, '23', null]
    }],
    formattedArgs: [{
        to: '0x47d33b27bb249a2dbab4c0612bf9caf4c1950855',
        topics: ['0x6d79537472696e67', '0x3131', '0x3233', null]
    }],
    result: '0xf',
    formattedResult: '0xf',
    call: 'shh_newFilter'
}];

describe('shh', function () {
    describe(method, function () {
        tests.forEach(function (test, index) {
            it('property test: ' + index, function () {
                
                // given
                var provider = new FakeHttpProvider();
                web3.setProvider(provider);
                web3.reset();
                provider.injectResult(test.result);
                provider.injectValidation(function (payload) {
                    assert.equal(payload.jsonrpc, '2.0');
                    assert.equal(payload.method, test.call);
                    assert.deepEqual(payload.params, test.formattedArgs);
                });

                // call
                web3.shh[method].apply(web3.shh, test.args);
                
            });
        });
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/formatters.outputBlockFormatter.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert; 
var formatters = require('../lib/web3/formatters.js');
var BigNumber = require('bignumber.js');

describe('formatters', function () {
    describe('outputBlockFormatter', function () {
        it('should return the correct value', function () {
            
            assert.deepEqual(formatters.outputBlockFormatter({
                hash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
                miner: '0xdcc6960376d6c6dea93647383ffb245cfced97cf',
                stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
                sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
                bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                difficulty: '0x3e8',
                totalDifficulty: '0x3e8',
                number: '0x3e8',
                gasLimit: '0x3e8',
                gasUsed: '0x3e8',
                timestamp: '0x3e8',
                extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                nonce: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                size: '0x3e8'
            }), {
                hash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
                miner: '0xdcc6960376d6c6dea93647383ffb245cfced97cf',
                stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
                sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
                bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                difficulty: new BigNumber(1000),
                totalDifficulty: new BigNumber(1000),
                number: 1000,
                gasLimit: 1000,
                gasUsed: 1000,
                timestamp: 1000,
                extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                nonce: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                size: 1000
            });
        });
        it('should return the correct value, when null values are present', function () {
            
            assert.deepEqual(formatters.outputBlockFormatter({
                hash: null,
                parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
                miner: null,
                stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
                sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
                bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                difficulty: '0x3e8',
                totalDifficulty: '0x3e8',
                number: null,
                gasLimit: '0x3e8',
                gasUsed: '0x3e8',
                timestamp: '0x3e8',
                extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                nonce: null,
                size: '0x3e8'
            }), {
                hash: null,
                parentHash: '0x83ffb245cfced97ccc5c75253d6960376d6c6dea93647397a543a72fdaea5265',
                miner: null,
                stateRoot: '0x54dda68af07643f68739a6e9612ad157a26ae7e2ce81f77842bb5835fbcde583',
                sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
                bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                difficulty: new BigNumber(1000),
                totalDifficulty: new BigNumber(1000),
                number: null,
                gasLimit: 1000,
                gasUsed: 1000,
                timestamp: 1000,
                extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
                nonce: null,
                size: 1000
            });
        });
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/utils.isJson.js<|end_filename|>
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: true},
    { obj: '[1, 2]', is: true},
    { obj: '{}', is: true},
    { obj: '{"a": 123, "b" :3,}', is: false},
    { obj: '{"c" : 2}', is: true}
];

describe('lib/utils/utils', function () {
    describe('isJson', function () {
        tests.forEach(function (test) {
            it('shoud test if value ' + test.obj + ' is json: ' + test.is, function () {
                assert.equal(utils.isJson(test.obj), test.is);
            });
        });   
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/utils.toBigNumber.js<|end_filename|>
var chai = require('chai');
var utils = require('../lib/utils/utils.js');
var BigNumber = require('bignumber.js');
var assert = chai.assert;

var tests = [
    { value: 1, expected: '1' },
    { value: '1', expected: '1' },
    { value: '0x1', expected: '1'},
    { value: '0x01', expected: '1'},
    { value: 15, expected: '15'},
    { value: '15', expected: '15'},
    { value: '0xf', expected: '15'},
    { value: '0x0f', expected: '15'},
    { value: new BigNumber('f', 16), expected: '15'},
    { value: -1, expected: '-1'},
    { value: '-1', expected: '-1'},
    { value: '-0x1', expected: '-1'},
    { value: '-0x01', expected: '-1'},
    { value: -15, expected: '-15'},
    { value: '-15', expected: '-15'},
    { value: '-0xf', expected: '-15'},
    { value: '-0x0f', expected: '-15'},
    { value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639935'},
    { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639933'},
    { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639935'},
    { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639933'},
    { value: 0, expected: '0'},
    { value: '0', expected: '0'},
    { value: '0x0', expected: '0'},
    { value: -0, expected: '0'},
    { value: '-0', expected: '0'},
    { value: '-0x0', expected: '0'},
    { value: new BigNumber(0), expected: '0'}
];

describe('lib/utils/utils', function () {
    describe('toBigNumber', function () {
        tests.forEach(function (test) {
            it('should turn ' + test.value + ' to ' + test.expected, function () {
                assert.equal(utils.toBigNumber(test.value).toString(10), test.expected);
            });
        });
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/utils.toUtf8.js<|end_filename|>
var chai = require('chai');
var BigNumber = require('bignumber.js');
var utils = require('../lib/utils/utils.js');
var assert = chai.assert;

var tests = [
    { value: '0x6d79537472696e67', expected: 'myString'},
    { value: '0x6d79537472696e6700', expected: 'myString'},
    { value: '0x65787065637465642076616c7565000000000000000000000000000000000000', expected: 'expected value'}
];

describe('lib/utils/utils', function () {
    describe('toUtf8', function () {
        tests.forEach(function (test) {
            it('should turn ' + test.value + ' to ' + test.expected, function () {
                assert.strictEqual(utils.toUtf8(test.value), test.expected);
            });
        });
    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.eth.getWork.js<|end_filename|>
var chai = require('chai');
var web3 = require('../index');
var testMethod = require('./helpers/test.method.js');

var method = 'getWork';

var tests = [{
    args: [],
    formattedArgs: [],
    result: true,
    formattedResult: true,
    call: 'eth_'+ method
}];

testMethod.runTests('eth', method, tests);



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/utils.extractTypeName.js<|end_filename|>
var assert = require('assert');
var utils = require('../lib/utils/utils.js');

describe('lib/utils/utils', function () {
    describe('extractTypeName', function () {
        it('should extract type name from method with no params', function () {
            
            // given
            var test = 'helloworld()';

            // when
            var typeName = utils.extractTypeName(test); 

            // then
            assert.equal(typeName, '');
        });

        it('should extract type name from method with one param', function () {
            
            // given
            var test = 'helloworld1(int)';

            // when
            var typeName = utils.extractTypeName(test);

            // then
            assert.equal(typeName, 'int');
        });
        
        it('should extract type name from method with two params', function () {
            
            // given
            var test = 'helloworld2(int,string)';

            // when
            var typeName = utils.extractTypeName(test);

            // then
            assert.equal(typeName, 'int,string');
        });
        
        it('should extract type name from method with spaces between params', function () {
            
            // given
            var test = 'helloworld3(int, string)';

            // when
            var typeName = utils.extractTypeName(test);

            // then
            assert.equal(typeName, 'int,string');
        });

    });
});


<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/iban.fromAddress.js<|end_filename|>
var chai = require('chai');
var Iban = require('../lib/web3/iban.js');
var assert = chai.assert;

var tests = [
    { address: '00c5496aee77c1ba1f0854206a26dda82a81d6d8',   expected: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'},
    { address: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'},
    { address: '0x11c5496aee77c1ba1f0854206a26dda82a81d6d8', expected: 'XE1222Q908LN1QBBU6XUQSO1OHWJIOS46OO'},
    { address: '0x52dc504a422f0e2a9e7632a34a50f1a82f8224c7', expected: 'XE499OG1EH8ZZI0KXC6N83EKGT1BM97P2O7'},
    { address: '0x0000a5327eab78357cbf2ae8f3d49fd9d90c7d22', expected: 'XE0600DQK33XDTYUCRI0KYM5ELAKXDWWF6'}
];

describe('lib/web3/iban', function () {
    describe('fromAddress', function () {
        tests.forEach(function (test) {
            it('shoud create indirect iban: ' +  test.expected, function () {
                assert.deepEqual(Iban.fromAddress(test.address), new Iban(test.expected));
            });
        });   
    });
});



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/web3.db.getString.js<|end_filename|>
var chai = require('chai');
var testMethod = require('./helpers/test.method.js');

var method = 'getString';

var tests = [{
    args: ['myDB', 'myKey'],
    formattedArgs: ['myDB', 'myKey'],
    result: 'myValue',
    formattedResult: 'myValue',
    call: 'db_'+ method
}];

testMethod.runTests('db', method, tests);



<|start_filename|>implementations/consensus/ethereumjs-web3s-js/test/helpers/FakeXMLHttpRequest.js<|end_filename|>
var chai = require('chai');
var assert = chai.assert;

var FakeXMLHttpRequest = function () {
    this.responseText = "{}";
    this.readyState = 4;
    this.onreadystatechange = null;
    this.async = false;
    this.headers = {
        'Content-Type': 'text/plain'
    };
};

FakeXMLHttpRequest.prototype.open = function (method, host, async) {
    assert.equal(method, 'POST');
    assert.notEqual(host, null);
    assert.equal(async === false || async === true, true);
    this.async = async;
};

FakeXMLHttpRequest.prototype.setRequestHeader = function(name, value) {
    this.headers[name] = value;
};

FakeXMLHttpRequest.prototype.send = function (payload) {
    assert.equal(typeof payload, 'string');
    if (this.async) {
        assert.equal(typeof this.onreadystatechange, 'function');
        this.onreadystatechange();
        return;
    }
    return this.responseText;
};

module.exports = { 
    XMLHttpRequest: FakeXMLHttpRequest
};

