tests for transaction && call

This commit is contained in:
Marek Kotewicz 2015-03-31 09:34:06 +02:00
parent 31220d578f
commit e53f316db9
8 changed files with 77 additions and 11 deletions

View File

@ -2142,7 +2142,9 @@ var inputTransactionFormatter = function (options){
delete options.code;
}
['gasPrice', 'gas', 'value'].forEach(function(key){
['gasPrice', 'gas', 'value'].filter(function (key) {
return options[key] !== undefined;
}).forEach(function(key){
options[key] = utils.fromDecimal(options[key]);
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
dist/ethereum.js vendored
View File

@ -2142,7 +2142,9 @@ var inputTransactionFormatter = function (options){
delete options.code;
}
['gasPrice', 'gas', 'value'].forEach(function(key){
['gasPrice', 'gas', 'value'].filter(function (key) {
return options[key] !== undefined;
}).forEach(function(key){
options[key] = utils.fromDecimal(options[key]);
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -70,7 +70,9 @@ var inputTransactionFormatter = function (options){
delete options.code;
}
['gasPrice', 'gas', 'value'].forEach(function(key){
['gasPrice', 'gas', 'value'].filter(function (key) {
return options[key] !== undefined;
}).forEach(function(key){
options[key] = utils.fromDecimal(options[key]);
});

View File

@ -42,7 +42,7 @@ var address = '0x1234567890123456789012345678901234567890';
describe('web3.eth.contract', function () {
describe('event', function () {
it('should probably create event filter', function (done) {
it('should create event filter', function (done) {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
web3.reset(); // reset different polls
@ -97,5 +97,65 @@ describe('web3.eth.contract', function () {
done();
});
});
it('should call constant function', function () {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
web3.reset();
var sha3 = '0x5131231231231231231231';
var address = '0x1234567890123456789012345678901234567890';
provider.injectResult(sha3);
var step = 0;
provider.injectValidation(function (payload) {
if (step === 0) {
step = 1;
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'web3_sha3');
assert.equal(payload.params[0], web3.fromAscii('balance(address)'));
} else if (step === 1) {
assert.equal(payload.method, 'eth_call');
assert.deepEqual(payload.params, [{
data: sha3.slice(0, 10) + '0000000000000000000000001234567890123456789012345678901234567890',
to: address
}, 'latest']);
}
});
var Contract = web3.eth.contract(desc);
var contract = new Contract(address);
contract.balance(address);
});
it('should transact to normal function', function () {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
web3.reset();
var sha3 = '0x5131231231231231231231';
var address = '0x1234567890123456789012345678901234567890';
provider.injectResult(sha3);
var step = 0;
provider.injectValidation(function (payload) {
if (step === 0) {
step = 1;
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'web3_sha3');
assert.equal(payload.params[0], web3.fromAscii('send(address,uint256)'));
} else if (step === 1) {
assert.equal(payload.method, 'eth_sendTransaction');
assert.deepEqual(payload.params, [{
data: sha3.slice(0, 10) +
'0000000000000000000000001234567890123456789012345678901234567890' +
'0000000000000000000000000000000000000000000000000000000000000011' ,
to: address
}]);
}
});
var Contract = web3.eth.contract(desc);
var contract = new Contract(address);
contract.send(address, 17);
});
});
});