Skip to content

Commit

Permalink
contract async call && transact
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed May 11, 2015
1 parent 1272780 commit a0b9cfb
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/web3-light.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/web3-light.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web3-light.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/web3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/web3.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/web3/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ SolidityFunction.prototype.sendTransaction = function () {
return;
}

web3.eth.call(payload, callback);
web3.eth.sendTransaction(payload, callback);
};

/**
Expand Down
75 changes: 74 additions & 1 deletion test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
});

});
});
});

0 comments on commit a0b9cfb

Please sign in to comment.