diff --git a/packages/bcp/src/cosmwasmcodec.ts b/packages/bcp/src/cosmwasmcodec.ts index 21a2c55c..1b2f1e76 100644 --- a/packages/bcp/src/cosmwasmcodec.ts +++ b/packages/bcp/src/cosmwasmcodec.ts @@ -96,20 +96,3 @@ export class CosmWasmCodec implements TxCodec { return isValidAddress(address); } } - -const defaultPrefix = "cosmos" as CosmosAddressBech32Prefix; - -const defaultTokens: BankTokens = [ - { - fractionalDigits: 6, - ticker: "ATOM", - denom: "uatom", - }, -]; - -/** - * Unconfigured codec is useful for testing only - * - * @deprecated use CosmWasmCodec constructor - */ -export const cosmWasmCodec = new CosmWasmCodec(defaultPrefix, defaultTokens); diff --git a/packages/bcp/src/cosmwasmconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts index 6baa9f01..769eb07a 100644 --- a/packages/bcp/src/cosmwasmconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -16,7 +16,7 @@ import { Bech32, Encoding } from "@iov/encoding"; import { HdPaths, Secp256k1HdWallet, UserProfile } from "@iov/keycontrol"; import { assert } from "@iov/utils"; -import { CosmWasmCodec, cosmWasmCodec } from "./cosmwasmcodec"; +import { CosmWasmCodec } from "./cosmwasmcodec"; import { CosmWasmConnection, TokenConfiguration } from "./cosmwasmconnection"; import { signedTxJson, txId } from "./testdata.spec"; import { nonceToSequence } from "./types"; @@ -97,6 +97,17 @@ describe("CosmWasmConnection", () => { ], }; + const atomConfig: TokenConfiguration = { + bankTokens: [ + { + fractionalDigits: 6, + name: "Atom", + ticker: "ATOM", + denom: "uatom", + }, + ], + }; + describe("establish", () => { it("can connect to Cosmos via http", async () => { pendingWithoutCosmos(); @@ -187,9 +198,9 @@ describe("CosmWasmConnection", () => { describe("identifier", () => { it("calculates tx hash from PostableBytes", async () => { pendingWithoutCosmos(); - const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultConfig); - // tslint:disable-next-line: deprecation - const postable = cosmWasmCodec.bytesToPost(signedTxJson); + const codec = new CosmWasmCodec(defaultPrefix, atomConfig.bankTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, atomConfig); + const postable = codec.bytesToPost(signedTxJson); const id = await connection.identifier(postable); expect(id).toMatch(/^[0-9A-F]{64}$/); expect(id).toEqual(txId); @@ -258,12 +269,12 @@ describe("CosmWasmConnection", () => { describe("integration tests", () => { it("can post and get a transaction", async () => { pendingWithoutCosmos(); + const codec = new CosmWasmCodec(defaultPrefix, defaultConfig.bankTokens); const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultConfig); const profile = new UserProfile(); const wallet = profile.addWallet(Secp256k1HdWallet.fromMnemonic(faucetMnemonic)); const faucet = await profile.createIdentity(wallet.id, defaultChainId, faucetPath); - // tslint:disable-next-line: deprecation - const faucetAddress = cosmWasmCodec.identityToAddress(faucet); + const faucetAddress = codec.identityToAddress(faucet); const unsigned = await connection.withDefaultFee({ kind: "bcp/send", @@ -278,8 +289,6 @@ describe("CosmWasmConnection", () => { }, }); const nonce = await connection.getNonce({ address: faucetAddress }); - // TODO: we need to use custom codecs everywhere - const codec = new CosmWasmCodec(defaultPrefix, defaultConfig.bankTokens); const signed = await profile.signTransaction(faucet, unsigned, codec, nonce); const postableBytes = codec.bytesToPost(signed); const response = await connection.postTx(postableBytes); @@ -324,12 +333,12 @@ describe("CosmWasmConnection", () => { it("can post and search for a transaction", async () => { pendingWithoutCosmos(); + const codec = new CosmWasmCodec(defaultPrefix, defaultConfig.bankTokens); const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultConfig); const profile = new UserProfile(); const wallet = profile.addWallet(Secp256k1HdWallet.fromMnemonic(faucetMnemonic)); const faucet = await profile.createIdentity(wallet.id, defaultChainId, faucetPath); - // tslint:disable-next-line: deprecation - const faucetAddress = cosmWasmCodec.identityToAddress(faucet); + const faucetAddress = codec.identityToAddress(faucet); const unsigned = await connection.withDefaultFee({ kind: "bcp/send", @@ -344,8 +353,6 @@ describe("CosmWasmConnection", () => { }, }); const nonce = await connection.getNonce({ address: faucetAddress }); - // TODO: we need to use custom codecs everywhere - const codec = new CosmWasmCodec(defaultPrefix, defaultConfig.bankTokens); const signed = await profile.signTransaction(faucet, unsigned, codec, nonce); const postableBytes = codec.bytesToPost(signed); const response = await connection.postTx(postableBytes); diff --git a/packages/bcp/types/cosmwasmcodec.d.ts b/packages/bcp/types/cosmwasmcodec.d.ts index c44c38b5..c7f01fb1 100644 --- a/packages/bcp/types/cosmwasmcodec.d.ts +++ b/packages/bcp/types/cosmwasmcodec.d.ts @@ -28,9 +28,3 @@ export declare class CosmWasmCodec implements TxCodec { identityToAddress(identity: Identity): Address; isValidAddress(address: string): boolean; } -/** - * Unconfigured codec is useful for testing only - * - * @deprecated use CosmWasmCodec constructor - */ -export declare const cosmWasmCodec: CosmWasmCodec;