cosmwasm-stargate: Adjust CosmWasmClient.getSequence
This commit is contained in:
parent
68dc0b45cf
commit
8b7ef45f3a
@ -82,24 +82,6 @@ describe("CosmWasmClient", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSequence", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = await CosmWasmClient.connect(wasmd.endpoint);
|
||||
expect(await client.getSequence(unused.address)).toEqual({
|
||||
accountNumber: unused.accountNumber,
|
||||
sequence: unused.sequence,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null for missing accounts", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = await CosmWasmClient.connect(wasmd.endpoint);
|
||||
const missing = makeRandomAddress();
|
||||
expect(await client.getSequence(missing)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAccount", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
@ -120,6 +102,26 @@ describe("CosmWasmClient", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSequence", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = await CosmWasmClient.connect(wasmd.endpoint);
|
||||
expect(await client.getSequence(unused.address)).toEqual({
|
||||
accountNumber: unused.accountNumber,
|
||||
sequence: unused.sequence,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects for missing accounts", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = await CosmWasmClient.connect(wasmd.endpoint);
|
||||
const missing = makeRandomAddress();
|
||||
await expectAsync(client.getSequence(missing)).toBeRejectedWithError(
|
||||
/account does not exist on chain/i,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getBlock", () => {
|
||||
it("works for latest block", async () => {
|
||||
pendingWithoutWasmd();
|
||||
|
||||
@ -120,14 +120,17 @@ export class CosmWasmClient {
|
||||
}
|
||||
}
|
||||
|
||||
public async getSequence(address: string): Promise<SequenceResponse | null> {
|
||||
public async getSequence(address: string): Promise<SequenceResponse> {
|
||||
const account = await this.getAccount(address);
|
||||
return account
|
||||
? {
|
||||
accountNumber: account.accountNumber,
|
||||
sequence: account.sequence,
|
||||
}
|
||||
: null;
|
||||
if (!account) {
|
||||
throw new Error(
|
||||
"Account does not exist on chain. Send some tokens there before trying to query sequence.",
|
||||
);
|
||||
}
|
||||
return {
|
||||
accountNumber: account.accountNumber,
|
||||
sequence: account.sequence,
|
||||
};
|
||||
}
|
||||
|
||||
public async getBlock(height?: number): Promise<Block> {
|
||||
|
||||
@ -409,11 +409,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
throw new Error("Failed to retrieve account from signer");
|
||||
}
|
||||
const pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
||||
const accountFromChain = await this.getAccount(signerAddress);
|
||||
if (!accountFromChain) {
|
||||
throw new Error("Account not found");
|
||||
}
|
||||
const { accountNumber, sequence } = accountFromChain;
|
||||
const { accountNumber, sequence } = await this.getSequence(signerAddress);
|
||||
const chainId = await this.getChainId();
|
||||
const txBody = {
|
||||
messages: messages,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user