You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
69 lines
2.2 KiB
var chai = require('chai');
|
|
var assert = chai.assert;
|
|
var web3 = require('../index');
|
|
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
|
var utils = require('../lib/utils/utils');
|
|
|
|
var tests = [{
|
|
protocol: 'eth',
|
|
args: ['pending'],
|
|
firstResult: 1,
|
|
firstPayload: {
|
|
method: "eth_newBlockFilter",
|
|
params: [
|
|
"pending"
|
|
]
|
|
},
|
|
secondResult: [null],
|
|
secondPayload: {
|
|
method: "eth_getFilterChanges"
|
|
}
|
|
}];
|
|
|
|
|
|
var testPolling = function (tests) {
|
|
|
|
describe('web3.eth.filter.polling', function () {
|
|
tests.forEach(function (test, index) {
|
|
it('should create && successfully poll filter', function (done) {
|
|
|
|
// given
|
|
var provider = new FakeHttpProvider();
|
|
web3.setProvider(provider);
|
|
web3.reset();
|
|
provider.injectResult(test.firstResult);
|
|
var step = 0;
|
|
provider.injectValidation(function (payload) {
|
|
if (step === 0) {
|
|
step = 1;
|
|
assert.equal(payload.jsonrpc, '2.0');
|
|
assert.equal(payload.method, test.firstPayload.method);
|
|
assert.deepEqual(payload.params, test.firstPayload.params);
|
|
} else if (step === 1 && utils.isArray(payload)) {
|
|
var r = payload.filter(function (p) {
|
|
return p.jsonrpc === '2.0' && p.method === test.secondPayload.method && p.params[0] === test.firstResult;
|
|
});
|
|
assert.equal(r.length > 0, true);
|
|
}
|
|
|
|
});
|
|
|
|
// when
|
|
var filter = web3[test.protocol].filter.apply(null, test.args);
|
|
provider.injectBatchResults([test.secondResult]);
|
|
filter.watch(function (err, result) {
|
|
if (test.err) {
|
|
// todo
|
|
} else {
|
|
assert.equal(result, test.secondResult[0]);
|
|
}
|
|
done();
|
|
|
|
});
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
testPolling(tests);
|
|
|
|
|