mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Test nodeInfo and encodeTx in RestServer
This commit is contained in:
parent
19c9c27e76
commit
b7877d136d
@ -1,10 +1,41 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
import { Encoding } from "@iov/encoding";
|
||||
|
||||
import { RestClient } from "./restclient";
|
||||
import data from "./testdata/cosmoshub.json";
|
||||
import { StdTx } from "./types";
|
||||
|
||||
const { fromBase64 } = Encoding;
|
||||
|
||||
const httpUrl = "http://localhost:1317";
|
||||
const defaultNetworkId = "testing";
|
||||
function pendingWithoutCosmos(): void {
|
||||
if (!process.env.COSMOS_ENABLED) {
|
||||
return pending("Set COSMOS_ENABLED to enable Cosmos node-based tests");
|
||||
}
|
||||
}
|
||||
|
||||
describe("RestClient", () => {
|
||||
it("can be constructed", () => {
|
||||
const client = new RestClient(httpUrl);
|
||||
expect(client).toBeTruthy();
|
||||
});
|
||||
|
||||
describe("nodeInfo", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutCosmos();
|
||||
const client = new RestClient(httpUrl);
|
||||
const info = await client.nodeInfo();
|
||||
expect(info.node_info.network).toEqual(defaultNetworkId);
|
||||
});
|
||||
});
|
||||
|
||||
describe("encodeTx", () => {
|
||||
it("works for cosmoshub example", async () => {
|
||||
pendingWithoutCosmos();
|
||||
const tx: StdTx = data.tx.value;
|
||||
const client = new RestClient(httpUrl);
|
||||
expect(await client.encodeTx(tx)).toEqual(fromBase64(data.tx_data));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -139,7 +139,7 @@ export class RestClient {
|
||||
return responseData as BlocksResponse;
|
||||
}
|
||||
|
||||
// encodeTx returns the amino-encoding of the transaction
|
||||
/** returns the amino-encoding of the transaction performed by the server */
|
||||
public async encodeTx(stdTx: StdTx): Promise<Uint8Array> {
|
||||
const tx = { type: "cosmos-sdk/StdTx", value: stdTx };
|
||||
const responseData = await this.post("/txs/encode", tx);
|
||||
|
44
packages/sdk/src/testdata/cosmoshub.json
vendored
Normal file
44
packages/sdk/src/testdata/cosmoshub.json
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"//source": "https://hubble.figment.network/cosmos/chains/cosmoshub-3/blocks/415777/transactions/2BD600EA6090FC75FD844CA73542CC90A828770F4C01C5B483C3C1C43CCB65F4?format=json",
|
||||
"tx": {
|
||||
"type": "cosmos-sdk/StdTx",
|
||||
"value": {
|
||||
"msg": [
|
||||
{
|
||||
"type": "cosmos-sdk/MsgSend",
|
||||
"value": {
|
||||
"from_address": "cosmos1txqfn5jmcts0x0q7krdxj8tgf98tj0965vqlmq",
|
||||
"to_address": "cosmos1nynns8ex9fq6sjjfj8k79ymkdz4sqth06xexae",
|
||||
"amount": [
|
||||
{
|
||||
"denom": "uatom",
|
||||
"amount": "35997500"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"fee": {
|
||||
"amount": [
|
||||
{
|
||||
"denom": "uatom",
|
||||
"amount": "2500"
|
||||
}
|
||||
],
|
||||
"gas": "100000"
|
||||
},
|
||||
"signatures": [
|
||||
{
|
||||
"pub_key": {
|
||||
"type": "tendermint/PubKeySecp256k1",
|
||||
"value": "A5qFcJBJvEK/fOmEAY0DHNWwSRZ9TEfNZyH8VoVvDtAq"
|
||||
},
|
||||
"signature": "NK1Oy4EUGAsoC03c1wi9GG03JC/39LEdautC5Jk643oIbEPqeXHMwaqbdvO/Jws0X/NAXaN8SAy2KNY5Qml+5Q=="
|
||||
}
|
||||
],
|
||||
"memo": ""
|
||||
}
|
||||
},
|
||||
"tx_data": "ygEoKBapCkOoo2GaChRZgJnSW8Lg8zwesNppHWhJTrk8uhIUmSc4HyYqQahKSZHt4pN2aKsALu8aEQoFdWF0b20SCDM1OTk3NTAwEhMKDQoFdWF0b20SBDI1MDAQoI0GGmoKJuta6YchA5qFcJBJvEK/fOmEAY0DHNWwSRZ9TEfNZyH8VoVvDtAqEkA0rU7LgRQYCygLTdzXCL0YbTckL/f0sR1q60LkmTrjeghsQ+p5cczBqpt2878nCzRf80Bdo3xIDLYo1jlCaX7l",
|
||||
"id": "2BD600EA6090FC75FD844CA73542CC90A828770F4C01C5B483C3C1C43CCB65F4"
|
||||
}
|
1
packages/sdk/types/restclient.d.ts
vendored
1
packages/sdk/types/restclient.d.ts
vendored
@ -71,6 +71,7 @@ export declare class RestClient {
|
||||
nodeInfo(): Promise<NodeInfoResponse>;
|
||||
blocksLatest(): Promise<BlocksResponse>;
|
||||
blocks(height: number): Promise<BlocksResponse>;
|
||||
/** returns the amino-encoding of the transaction performed by the server */
|
||||
encodeTx(stdTx: StdTx): Promise<Uint8Array>;
|
||||
authAccounts(address: string, height?: string): Promise<AuthAccountsResponse>;
|
||||
txs(query: string): Promise<SearchTxsResponse>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user