mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Stabilize ID test for createJsonRpcRequest
This commit is contained in:
parent
bcbcf91fda
commit
c1770dbe0c
@ -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");
|
||||
});
|
||||
|
||||
|
@ -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 })
|
||||
|
Loading…
x
Reference in New Issue
Block a user