Test nodeInfo and encodeTx in RestServer

This commit is contained in:
Simon Warta 2020-02-04 00:02:44 +01:00
parent 19c9c27e76
commit b7877d136d
4 changed files with 77 additions and 1 deletions

View File

@ -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));
});
});
});

View File

@ -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);

View 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"
}

View File

@ -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>;