-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Problem
The rpc.query.ts
that Telescope generates is like,
export const createRPCQueryClient = async ({
rpcEndpoint,
}: {
rpcEndpoint: string | HttpEndpoint;
}) => {
const tmClient = await Tendermint34Client.connect(rpcEndpoint);
const client = new QueryClient(tmClient);
Such a construction depends on ambient authority of Tendermint34Client.connect
.
This causes a couple problems:
Prototype lockdown
The module with connect
imports axios
and that fails to load in Hardened JS:
Ambient authority
fetch
may not always be available, for example if run in a hardened compartment.
Mocking in tests
To test code with a fake RpcClient requires hacking into the module loader to intercept Axios.
Possible solution
You could move to just using Fetch API but that would still be an ambient authority.
Better would be an option for the createRPCQueryClient
helper (or whatever it be called) to take an RpcClient
instead of an endpoint. Then consumers can make their own RpcClient using whatever authorities are available, including a test mock.
Inside the function you can create the Tendermint client from the RpcClient argument,
const tmClient = await Tendermint34Client.create(rpcClient);