mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 03:28:07 +00:00
fixed #161, web3.ssh.post
This commit is contained in:
parent
dc0f2318bf
commit
96b44682f1
8
dist/web3-light.js
vendored
8
dist/web3-light.js
vendored
@ -804,7 +804,7 @@ var toAscii = function(hex) {
|
|||||||
/**
|
/**
|
||||||
* Shold be called to get hex representation (prefixed by 0x) of ascii string
|
* Shold be called to get hex representation (prefixed by 0x) of ascii string
|
||||||
*
|
*
|
||||||
* @method fromAscii
|
* @method toHexNative
|
||||||
* @param {String} string
|
* @param {String} string
|
||||||
* @returns {String} hex representation of input string
|
* @returns {String} hex representation of input string
|
||||||
*/
|
*/
|
||||||
@ -2304,9 +2304,11 @@ var inputPostFormatter = function(post) {
|
|||||||
|
|
||||||
post.payload = utils.toHex(post.payload);
|
post.payload = utils.toHex(post.payload);
|
||||||
post.ttl = utils.fromDecimal(post.ttl);
|
post.ttl = utils.fromDecimal(post.ttl);
|
||||||
|
post.workToProve = utils.fromDecimal(post.workToProve);
|
||||||
post.priority = utils.fromDecimal(post.priority);
|
post.priority = utils.fromDecimal(post.priority);
|
||||||
|
|
||||||
if(!utils.isArray(post.topics)) {
|
// fallback
|
||||||
|
if (!utils.isArray(post.topics)) {
|
||||||
post.topics = [post.topics];
|
post.topics = [post.topics];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3118,7 +3120,7 @@ var post = new Method({
|
|||||||
name: 'post',
|
name: 'post',
|
||||||
call: 'shh_post',
|
call: 'shh_post',
|
||||||
params: 1,
|
params: 1,
|
||||||
inputFormatter: formatters.inputPostFormatter
|
inputFormatter: [formatters.inputPostFormatter]
|
||||||
});
|
});
|
||||||
|
|
||||||
var newIdentity = new Method({
|
var newIdentity = new Method({
|
||||||
|
8
dist/web3-light.js.map
vendored
8
dist/web3-light.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/web3-light.min.js
vendored
2
dist/web3-light.min.js
vendored
File diff suppressed because one or more lines are too long
72
dist/web3.js
vendored
72
dist/web3.js
vendored
@ -804,7 +804,7 @@ var toAscii = function(hex) {
|
|||||||
/**
|
/**
|
||||||
* Shold be called to get hex representation (prefixed by 0x) of ascii string
|
* Shold be called to get hex representation (prefixed by 0x) of ascii string
|
||||||
*
|
*
|
||||||
* @method fromAscii
|
* @method toHexNative
|
||||||
* @param {String} string
|
* @param {String} string
|
||||||
* @returns {String} hex representation of input string
|
* @returns {String} hex representation of input string
|
||||||
*/
|
*/
|
||||||
@ -2304,9 +2304,11 @@ var inputPostFormatter = function(post) {
|
|||||||
|
|
||||||
post.payload = utils.toHex(post.payload);
|
post.payload = utils.toHex(post.payload);
|
||||||
post.ttl = utils.fromDecimal(post.ttl);
|
post.ttl = utils.fromDecimal(post.ttl);
|
||||||
|
post.workToProve = utils.fromDecimal(post.workToProve);
|
||||||
post.priority = utils.fromDecimal(post.priority);
|
post.priority = utils.fromDecimal(post.priority);
|
||||||
|
|
||||||
if(!utils.isArray(post.topics)) {
|
// fallback
|
||||||
|
if (!utils.isArray(post.topics)) {
|
||||||
post.topics = [post.topics];
|
post.topics = [post.topics];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3118,7 +3120,7 @@ var post = new Method({
|
|||||||
name: 'post',
|
name: 'post',
|
||||||
call: 'shh_post',
|
call: 'shh_post',
|
||||||
params: 1,
|
params: 1,
|
||||||
inputFormatter: formatters.inputPostFormatter
|
inputFormatter: [formatters.inputPostFormatter]
|
||||||
});
|
});
|
||||||
|
|
||||||
var newIdentity = new Method({
|
var newIdentity = new Method({
|
||||||
@ -3308,13 +3310,13 @@ module.exports = {
|
|||||||
},{"./method":19}],27:[function(require,module,exports){
|
},{"./method":19}],27:[function(require,module,exports){
|
||||||
|
|
||||||
},{}],"bignumber.js":[function(require,module,exports){
|
},{}],"bignumber.js":[function(require,module,exports){
|
||||||
/*! bignumber.js v2.0.3 https://github.com/MikeMcl/bignumber.js/LICENCE */
|
/*! bignumber.js v2.0.7 https://github.com/MikeMcl/bignumber.js/LICENCE */
|
||||||
|
|
||||||
;(function (global) {
|
;(function (global) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
bignumber.js v2.0.3
|
bignumber.js v2.0.7
|
||||||
A JavaScript library for arbitrary-precision arithmetic.
|
A JavaScript library for arbitrary-precision arithmetic.
|
||||||
https://github.com/MikeMcl/bignumber.js
|
https://github.com/MikeMcl/bignumber.js
|
||||||
Copyright (c) 2015 Michael Mclaughlin <M8ch88l@gmail.com>
|
Copyright (c) 2015 Michael Mclaughlin <M8ch88l@gmail.com>
|
||||||
@ -4146,10 +4148,12 @@ module.exports = {
|
|||||||
i = 0;
|
i = 0;
|
||||||
s += 2;
|
s += 2;
|
||||||
|
|
||||||
// Normalise xc and yc so highest order digit of yc is >= base/2
|
// Normalise xc and yc so highest order digit of yc is >= base / 2.
|
||||||
|
|
||||||
n = mathfloor( base / ( yc[0] + 1 ) );
|
n = mathfloor( base / ( yc[0] + 1 ) );
|
||||||
|
|
||||||
|
// Not necessary, but to handle odd bases where yc[0] == ( base / 2 ) - 1.
|
||||||
|
// if ( n > 1 || n++ == 1 && yc[0] < base / 2 ) {
|
||||||
if ( n > 1 ) {
|
if ( n > 1 ) {
|
||||||
yc = multiply( yc, n, base );
|
yc = multiply( yc, n, base );
|
||||||
xc = multiply( xc, n, base );
|
xc = multiply( xc, n, base );
|
||||||
@ -4167,6 +4171,8 @@ module.exports = {
|
|||||||
yz.unshift(0);
|
yz.unshift(0);
|
||||||
yc0 = yc[0];
|
yc0 = yc[0];
|
||||||
if ( yc[1] >= base / 2 ) yc0++;
|
if ( yc[1] >= base / 2 ) yc0++;
|
||||||
|
// Not necessary, but to prevent trial digit n > base, when using base 3.
|
||||||
|
// else if ( base == 3 && yc0 == 1 ) yc0 = 1 + 1e-15;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
n = 0;
|
n = 0;
|
||||||
@ -4194,7 +4200,9 @@ module.exports = {
|
|||||||
// 6. If remainder > divisor: remainder -= divisor, n++
|
// 6. If remainder > divisor: remainder -= divisor, n++
|
||||||
|
|
||||||
if ( n > 1 ) {
|
if ( n > 1 ) {
|
||||||
if ( n >= base ) n = base - 1;
|
|
||||||
|
// n may be > base only when base is 3.
|
||||||
|
if (n >= base) n = base - 1;
|
||||||
|
|
||||||
// product = divisor * trial digit.
|
// product = divisor * trial digit.
|
||||||
prod = multiply( yc, n, base );
|
prod = multiply( yc, n, base );
|
||||||
@ -4202,58 +4210,66 @@ module.exports = {
|
|||||||
remL = rem.length;
|
remL = rem.length;
|
||||||
|
|
||||||
// Compare product and remainder.
|
// Compare product and remainder.
|
||||||
cmp = compare( prod, rem, prodL, remL );
|
// If product > remainder.
|
||||||
|
// Trial digit n too high.
|
||||||
// product > remainder.
|
// n is 1 too high about 5% of the time, and is not known to have
|
||||||
if ( cmp == 1 ) {
|
// ever been more than 1 too high.
|
||||||
|
while ( compare( prod, rem, prodL, remL ) == 1 ) {
|
||||||
n--;
|
n--;
|
||||||
|
|
||||||
// Subtract divisor from product.
|
// Subtract divisor from product.
|
||||||
subtract( prod, yL < prodL ? yz : yc, prodL, base );
|
subtract( prod, yL < prodL ? yz : yc, prodL, base );
|
||||||
|
prodL = prod.length;
|
||||||
|
cmp = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// cmp is -1.
|
// n is 0 or 1, cmp is -1.
|
||||||
// If n is 0, there is no need to compare yc and rem again
|
// If n is 0, there is no need to compare yc and rem again below,
|
||||||
// below, so change cmp to 1 to avoid it.
|
// so change cmp to 1 to avoid it.
|
||||||
// If n is 1, compare yc and rem again below.
|
// If n is 1, leave cmp as -1, so yc and rem are compared again.
|
||||||
if ( n == 0 ) cmp = n = 1;
|
if ( n == 0 ) {
|
||||||
|
|
||||||
|
// divisor < remainder, so n must be at least 1.
|
||||||
|
cmp = n = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// product = divisor
|
||||||
prod = yc.slice();
|
prod = yc.slice();
|
||||||
|
prodL = prod.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
prodL = prod.length;
|
|
||||||
if ( prodL < remL ) prod.unshift(0);
|
if ( prodL < remL ) prod.unshift(0);
|
||||||
|
|
||||||
// Subtract product from remainder.
|
// Subtract product from remainder.
|
||||||
subtract( rem, prod, remL, base );
|
subtract( rem, prod, remL, base );
|
||||||
|
remL = rem.length;
|
||||||
|
|
||||||
// If product was < previous remainder.
|
// If product was < remainder.
|
||||||
if ( cmp == -1 ) {
|
if ( cmp == -1 ) {
|
||||||
remL = rem.length;
|
|
||||||
|
|
||||||
// Compare divisor and new remainder.
|
// Compare divisor and new remainder.
|
||||||
cmp = compare( yc, rem, yL, remL );
|
|
||||||
|
|
||||||
// If divisor < new remainder, subtract divisor from remainder.
|
// If divisor < new remainder, subtract divisor from remainder.
|
||||||
if ( cmp < 1 ) {
|
// Trial digit n too low.
|
||||||
|
// n is 1 too low about 5% of the time, and very rarely 2 too low.
|
||||||
|
while ( compare( yc, rem, yL, remL ) < 1 ) {
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
// Subtract divisor from remainder.
|
// Subtract divisor from remainder.
|
||||||
subtract( rem, yL < remL ? yz : yc, remL, base );
|
subtract( rem, yL < remL ? yz : yc, remL, base );
|
||||||
|
remL = rem.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remL = rem.length;
|
|
||||||
} else if ( cmp === 0 ) {
|
} else if ( cmp === 0 ) {
|
||||||
n++;
|
n++;
|
||||||
rem = [0];
|
rem = [0];
|
||||||
}
|
} // else cmp === 1 and n will be 0
|
||||||
// if cmp === 1, n will be 0
|
|
||||||
|
|
||||||
// Add the next digit, n, to the result array.
|
// Add the next digit, n, to the result array.
|
||||||
qc[i++] = n;
|
qc[i++] = n;
|
||||||
|
|
||||||
// Update the remainder.
|
// Update the remainder.
|
||||||
if ( cmp && rem[0] ) {
|
if ( rem[0] ) {
|
||||||
rem[remL++] = xc[xi] || 0;
|
rem[remL++] = xc[xi] || 0;
|
||||||
} else {
|
} else {
|
||||||
rem = [ xc[xi] ];
|
rem = [ xc[xi] ];
|
||||||
@ -4424,11 +4440,11 @@ module.exports = {
|
|||||||
|
|
||||||
// Handle values that fail the validity test in BigNumber.
|
// Handle values that fail the validity test in BigNumber.
|
||||||
parseNumeric = (function () {
|
parseNumeric = (function () {
|
||||||
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i,
|
var basePrefix = /^(-?)0([xbo])/i,
|
||||||
dotAfter = /^([^.]+)\.$/,
|
dotAfter = /^([^.]+)\.$/,
|
||||||
dotBefore = /^\.([^.]+)$/,
|
dotBefore = /^\.([^.]+)$/,
|
||||||
isInfinityOrNaN = /^-?(Infinity|NaN)$/,
|
isInfinityOrNaN = /^-?(Infinity|NaN)$/,
|
||||||
whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
whitespaceOrPlus = /^\s*\+|^\s+|\s+$/g;
|
||||||
|
|
||||||
return function ( x, str, num, b ) {
|
return function ( x, str, num, b ) {
|
||||||
var base,
|
var base,
|
||||||
|
12
dist/web3.js.map
vendored
12
dist/web3.js.map
vendored
File diff suppressed because one or more lines are too long
5
dist/web3.min.js
vendored
5
dist/web3.min.js
vendored
File diff suppressed because one or more lines are too long
@ -112,7 +112,7 @@ var toAscii = function(hex) {
|
|||||||
/**
|
/**
|
||||||
* Shold be called to get hex representation (prefixed by 0x) of ascii string
|
* Shold be called to get hex representation (prefixed by 0x) of ascii string
|
||||||
*
|
*
|
||||||
* @method fromAscii
|
* @method toHexNative
|
||||||
* @param {String} string
|
* @param {String} string
|
||||||
* @returns {String} hex representation of input string
|
* @returns {String} hex representation of input string
|
||||||
*/
|
*/
|
||||||
|
@ -155,9 +155,11 @@ var inputPostFormatter = function(post) {
|
|||||||
|
|
||||||
post.payload = utils.toHex(post.payload);
|
post.payload = utils.toHex(post.payload);
|
||||||
post.ttl = utils.fromDecimal(post.ttl);
|
post.ttl = utils.fromDecimal(post.ttl);
|
||||||
|
post.workToProve = utils.fromDecimal(post.workToProve);
|
||||||
post.priority = utils.fromDecimal(post.priority);
|
post.priority = utils.fromDecimal(post.priority);
|
||||||
|
|
||||||
if(!utils.isArray(post.topics)) {
|
// fallback
|
||||||
|
if (!utils.isArray(post.topics)) {
|
||||||
post.topics = [post.topics];
|
post.topics = [post.topics];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ var post = new Method({
|
|||||||
name: 'post',
|
name: 'post',
|
||||||
call: 'shh_post',
|
call: 'shh_post',
|
||||||
params: 1,
|
params: 1,
|
||||||
inputFormatter: formatters.inputPostFormatter
|
inputFormatter: [formatters.inputPostFormatter]
|
||||||
});
|
});
|
||||||
|
|
||||||
var newIdentity = new Method({
|
var newIdentity = new Method({
|
||||||
|
@ -20,7 +20,8 @@ describe('formatters', function () {
|
|||||||
payload: '0x7b2274657374223a2274657374227d',
|
payload: '0x7b2274657374223a2274657374227d',
|
||||||
ttl: '0xc8',
|
ttl: '0xc8',
|
||||||
priority: '0x3e8',
|
priority: '0x3e8',
|
||||||
topics: ['0x68656c6c6f','0x6d79746f70696373']
|
topics: ['0x68656c6c6f','0x6d79746f70696373'],
|
||||||
|
workToProve: '0x0'
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -2,6 +2,7 @@ var chai = require('chai');
|
|||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var web3 = require('../../index');
|
var web3 = require('../../index');
|
||||||
var FakeHttpProvider = require('./FakeHttpProvider');
|
var FakeHttpProvider = require('./FakeHttpProvider');
|
||||||
|
var clone = function (object) { return JSON.parse(JSON.stringify(object)); };
|
||||||
|
|
||||||
var runTests = function (obj, method, tests) {
|
var runTests = function (obj, method, tests) {
|
||||||
|
|
||||||
@ -22,10 +23,18 @@ var runTests = function (obj, method, tests) {
|
|||||||
assert.deepEqual(payload.params, test.formattedArgs);
|
assert.deepEqual(payload.params, test.formattedArgs);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var args = clone(test.args)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var result = (obj)
|
if (obj) {
|
||||||
? web3[obj][method].apply(null, test.args.slice(0))
|
var result = web3[obj][method].apply(null, args);
|
||||||
: web3[method].apply(null, test.args.slice(0));
|
} else {
|
||||||
|
var result = web3[method].apply(null, args);
|
||||||
|
}
|
||||||
|
// when
|
||||||
|
//var result = (obj)
|
||||||
|
//? web3[obj][method].apply(null, test.args.slice(0))
|
||||||
|
//: web3[method].apply(null, test.args.slice(0));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assert.deepEqual(test.formattedResult, result);
|
assert.deepEqual(test.formattedResult, result);
|
||||||
@ -43,7 +52,8 @@ var runTests = function (obj, method, tests) {
|
|||||||
assert.deepEqual(payload.params, test.formattedArgs);
|
assert.deepEqual(payload.params, test.formattedArgs);
|
||||||
});
|
});
|
||||||
|
|
||||||
var args = test.args.slice(0);
|
var args = clone(test.args);
|
||||||
|
|
||||||
// add callback
|
// add callback
|
||||||
args.push(function (err, result) {
|
args.push(function (err, result) {
|
||||||
assert.deepEqual(test.formattedResult, result);
|
assert.deepEqual(test.formattedResult, result);
|
||||||
@ -51,10 +61,11 @@ var runTests = function (obj, method, tests) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
if(obj)
|
if (obj) {
|
||||||
web3[obj][method].apply(null, args);
|
web3[obj][method].apply(null, args);
|
||||||
else
|
} else {
|
||||||
web3[method].apply(null, args);
|
web3[method].apply(null, args);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
49
test/web3.shh.post.js
Normal file
49
test/web3.shh.post.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
var chai = require('chai');
|
||||||
|
var web3 = require('../index');
|
||||||
|
var testMethod = require('./helpers/test.method.js');
|
||||||
|
|
||||||
|
var method = 'post';
|
||||||
|
|
||||||
|
var tests = [{
|
||||||
|
args: [{
|
||||||
|
from: '0x123123123',
|
||||||
|
topics: ['hello_world'],
|
||||||
|
payload: '12345',
|
||||||
|
ttl: 100,
|
||||||
|
workToProve: 101
|
||||||
|
}],
|
||||||
|
formattedArgs: [{
|
||||||
|
from: '0x123123123',
|
||||||
|
topics: [web3.fromAscii('hello_world')],
|
||||||
|
payload: web3.toHex('12345'),
|
||||||
|
ttl: web3.toHex('100'),
|
||||||
|
workToProve: web3.toHex('101'),
|
||||||
|
priority: '0x0'
|
||||||
|
}],
|
||||||
|
result: true,
|
||||||
|
formattedResult: true,
|
||||||
|
call: 'shh_'+ method
|
||||||
|
}, {
|
||||||
|
args: [{
|
||||||
|
from: '0x21312',
|
||||||
|
topics: ['hello_world'],
|
||||||
|
payload: '0x12345',
|
||||||
|
ttl: 0x100,
|
||||||
|
workToProve: 0x101,
|
||||||
|
priority: 0x15
|
||||||
|
}],
|
||||||
|
formattedArgs: [{
|
||||||
|
from: '0x21312',
|
||||||
|
topics: [web3.fromAscii('hello_world')],
|
||||||
|
payload: '0x12345',
|
||||||
|
ttl: '0x100',
|
||||||
|
workToProve: '0x101',
|
||||||
|
priority: '0x15'
|
||||||
|
}],
|
||||||
|
result: true,
|
||||||
|
formattedResult: true,
|
||||||
|
call: 'shh_'+ method
|
||||||
|
}];
|
||||||
|
|
||||||
|
testMethod.runTests('shh', method, tests);
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user