stargate: Adjust StargateClient.getSequence

This commit is contained in:
willclarktech
2021-03-30 17:13:32 +02:00
parent 86fc265fba
commit 68dc0b45cf
3 changed files with 15 additions and 15 deletions
@@ -276,11 +276,7 @@ export class SigningStargateClient extends StargateClient {
if (explicitSignerData) {
signerData = explicitSignerData;
} else {
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();
signerData = { accountNumber, sequence, chainId };
}
+4 -3
View File
@@ -131,12 +131,13 @@ describe("StargateClient", () => {
client.disconnect();
});
it("returns null for non-existent address", async () => {
it("rejects for non-existent address", async () => {
pendingWithoutSimapp();
const client = await StargateClient.connect(simapp.tendermintUrl);
const account = await client.getSequence(nonExistentAddress);
expect(account).toBeNull();
await expectAsync(client.getSequence(nonExistentAddress)).toBeRejectedWithError(
/account does not exist on chain/i,
);
client.disconnect();
});
+10 -7
View File
@@ -177,14 +177,17 @@ export class StargateClient {
return account ? accountFromAny(account) : null;
}
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> {