Merge pull request #81 from confio/calc-nonce-from-account-and-sequence
Calculate Nonce from account number and sequence
This commit is contained in:
commit
e0e5f1d568
@ -19,7 +19,6 @@ import { assert } from "@iov/utils";
|
||||
import { CosmWasmCodec } from "./cosmwasmcodec";
|
||||
import { CosmWasmConnection, TokenConfiguration } from "./cosmwasmconnection";
|
||||
import { signedTxJson, txId } from "./testdata.spec";
|
||||
import { nonceToSequence } from "./types";
|
||||
|
||||
const { fromBase64, toHex } = Encoding;
|
||||
|
||||
@ -302,9 +301,10 @@ describe("CosmWasmConnection", () => {
|
||||
if (isFailedTransaction(getResponse)) {
|
||||
throw new Error("Expected transaction to succeed");
|
||||
}
|
||||
assert(getResponse.log, "Log must be available");
|
||||
// we get a json response in the log for each msg, multiple events is good (transfer succeeded)
|
||||
const log = JSON.parse(getResponse.log!)[0];
|
||||
expect(log.events.length).toBe(2);
|
||||
const [firstLog] = JSON.parse(getResponse.log);
|
||||
expect(firstLog.events.length).toEqual(2);
|
||||
const { transaction, signatures } = getResponse;
|
||||
if (!isSendTransaction(transaction)) {
|
||||
throw new Error("Expected send transaction");
|
||||
@ -317,9 +317,7 @@ describe("CosmWasmConnection", () => {
|
||||
expect(transaction.chainId).toEqual(unsigned.chainId);
|
||||
|
||||
expect(signatures.length).toEqual(1);
|
||||
// TODO: the nonce we recover in response doesn't have accountNumber, only sequence
|
||||
const signedSequence = nonceToSequence(signed.signatures[0].nonce);
|
||||
expect(signatures[0].nonce).toEqual(signedSequence);
|
||||
expect(signatures[0].nonce).toEqual(signed.signatures[0].nonce);
|
||||
expect(signatures[0].pubkey.algo).toEqual(signed.signatures[0].pubkey.algo);
|
||||
expect(toHex(signatures[0].pubkey.data)).toEqual(
|
||||
toHex(Secp256k1.compressPubkey(signed.signatures[0].pubkey.data)),
|
||||
@ -363,7 +361,6 @@ describe("CosmWasmConnection", () => {
|
||||
// search by id
|
||||
|
||||
const idSearchResponse = await connection.searchTx({ id: transactionId });
|
||||
expect(idSearchResponse).toBeTruthy();
|
||||
expect(idSearchResponse.length).toEqual(1);
|
||||
|
||||
const idResult = idSearchResponse[0];
|
||||
@ -371,8 +368,9 @@ describe("CosmWasmConnection", () => {
|
||||
if (isFailedTransaction(idResult)) {
|
||||
throw new Error("Expected transaction to succeed");
|
||||
}
|
||||
const idlog = JSON.parse(idResult.log!)[0];
|
||||
expect(idlog.events.length).toBe(2);
|
||||
assert(idResult.log, "Log must be available");
|
||||
const [firstIdlog] = JSON.parse(idResult.log);
|
||||
expect(firstIdlog.events.length).toEqual(2);
|
||||
|
||||
const { transaction: idTransaction } = idResult;
|
||||
if (!isSendTransaction(idTransaction)) {
|
||||
@ -395,8 +393,9 @@ describe("CosmWasmConnection", () => {
|
||||
if (isFailedTransaction(senderAddressResult)) {
|
||||
throw new Error("Expected transaction to succeed");
|
||||
}
|
||||
const senderLog = JSON.parse(senderAddressResult.log!)[0];
|
||||
expect(senderLog.events.length).toBe(2);
|
||||
assert(senderAddressResult.log, "Log must be available");
|
||||
const [firstSenderLog] = JSON.parse(senderAddressResult.log);
|
||||
expect(firstSenderLog.events.length).toEqual(2);
|
||||
|
||||
const { transaction: senderAddressTransaction } = senderAddressResult;
|
||||
if (!isSendTransaction(senderAddressTransaction)) {
|
||||
@ -443,8 +442,9 @@ describe("CosmWasmConnection", () => {
|
||||
if (isFailedTransaction(heightResult)) {
|
||||
throw new Error("Expected transaction to succeed");
|
||||
}
|
||||
const heightLog = JSON.parse(heightResult.log!)[0];
|
||||
expect(heightLog.events.length).toBe(2);
|
||||
assert(heightResult.log, "Log must be available");
|
||||
const [firstHeightLog] = JSON.parse(heightResult.log);
|
||||
expect(firstHeightLog.events.length).toEqual(2);
|
||||
|
||||
const { transaction: heightTransaction } = heightResult;
|
||||
if (!isSendTransaction(heightTransaction)) {
|
||||
|
||||
@ -372,9 +372,12 @@ export class CosmWasmConnection implements BlockchainConnection {
|
||||
|
||||
// tslint:disable-next-line: deprecation
|
||||
const accountForHeight = await this.restClient.authAccounts(senderAddress, response.height);
|
||||
// this is technically not the proper nonce. maybe this causes issues for sig validation?
|
||||
const accountNumber = accountForHeight.result.value.account_number;
|
||||
// this is technically not the proper sequence. maybe this causes issues for sig validation?
|
||||
// leaving for now unless it causes issues
|
||||
const sequence = (accountForHeight.result.value.sequence - 1) as Nonce;
|
||||
return parseTxsResponse(chainId, parseInt(response.height, 10), sequence, response, this.bankTokens);
|
||||
const sequence = accountForHeight.result.value.sequence - 1;
|
||||
const nonce = accountToNonce(accountNumber, sequence);
|
||||
|
||||
return parseTxsResponse(chainId, parseInt(response.height, 10), nonce, response, this.bankTokens);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user