From 334df80061f7a0292efa63d57abbf66bc28b1d8a Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 29 Sep 2020 18:43:04 +0200 Subject: [PATCH] Create broadcasting test --- .../launchpad-ledger/src/ledgersigner.spec.ts | 35 +++++++++++++++++-- .../launchpad-ledger/src/testutils.spec.ts | 5 +++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/launchpad-ledger/src/ledgersigner.spec.ts b/packages/launchpad-ledger/src/ledgersigner.spec.ts index 8fe88e9c..6314e2cd 100644 --- a/packages/launchpad-ledger/src/ledgersigner.spec.ts +++ b/packages/launchpad-ledger/src/ledgersigner.spec.ts @@ -1,10 +1,20 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto"; import { fromBase64 } from "@cosmjs/encoding"; -import { coins, makeCosmoshubPath, makeSignDoc, Msg, serializeSignDoc, StdFee } from "@cosmjs/launchpad"; +import { + coins, + isBroadcastTxSuccess, + makeCosmoshubPath, + makeSignDoc, + Msg, + serializeSignDoc, + SigningCosmosClient, + StdFee, +} from "@cosmjs/launchpad"; +import { assert } from "@cosmjs/utils"; import { LedgerSigner } from "./ledgersigner"; -import { pendingWithoutLedger, pendingWithoutLedgerInteractive } from "./testutils.spec"; +import { pendingWithoutLedger, pendingWithoutLedgerInteractive, wasmd } from "./testutils.spec"; const interactiveTimeout = 120_000; @@ -53,7 +63,7 @@ describe("LedgerSigner", () => { describe("sign", () => { it( - "works", + "returns valid signature", async () => { pendingWithoutLedgerInteractive(); const signer = new LedgerSigner({ @@ -94,5 +104,24 @@ describe("LedgerSigner", () => { }, interactiveTimeout, ); + + it( + "creates signature accepted by launchpad backend", + async () => { + pendingWithoutLedgerInteractive(); + const signer = new LedgerSigner({ + testModeAllowed: true, + hdPaths: [makeCosmoshubPath(0), makeCosmoshubPath(1), makeCosmoshubPath(10)], + }); + const [fistAccount] = await signer.getAccounts(); + + const client = new SigningCosmosClient(wasmd.endpoint, fistAccount.address, signer); + const result = await client.sendTokens(defaultRecipient, coins(1234567, "ucosm")); + assert(isBroadcastTxSuccess(result)); + + await signer.disconnect(); + }, + interactiveTimeout, + ); }); }); diff --git a/packages/launchpad-ledger/src/testutils.spec.ts b/packages/launchpad-ledger/src/testutils.spec.ts index b4e493cf..598501a3 100644 --- a/packages/launchpad-ledger/src/testutils.spec.ts +++ b/packages/launchpad-ledger/src/testutils.spec.ts @@ -17,3 +17,8 @@ export function pendingWithoutLedgerInteractive(): void { return pending("Set LEDGER_INTERACTIVE_ENABLED to enable Wasmd based tests"); } } + +export const wasmd = { + endpoint: "http://localhost:1317", + chainId: "testing", +};