-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #402 from CosmWasm/test-query-client
Test QueryClient directly
- Loading branch information
Showing
7 changed files
with
104 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { toAscii } from "@cosmjs/encoding"; | ||
import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; | ||
|
||
import { cosmos } from "../codec"; | ||
import { nonNegativeIntegerMatcher, pendingWithoutSimapp, simapp, unused } from "../testutils.spec"; | ||
import { QueryClient } from "./queryclient"; | ||
import { toAccAddress } from "./utils"; | ||
|
||
async function makeClient(rpcUrl: string): Promise<[QueryClient, TendermintClient]> { | ||
const tmClient = await TendermintClient.connect(rpcUrl); | ||
return [QueryClient.withExtensions(tmClient), tmClient]; | ||
} | ||
|
||
describe("QueryClient", () => { | ||
describe("queryVerified", () => { | ||
it("works via WebSockets", async () => { | ||
pendingWithoutSimapp(); | ||
const [client, tmClient] = await makeClient(simapp.tendermintUrlWs); | ||
|
||
const key = Uint8Array.from([ | ||
...toAscii("balances"), | ||
...toAccAddress(unused.address), | ||
...toAscii(simapp.denomFee), | ||
]); | ||
const data = await client.queryVerified("bank", key); | ||
const response = cosmos.Coin.decode(data); | ||
expect(response.amount).toMatch(nonNegativeIntegerMatcher); | ||
expect(response.denom).toEqual(simapp.denomFee); | ||
|
||
tmClient.disconnect(); | ||
}); | ||
|
||
it("works via http", async () => { | ||
pendingWithoutSimapp(); | ||
const [client, tmClient] = await makeClient(simapp.tendermintUrlHttp); | ||
|
||
const key = Uint8Array.from([ | ||
...toAscii("balances"), | ||
...toAccAddress(unused.address), | ||
...toAscii(simapp.denomFee), | ||
]); | ||
const data = await client.queryVerified("bank", key); | ||
const response = cosmos.Coin.decode(data); | ||
expect(response.amount).toMatch(nonNegativeIntegerMatcher); | ||
expect(response.denom).toEqual(simapp.denomFee); | ||
|
||
tmClient.disconnect(); | ||
}); | ||
}); | ||
|
||
describe("queryUnverified", () => { | ||
it("works via WebSockets", async () => { | ||
pendingWithoutSimapp(); | ||
const [client, tmClient] = await makeClient(simapp.tendermintUrlWs); | ||
|
||
const requestData = Uint8Array.from( | ||
cosmos.bank.QueryAllBalancesRequest.encode({ address: toAccAddress(unused.address) }).finish(), | ||
); | ||
const data = await client.queryUnverified(`/cosmos.bank.Query/AllBalances`, requestData); | ||
const response = cosmos.bank.QueryAllBalancesResponse.decode(data); | ||
expect(response.balances.length).toEqual(2); | ||
|
||
tmClient.disconnect(); | ||
}); | ||
|
||
it("works via http", async () => { | ||
pendingWithoutSimapp(); | ||
const [client, tmClient] = await makeClient(simapp.tendermintUrlHttp); | ||
|
||
const requestData = Uint8Array.from( | ||
cosmos.bank.QueryAllBalancesRequest.encode({ address: toAccAddress(unused.address) }).finish(), | ||
); | ||
const data = await client.queryUnverified(`/cosmos.bank.Query/AllBalances`, requestData); | ||
const response = cosmos.bank.QueryAllBalancesResponse.decode(data); | ||
expect(response.balances.length).toEqual(2); | ||
|
||
tmClient.disconnect(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters