2015-03-28 13:38:56 +00:00
|
|
|
var chai = require('chai');
|
|
|
|
var assert = chai.assert;
|
2016-08-26 21:55:16 +00:00
|
|
|
var Jsonrpc = require('../lib/web3/jsonrpc');
|
2015-02-03 22:00:02 +00:00
|
|
|
|
|
|
|
describe('jsonrpc', function () {
|
|
|
|
describe('toPayload', function () {
|
|
|
|
it('should create basic payload', function () {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var method = 'helloworld';
|
|
|
|
|
|
|
|
// when
|
2016-08-26 21:55:16 +00:00
|
|
|
var payload = Jsonrpc.toPayload(method);
|
2015-02-03 22:00:02 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
assert.equal(payload.jsonrpc, '2.0');
|
|
|
|
assert.equal(payload.method, method);
|
|
|
|
assert.equal(payload.params instanceof Array, true);
|
|
|
|
assert.equal(payload.params.length, 0);
|
|
|
|
assert.equal(typeof payload.id, 'number');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create payload with params', function () {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var method = 'helloworld1';
|
|
|
|
var params = [123, 'test'];
|
|
|
|
|
|
|
|
// when
|
2016-08-26 21:55:16 +00:00
|
|
|
var payload = Jsonrpc.toPayload(method, params);
|
2015-02-03 22:00:02 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
assert.equal(payload.jsonrpc, '2.0');
|
|
|
|
assert.equal(payload.method, method);
|
|
|
|
assert.equal(payload.params.length, 2);
|
|
|
|
assert.equal(payload.params[0], params[0]);
|
|
|
|
assert.equal(payload.params[1], params[1]);
|
|
|
|
assert.equal(typeof payload.id, 'number');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|