mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Fix undefined this in decodeBroadcastTxAsync
This commit is contained in:
parent
4962be9729
commit
cd5bc69012
@ -12,6 +12,13 @@ and this project adheres to
|
||||
`string` as input types for the amount. This is useful if your values exceed
|
||||
the safe integer range.
|
||||
|
||||
### Fixed
|
||||
|
||||
- @cosmjs/tendermint-rpc: Fix undefined `this` in `decodeBroadcastTxAsync` and
|
||||
`broadcastTxAsync` ([#937]).
|
||||
|
||||
[#937]: https://github.com/cosmos/cosmjs/pull/937
|
||||
|
||||
## [0.26.4] - 2021-10-28
|
||||
|
||||
### Fixed
|
||||
|
@ -121,8 +121,8 @@ function decodeEvent(event: RpcEvent): responses.Event {
|
||||
};
|
||||
}
|
||||
|
||||
function decodeEvents(events: readonly RpcEvent[]): readonly responses.Event[] {
|
||||
return assertArray(events).map(decodeEvent);
|
||||
function decodeEvents(events: readonly RpcEvent[] | undefined): readonly responses.Event[] {
|
||||
return assertArray(events ?? []).map(decodeEvent);
|
||||
}
|
||||
|
||||
interface RpcTxData {
|
||||
@ -130,7 +130,7 @@ interface RpcTxData {
|
||||
readonly log?: string;
|
||||
/** base64 encoded */
|
||||
readonly data?: string;
|
||||
readonly events: readonly RpcEvent[];
|
||||
readonly events?: readonly RpcEvent[];
|
||||
}
|
||||
|
||||
function decodeTxData(data: RpcTxData): responses.TxData {
|
||||
@ -787,7 +787,7 @@ export class Responses {
|
||||
}
|
||||
|
||||
public static decodeBroadcastTxAsync(response: JsonRpcSuccessResponse): responses.BroadcastTxAsyncResponse {
|
||||
return this.decodeBroadcastTxSync(response);
|
||||
return Responses.decodeBroadcastTxSync(response);
|
||||
}
|
||||
|
||||
public static decodeBroadcastTxCommit(
|
||||
|
@ -47,22 +47,53 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it("can broadcast a transaction", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
describe("broadcastTxCommit", () => {
|
||||
it("can broadcast a transaction", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
|
||||
const response = await client.broadcastTxCommit({ tx: tx });
|
||||
expect(response.height).toBeGreaterThan(2);
|
||||
expect(response.hash).toBeTruthy();
|
||||
// verify success
|
||||
expect(response.checkTx.code).toBeFalsy();
|
||||
expect(response.deliverTx).toBeTruthy();
|
||||
if (response.deliverTx) {
|
||||
expect(response.deliverTx.code).toBeFalsy();
|
||||
}
|
||||
const response = await client.broadcastTxCommit({ tx: tx });
|
||||
expect(response.height).toBeGreaterThan(2);
|
||||
expect(response.hash).toBeTruthy();
|
||||
// verify success
|
||||
expect(response.checkTx.code).toBeFalsy();
|
||||
expect(response.deliverTx).toBeTruthy();
|
||||
if (response.deliverTx) {
|
||||
expect(response.deliverTx.code).toBeFalsy();
|
||||
}
|
||||
|
||||
client.disconnect();
|
||||
client.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("broadcastTxSync", () => {
|
||||
it("can broadcast a transaction", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
|
||||
const response = await client.broadcastTxSync({ tx: tx });
|
||||
expect(response.hash.length).toEqual(32);
|
||||
// verify success
|
||||
expect(response.code).toBeFalsy();
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("broadcastTxAsync", () => {
|
||||
it("can broadcast a transaction", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint33Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
|
||||
const response = await client.broadcastTxAsync({ tx: tx });
|
||||
// TODO: Remove any cast after https://github.com/cosmos/cosmjs/issues/938
|
||||
expect((response as any).hash.length).toEqual(32);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
it("gets the same tx hash from backend as calculated locally", async () => {
|
||||
|
@ -829,7 +829,7 @@ export class Responses {
|
||||
}
|
||||
|
||||
public static decodeBroadcastTxAsync(response: JsonRpcSuccessResponse): responses.BroadcastTxAsyncResponse {
|
||||
return this.decodeBroadcastTxSync(response);
|
||||
return Responses.decodeBroadcastTxSync(response);
|
||||
}
|
||||
|
||||
public static decodeBroadcastTxCommit(
|
||||
|
@ -47,22 +47,54 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it("can broadcast a transaction", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint34Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
describe("broadcastTxCommit", () => {
|
||||
it("can broadcast a transaction", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint34Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
|
||||
const response = await client.broadcastTxCommit({ tx: tx });
|
||||
expect(response.height).toBeGreaterThan(2);
|
||||
expect(response.hash).toBeTruthy();
|
||||
// verify success
|
||||
expect(response.checkTx.code).toBeFalsy();
|
||||
expect(response.deliverTx).toBeTruthy();
|
||||
if (response.deliverTx) {
|
||||
expect(response.deliverTx.code).toBeFalsy();
|
||||
}
|
||||
const response = await client.broadcastTxCommit({ tx: tx });
|
||||
expect(response.height).toBeGreaterThan(2);
|
||||
expect(response.hash).toBeTruthy();
|
||||
// verify success
|
||||
expect(response.checkTx.code).toBeFalsy();
|
||||
expect(response.deliverTx).toBeTruthy();
|
||||
if (response.deliverTx) {
|
||||
expect(response.deliverTx.code).toBeFalsy();
|
||||
}
|
||||
|
||||
client.disconnect();
|
||||
client.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("broadcastTxSync", () => {
|
||||
it("can broadcast a transaction", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint34Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
|
||||
const response = await client.broadcastTxSync({ tx: tx });
|
||||
expect(response.hash.length).toEqual(32);
|
||||
// verify success
|
||||
expect(response.code).toBeFalsy();
|
||||
expect(response.codeSpace).toBeFalsy();
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("broadcastTxAsync", () => {
|
||||
it("can broadcast a transaction", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint34Client.create(rpcFactory());
|
||||
const tx = buildKvTx(randomString(), randomString());
|
||||
|
||||
const response = await client.broadcastTxAsync({ tx: tx });
|
||||
// TODO: Remove any cast after https://github.com/cosmos/cosmjs/issues/938
|
||||
expect((response as any).hash.length).toEqual(32);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
it("gets the same tx hash from backend as calculated locally", async () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user