fixed for defaultBlock formatter

This commit is contained in:
Marek Kotewicz 2015-03-23 14:23:45 +01:00
parent 33a3fc7bcd
commit 99ea9cdc1c
7 changed files with 28 additions and 14 deletions

9
dist/ethereum.js vendored
View File

@ -1147,11 +1147,12 @@ var setupMethods = function (obj, methods) {
var args = Array.prototype.slice.call(arguments);
var call = method.getCall(args);
var callback = method.extractCallback(args);
method.validateArgs(args);
var params = method.formatInput(args);
method.validateArgs(params);
var payload = {
method: call,
params: method.formatInput(args)
params: params
};
if (callback) {
@ -1775,7 +1776,7 @@ var getBalance = new Method({
name: 'getBalance',
call: 'eth_getBalance',
params: 2,
inputFormatter: [null, formatters.inputBlockNumberFormatter],
inputFormatter: [utils.toHex, formatters.inputBlockNumberFormatter],
outputFormatter: formatters.inputNumberFormatter
});
@ -2289,7 +2290,7 @@ var outputNumberFormatter = function (number) {
};
var inputBlockNumberFormatter = function (blockNumber) {
return blockNumber === null ? -1 : blockNumber;
return blockNumber === undefined ? "pending" : utils.toHex(blockNumber); // instead use default block number here
};
/**

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -62,11 +62,12 @@ var setupMethods = function (obj, methods) {
var args = Array.prototype.slice.call(arguments);
var call = method.getCall(args);
var callback = method.extractCallback(args);
method.validateArgs(args);
var params = method.formatInput(args);
method.validateArgs(params);
var payload = {
method: call,
params: method.formatInput(args)
params: params
};
if (callback) {

View File

@ -78,7 +78,7 @@ var getBalance = new Method({
name: 'getBalance',
call: 'eth_getBalance',
params: 2,
inputFormatter: [null, formatters.inputBlockNumberFormatter],
inputFormatter: [utils.toHex, formatters.inputBlockNumberFormatter],
outputFormatter: formatters.inputNumberFormatter
});

View File

@ -35,7 +35,7 @@ var outputNumberFormatter = function (number) {
};
var inputBlockNumberFormatter = function (blockNumber) {
return blockNumber === null ? -1 : blockNumber;
return blockNumber === undefined ? "pending" : utils.toHex(blockNumber); // instead use default block number here
};
/**

View File

@ -11,12 +11,24 @@ var tests = [{
result: '0x31981',
formattedResult: '0x31981',
call: 'eth_getBalance'
}, {
args: [0x12d, 0x1],
formattedArgs: ['0x12d', '0x1'],
result: '0x31981',
formattedResult: '0x31981',
call: 'eth_getBalance'
}, {
args: [0x12d],
formattedArgs: ['0x12d', 'pending'], // here we might want to get current defaultBlock
result: '0x31981',
formattedResult: '0x31981',
call: 'eth_getBalance'
}];
describe('eth', function () {
describe(method, function () {
tests.forEach(function (test, index) {
it('sync test:' + index, function () {
it('sync test: ' + index, function () {
// given
var provider = new FakeHttpProvider();