mirror of https://github.com/status-im/web3.js.git
contract async call && transact
This commit is contained in:
parent
1272780686
commit
a0b9cfb1e7
|
@ -2680,7 +2680,7 @@ SolidityFunction.prototype.sendTransaction = function () {
|
|||
return;
|
||||
}
|
||||
|
||||
web3.eth.call(payload, callback);
|
||||
web3.eth.sendTransaction(payload, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2680,7 +2680,7 @@ SolidityFunction.prototype.sendTransaction = function () {
|
|||
return;
|
||||
}
|
||||
|
||||
web3.eth.call(payload, callback);
|
||||
web3.eth.sendTransaction(payload, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -125,7 +125,7 @@ SolidityFunction.prototype.sendTransaction = function () {
|
|||
return;
|
||||
}
|
||||
|
||||
web3.eth.call(payload, callback);
|
||||
web3.eth.sendTransaction(payload, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -321,6 +321,43 @@ describe('web3.eth.contract', function () {
|
|||
contract.send.sendTransaction(address, 17, {from: address, gas: 50000, gasPrice: 3000, value: 10000});
|
||||
});
|
||||
|
||||
it('should explicitly sendTransaction with optional params and call callback without error', function (done) {
|
||||
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,
|
||||
from: address,
|
||||
gas: '0xc350',
|
||||
gasPrice: '0xbb8',
|
||||
value: '0x2710'
|
||||
}]);
|
||||
}
|
||||
});
|
||||
|
||||
var contract = web3.eth.contract(desc).at(address);
|
||||
|
||||
contract.send.sendTransaction(address, 17, {from: address, gas: 50000, gasPrice: 3000, value: 10000}, function (err) {
|
||||
assert.equal(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call testArr method and properly parse result', function () {
|
||||
var provider = new FakeHttpProvider2();
|
||||
web3.setProvider(provider);
|
||||
|
@ -350,10 +387,46 @@ describe('web3.eth.contract', function () {
|
|||
});
|
||||
|
||||
var contract = web3.eth.contract(desc).at(address);
|
||||
|
||||
var result = contract.testArr([3]);
|
||||
|
||||
assert.deepEqual(new BigNumber(5), result);
|
||||
});
|
||||
|
||||
it('should call testArr method, properly parse result and return the result async', function (done) {
|
||||
var provider = new FakeHttpProvider2();
|
||||
web3.setProvider(provider);
|
||||
web3.reset();
|
||||
var sha3 = '0x5131231231231231231231';
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
provider.injectResultList([{
|
||||
result: sha3
|
||||
}, {
|
||||
result: '0x0000000000000000000000000000000000000000000000000000000000000005'
|
||||
}]);
|
||||
var step = 0;
|
||||
provider.injectValidation(function (payload) {
|
||||
if (step === 1) { // getting sha3 is first
|
||||
assert.equal(payload.method, 'eth_call');
|
||||
assert.deepEqual(payload.params, [{
|
||||
data: sha3.slice(0, 10) +
|
||||
'0000000000000000000000000000000000000000000000000000000000000020' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000001' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000003',
|
||||
to: address
|
||||
},
|
||||
'latest'
|
||||
]);
|
||||
}
|
||||
step++;
|
||||
});
|
||||
|
||||
var contract = web3.eth.contract(desc).at(address);
|
||||
|
||||
contract.testArr([3], function (err, result) {
|
||||
assert.deepEqual(new BigNumber(5), result);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue