From 58634eb577f96cba113e632642a2d9b4a37c1fe5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 12 Feb 2020 00:39:02 +0100 Subject: [PATCH 1/2] Calculate Nonce from account number and sequence --- packages/bcp/src/cosmwasmconnection.spec.ts | 5 +---- packages/bcp/src/cosmwasmconnection.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/bcp/src/cosmwasmconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts index 6e28d6dc..7387cd2f 100644 --- a/packages/bcp/src/cosmwasmconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -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; @@ -317,9 +316,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)), diff --git a/packages/bcp/src/cosmwasmconnection.ts b/packages/bcp/src/cosmwasmconnection.ts index a659d89f..801ec313 100644 --- a/packages/bcp/src/cosmwasmconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -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); } } From 2b8a1bce358beaff546f3c4621853b2d832fda04 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 12 Feb 2020 00:54:42 +0100 Subject: [PATCH 2/2] Random test cleanups --- packages/bcp/src/cosmwasmconnection.spec.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/bcp/src/cosmwasmconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts index 7387cd2f..d3f3ae56 100644 --- a/packages/bcp/src/cosmwasmconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -301,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"); @@ -360,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]; @@ -368,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)) { @@ -392,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)) { @@ -440,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)) {