Stabilize ID test for createJsonRpcRequest

This commit is contained in:
Simon Warta 2020-06-30 08:45:07 +02:00 committed by Simon Warta
parent bcbcf91fda
commit c1770dbe0c
2 changed files with 6 additions and 3 deletions

View File

@ -5,7 +5,7 @@ describe("jsonrpc", () => {
it("generates proper object with correct method", () => {
const request = createJsonRpcRequest("do_something");
expect(request.jsonrpc).toEqual("2.0");
expect(request.id.toString()).toMatch(/^[0-9]{10,12}$/);
expect(request.id.toString()).toMatch(/^[1-9]{12}$/);
expect(request.method).toEqual("do_something");
});

View File

@ -1,12 +1,15 @@
import { JsonRpcRequest } from "@cosmjs/json-rpc";
const numbers = "0123456789";
const numbersWithoutZero = "123456789";
/** generates a random numeric character */
function randomNumericChar(): string {
return numbers[Math.floor(Math.random() * numbers.length)];
return numbersWithoutZero[Math.floor(Math.random() * numbersWithoutZero.length)];
}
/**
* An (absolutely not cryptographically secure) random integer > 0.
*/
function randomId(): number {
return parseInt(
Array.from({ length: 12 })