2015-03-27 07:42:23 +00:00
|
|
|
var chai = require('chai');
|
|
|
|
var assert = chai.assert;
|
|
|
|
var web3 = require('../index');
|
|
|
|
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
|
|
|
var utils = require('../lib/utils/utils');
|
|
|
|
|
|
|
|
var desc = [{
|
|
|
|
"name": "balance(address)",
|
|
|
|
"type": "function",
|
|
|
|
"inputs": [{
|
|
|
|
"name": "who",
|
|
|
|
"type": "address"
|
|
|
|
}],
|
|
|
|
"constant": true,
|
|
|
|
"outputs": [{
|
|
|
|
"name": "value",
|
|
|
|
"type": "uint256"
|
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
"name": "send(address,uint256)",
|
|
|
|
"type": "function",
|
|
|
|
"inputs": [{
|
|
|
|
"name": "to",
|
|
|
|
"type": "address"
|
|
|
|
}, {
|
|
|
|
"name": "value",
|
|
|
|
"type": "uint256"
|
|
|
|
}],
|
|
|
|
"outputs": []
|
|
|
|
}, {
|
|
|
|
"name":"Changed",
|
|
|
|
"type":"event",
|
|
|
|
"inputs": [
|
|
|
|
{"name":"from","type":"address","indexed":true},
|
|
|
|
{"name":"amount","type":"uint256","indexed":true},
|
2015-03-27 10:27:50 +00:00
|
|
|
{"name":"t1","type":"uint256","indexed":false},
|
|
|
|
{"name":"t2","type":"uint256","indexed":false}
|
2015-03-27 07:42:23 +00:00
|
|
|
],
|
|
|
|
}];
|
|
|
|
|
|
|
|
var address = '0x1234567890123456789012345678901234567890';
|
|
|
|
|
|
|
|
describe('web3.eth.contract', function () {
|
|
|
|
describe('event', function () {
|
|
|
|
it('should probably create event filter', function (done) {
|
|
|
|
var provider = new FakeHttpProvider();
|
|
|
|
web3.setProvider(provider);
|
|
|
|
web3.reset(); // reset different polls
|
|
|
|
var sha3 = '0x5131231231231231231231';
|
|
|
|
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');
|
2015-03-27 10:27:50 +00:00
|
|
|
assert.equal(payload.params[0], web3.fromAscii('Changed(address,uint256,uint256,uint256)'));
|
2015-03-27 07:42:23 +00:00
|
|
|
} else if (step === 1) {
|
|
|
|
step = 2;
|
|
|
|
provider.injectResult(3);
|
|
|
|
assert.equal(payload.jsonrpc, '2.0');
|
|
|
|
assert.equal(payload.method, 'eth_newFilter');
|
|
|
|
assert.deepEqual(payload.params[0], {
|
|
|
|
topics: [
|
|
|
|
sha3,
|
|
|
|
'0x1234567890123456789012345678901234567890'
|
|
|
|
],
|
|
|
|
address: '0x1234567890123456789012345678901234567890'
|
|
|
|
});
|
|
|
|
} else if (step === 2 && utils.isArray(payload)) {
|
|
|
|
provider.injectBatchResults([[{
|
|
|
|
address: address,
|
|
|
|
topics: [
|
|
|
|
sha3,
|
|
|
|
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
|
|
'0x0000000000000000000000000000000000000000000000000000000000000001'
|
|
|
|
],
|
2015-03-27 10:27:50 +00:00
|
|
|
number: 2,
|
|
|
|
data: '0x0000000000000000000000000000000000000000000000000000000000000001' +
|
|
|
|
'0000000000000000000000000000000000000000000000000000000000000008'
|
2015-03-27 07:42:23 +00:00
|
|
|
}]]);
|
|
|
|
var r = payload.filter(function (p) {
|
|
|
|
return p.jsonrpc === '2.0' && p.method === 'eth_getFilterChanges' && p.params[0] === 3;
|
|
|
|
});
|
|
|
|
assert.equal(r.length > 0, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var Contract = web3.eth.contract(desc);
|
|
|
|
var contract = new Contract(address);
|
|
|
|
|
|
|
|
contract.Changed({from: address}).watch(function(err, result) {
|
|
|
|
assert.equal(result.args.from, address);
|
|
|
|
assert.equal(result.args.amount, 1);
|
2015-03-27 10:27:50 +00:00
|
|
|
assert.equal(result.args.t1, 1);
|
|
|
|
assert.equal(result.args.t2, 8);
|
2015-03-27 07:42:23 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|