From 7c8ddf801920ed1a400fe961f661be39fe8a40b5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 29 Jan 2020 13:41:17 +0100 Subject: [PATCH] Rename cosmos* types to cosmwasm* --- ...moscodec.spec.ts => cosmwasmcodec.spec.ts} | 18 +++++----- .../src/{cosmoscodec.ts => cosmwasmcodec.ts} | 4 +-- ...ion.spec.ts => cosmwasmconnection.spec.ts} | 36 +++++++++---------- ...mosconnection.ts => cosmwasmconnection.ts} | 6 ++-- ...osmosconnector.ts => cosmwasmconnector.ts} | 12 +++---- packages/bcp/src/index.ts | 6 ++-- .../{cosmoscodec.d.ts => cosmwasmcodec.d.ts} | 4 +-- ...onnection.d.ts => cosmwasmconnection.d.ts} | 8 +++-- ...sconnector.d.ts => cosmwasmconnector.d.ts} | 6 ++-- packages/bcp/types/index.d.ts | 6 ++-- 10 files changed, 55 insertions(+), 51 deletions(-) rename packages/bcp/src/{cosmoscodec.spec.ts => cosmwasmcodec.spec.ts} (69%) rename packages/bcp/src/{cosmoscodec.ts => cosmwasmcodec.ts} (96%) rename packages/bcp/src/{cosmosconnection.spec.ts => cosmwasmconnection.spec.ts} (90%) rename packages/bcp/src/{cosmosconnection.ts => cosmwasmconnection.ts} (98%) rename packages/bcp/src/{cosmosconnector.ts => cosmwasmconnector.ts} (54%) rename packages/bcp/types/{cosmoscodec.d.ts => cosmwasmcodec.d.ts} (87%) rename packages/bcp/types/{cosmosconnection.d.ts => cosmwasmconnection.d.ts} (90%) rename packages/bcp/types/{cosmosconnector.d.ts => cosmwasmconnector.d.ts} (67%) diff --git a/packages/bcp/src/cosmoscodec.spec.ts b/packages/bcp/src/cosmwasmcodec.spec.ts similarity index 69% rename from packages/bcp/src/cosmoscodec.spec.ts rename to packages/bcp/src/cosmwasmcodec.spec.ts index a4a046ec..1829b936 100644 --- a/packages/bcp/src/cosmoscodec.spec.ts +++ b/packages/bcp/src/cosmwasmcodec.spec.ts @@ -1,12 +1,12 @@ import { PostableBytes, PrehashType } from "@iov/bcp"; import { Encoding } from "@iov/encoding"; -import { cosmosCodec } from "./cosmoscodec"; +import { cosmWasmCodec } from "./cosmwasmcodec"; import { chainId, nonce, sendTxJson, signedTxBin, signedTxJson, txId } from "./testdata.spec"; const { toUtf8 } = Encoding; -describe("cosmoscodec", () => { +describe("cosmWasmCodec", () => { it("properly generates bytes to sign", () => { const expected = { bytes: toUtf8( @@ -14,36 +14,36 @@ describe("cosmoscodec", () => { ), prehashType: PrehashType.Sha256, }; - const bytesToSign = cosmosCodec.bytesToSign(sendTxJson, nonce); + const bytesToSign = cosmWasmCodec.bytesToSign(sendTxJson, nonce); expect(bytesToSign).toEqual(expected); }); it("properly encodes transactions", () => { - const encoded = cosmosCodec.bytesToPost(signedTxJson); + const encoded = cosmWasmCodec.bytesToPost(signedTxJson); expect(encoded).toEqual(signedTxBin); }); it("throws when trying to decode a transaction without a nonce", () => { - expect(() => cosmosCodec.parseBytes(signedTxBin as PostableBytes, chainId)).toThrowError( + expect(() => cosmWasmCodec.parseBytes(signedTxBin as PostableBytes, chainId)).toThrowError( /nonce is required/i, ); }); it("properly decodes transactions", () => { - const decoded = cosmosCodec.parseBytes(signedTxBin as PostableBytes, chainId, nonce); + const decoded = cosmWasmCodec.parseBytes(signedTxBin as PostableBytes, chainId, nonce); expect(decoded).toEqual(signedTxJson); }); it("generates transaction id", () => { - const id = cosmosCodec.identifier(signedTxJson); + const id = cosmWasmCodec.identifier(signedTxJson); expect(id).toMatch(/^[0-9A-F]{64}$/); expect(id).toEqual(txId); }); it("round trip works", () => { - const encoded = cosmosCodec.bytesToPost(signedTxJson); - const decoded = cosmosCodec.parseBytes(encoded, chainId, nonce); + const encoded = cosmWasmCodec.bytesToPost(signedTxJson); + const decoded = cosmWasmCodec.parseBytes(encoded, chainId, nonce); expect(decoded).toEqual(signedTxJson); }); }); diff --git a/packages/bcp/src/cosmoscodec.ts b/packages/bcp/src/cosmwasmcodec.ts similarity index 96% rename from packages/bcp/src/cosmoscodec.ts rename to packages/bcp/src/cosmwasmcodec.ts index f4b3619d..17e8c70a 100644 --- a/packages/bcp/src/cosmoscodec.ts +++ b/packages/bcp/src/cosmwasmcodec.ts @@ -44,7 +44,7 @@ function sortJson(json: any): any { return result; } -export class CosmosCodec implements TxCodec { +export class CosmWasmCodec implements TxCodec { private readonly prefix: CosmosBech32Prefix; private readonly tokens: TokenInfos; @@ -113,4 +113,4 @@ const defaultTokens: TokenInfos = [ }, ]; -export const cosmosCodec = new CosmosCodec(defaultPrefix, defaultTokens); +export const cosmWasmCodec = new CosmWasmCodec(defaultPrefix, defaultTokens); diff --git a/packages/bcp/src/cosmosconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts similarity index 90% rename from packages/bcp/src/cosmosconnection.spec.ts rename to packages/bcp/src/cosmwasmconnection.spec.ts index fc916c56..3bb665fc 100644 --- a/packages/bcp/src/cosmosconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -15,8 +15,8 @@ import { Encoding } from "@iov/encoding"; import { HdPaths, Secp256k1HdWallet, UserProfile } from "@iov/keycontrol"; import { CosmosBech32Prefix } from "./address"; -import { CosmosCodec, cosmosCodec } from "./cosmoscodec"; -import { CosmosConnection } from "./cosmosconnection"; +import { CosmWasmCodec, cosmWasmCodec } from "./cosmwasmcodec"; +import { CosmWasmConnection } from "./cosmwasmconnection"; import { nonceToSequence, TokenInfos } from "./types"; const { fromBase64, toHex } = Encoding; @@ -27,7 +27,7 @@ function pendingWithoutCosmos(): void { } } -describe("CosmosConnection", () => { +describe("CosmWasmConnection", () => { const cosm = "COSM" as TokenTicker; const httpUrl = "http://localhost:1317"; const defaultChainId = "cosmos:testing" as ChainId; @@ -63,7 +63,7 @@ describe("CosmosConnection", () => { describe("establish", () => { it("can connect to Cosmos via http", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); expect(connection).toBeTruthy(); connection.disconnect(); }); @@ -72,7 +72,7 @@ describe("CosmosConnection", () => { describe("chainId", () => { it("displays the chain ID", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const chainId = connection.chainId(); expect(chainId).toEqual(defaultChainId); connection.disconnect(); @@ -82,7 +82,7 @@ describe("CosmosConnection", () => { describe("height", () => { it("displays the current height", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const height = await connection.height(); expect(height).toBeGreaterThan(0); connection.disconnect(); @@ -92,7 +92,7 @@ describe("CosmosConnection", () => { describe("getToken", () => { it("displays a given token", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const token = await connection.getToken("COSM" as TokenTicker); expect(token).toEqual({ fractionalDigits: 6, @@ -104,7 +104,7 @@ describe("CosmosConnection", () => { it("resolves to undefined if the token is not supported", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const token = await connection.getToken("whatever" as TokenTicker); expect(token).toBeUndefined(); connection.disconnect(); @@ -114,7 +114,7 @@ describe("CosmosConnection", () => { describe("getAllTokens", () => { it("resolves to a list of all supported tokens", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const tokens = await connection.getAllTokens(); // TODO: make this more flexible expect(tokens).toEqual([ @@ -136,7 +136,7 @@ describe("CosmosConnection", () => { describe("getAccount", () => { it("gets an empty account by address", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const account = await connection.getAccount({ address: defaultEmptyAddress }); expect(account).toBeUndefined(); connection.disconnect(); @@ -144,7 +144,7 @@ describe("CosmosConnection", () => { it("gets an account by address", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const account = await connection.getAccount({ address: defaultAddress }); if (account === undefined) { throw new Error("Expected account not to be undefined"); @@ -161,7 +161,7 @@ describe("CosmosConnection", () => { it("gets an account by pubkey", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const account = await connection.getAccount({ pubkey: defaultPubkey }); if (account === undefined) { throw new Error("Expected account not to be undefined"); @@ -180,11 +180,11 @@ describe("CosmosConnection", () => { describe("integration tests", () => { it("can post and get a transaction", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const profile = new UserProfile(); const wallet = profile.addWallet(Secp256k1HdWallet.fromMnemonic(faucetMnemonic)); const faucet = await profile.createIdentity(wallet.id, defaultChainId, faucetPath); - const faucetAddress = cosmosCodec.identityToAddress(faucet); + const faucetAddress = cosmWasmCodec.identityToAddress(faucet); const unsigned = await connection.withDefaultFee({ kind: "bcp/send", @@ -200,7 +200,7 @@ describe("CosmosConnection", () => { }); const nonce = await connection.getNonce({ address: faucetAddress }); // TODO: we need to use custom codecs everywhere - const codec = new CosmosCodec(defaultPrefix, defaultTokens); + const codec = new CosmWasmCodec(defaultPrefix, defaultTokens); const signed = await profile.signTransaction(faucet, unsigned, codec, nonce); const postableBytes = codec.bytesToPost(signed); const response = await connection.postTx(postableBytes); @@ -243,11 +243,11 @@ describe("CosmosConnection", () => { it("can post and search for a transaction", async () => { pendingWithoutCosmos(); - const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultTokens); const profile = new UserProfile(); const wallet = profile.addWallet(Secp256k1HdWallet.fromMnemonic(faucetMnemonic)); const faucet = await profile.createIdentity(wallet.id, defaultChainId, faucetPath); - const faucetAddress = cosmosCodec.identityToAddress(faucet); + const faucetAddress = cosmWasmCodec.identityToAddress(faucet); const unsigned = await connection.withDefaultFee({ kind: "bcp/send", @@ -263,7 +263,7 @@ describe("CosmosConnection", () => { }); const nonce = await connection.getNonce({ address: faucetAddress }); // TODO: we need to use custom codecs everywhere - const codec = new CosmosCodec(defaultPrefix, defaultTokens); + const codec = new CosmWasmCodec(defaultPrefix, defaultTokens); 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/src/cosmosconnection.ts b/packages/bcp/src/cosmwasmconnection.ts similarity index 98% rename from packages/bcp/src/cosmosconnection.ts rename to packages/bcp/src/cosmwasmconnection.ts index 3c10fa6f..c5277212 100644 --- a/packages/bcp/src/cosmosconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -68,16 +68,16 @@ function buildQueryString({ return components.filter(Boolean).join("&"); } -export class CosmosConnection implements BlockchainConnection { +export class CosmWasmConnection implements BlockchainConnection { // we must know prefix and tokens a priori to understand the chain public static async establish( url: string, prefix: CosmosBech32Prefix, tokenInfo: TokenInfos, - ): Promise { + ): Promise { const restClient = new RestClient(url); const chainData = await this.initialize(restClient); - return new CosmosConnection(restClient, chainData, prefix, tokenInfo); + return new CosmWasmConnection(restClient, chainData, prefix, tokenInfo); } private static async initialize(restClient: RestClient): Promise { diff --git a/packages/bcp/src/cosmosconnector.ts b/packages/bcp/src/cosmwasmconnector.ts similarity index 54% rename from packages/bcp/src/cosmosconnector.ts rename to packages/bcp/src/cosmwasmconnector.ts index fd9c82e4..9863aa18 100644 --- a/packages/bcp/src/cosmosconnector.ts +++ b/packages/bcp/src/cosmwasmconnector.ts @@ -1,22 +1,22 @@ import { ChainConnector, ChainId } from "@iov/bcp"; import { CosmosBech32Prefix } from "./address"; -import { cosmosCodec } from "./cosmoscodec"; -import { CosmosConnection } from "./cosmosconnection"; +import { cosmWasmCodec } from "./cosmwasmcodec"; +import { CosmWasmConnection } from "./cosmwasmconnection"; import { TokenInfos } from "./types"; /** * A helper to connect to a cosmos-based chain at a given url */ -export function createCosmosConnector( +export function createCosmWasmConnector( url: string, prefix: CosmosBech32Prefix, tokenInfo: TokenInfos, expectedChainId?: ChainId, -): ChainConnector { +): ChainConnector { return { - establishConnection: async () => CosmosConnection.establish(url, prefix, tokenInfo), - codec: cosmosCodec, + establishConnection: async () => CosmWasmConnection.establish(url, prefix, tokenInfo), + codec: cosmWasmCodec, expectedChainId: expectedChainId, }; } diff --git a/packages/bcp/src/index.ts b/packages/bcp/src/index.ts index 4c607b18..91313392 100644 --- a/packages/bcp/src/index.ts +++ b/packages/bcp/src/index.ts @@ -1,3 +1,3 @@ -export { cosmosCodec, CosmosCodec } from "./cosmoscodec"; -export { CosmosConnection } from "./cosmosconnection"; -export { createCosmosConnector } from "./cosmosconnector"; +export { cosmWasmCodec, CosmWasmCodec } from "./cosmwasmcodec"; +export { CosmWasmConnection } from "./cosmwasmconnection"; +export { createCosmWasmConnector } from "./cosmwasmconnector"; diff --git a/packages/bcp/types/cosmoscodec.d.ts b/packages/bcp/types/cosmwasmcodec.d.ts similarity index 87% rename from packages/bcp/types/cosmoscodec.d.ts rename to packages/bcp/types/cosmwasmcodec.d.ts index 64de7f38..ec1253b0 100644 --- a/packages/bcp/types/cosmoscodec.d.ts +++ b/packages/bcp/types/cosmwasmcodec.d.ts @@ -12,7 +12,7 @@ import { } from "@iov/bcp"; import { CosmosBech32Prefix } from "./address"; import { TokenInfos } from "./types"; -export declare class CosmosCodec implements TxCodec { +export declare class CosmWasmCodec implements TxCodec { private readonly prefix; private readonly tokens; constructor(prefix: CosmosBech32Prefix, tokens: TokenInfos); @@ -23,4 +23,4 @@ export declare class CosmosCodec implements TxCodec { identityToAddress(identity: Identity): Address; isValidAddress(address: string): boolean; } -export declare const cosmosCodec: CosmosCodec; +export declare const cosmWasmCodec: CosmWasmCodec; diff --git a/packages/bcp/types/cosmosconnection.d.ts b/packages/bcp/types/cosmwasmconnection.d.ts similarity index 90% rename from packages/bcp/types/cosmosconnection.d.ts rename to packages/bcp/types/cosmwasmconnection.d.ts index de0cf74a..5144df67 100644 --- a/packages/bcp/types/cosmosconnection.d.ts +++ b/packages/bcp/types/cosmwasmconnection.d.ts @@ -22,8 +22,12 @@ import { import { Stream } from "xstream"; import { CosmosBech32Prefix } from "./address"; import { TokenInfos } from "./types"; -export declare class CosmosConnection implements BlockchainConnection { - static establish(url: string, prefix: CosmosBech32Prefix, tokenInfo: TokenInfos): Promise; +export declare class CosmWasmConnection implements BlockchainConnection { + static establish( + url: string, + prefix: CosmosBech32Prefix, + tokenInfo: TokenInfos, + ): Promise; private static initialize; private readonly restClient; private readonly chainData; diff --git a/packages/bcp/types/cosmosconnector.d.ts b/packages/bcp/types/cosmwasmconnector.d.ts similarity index 67% rename from packages/bcp/types/cosmosconnector.d.ts rename to packages/bcp/types/cosmwasmconnector.d.ts index 05a3d528..9e34e052 100644 --- a/packages/bcp/types/cosmosconnector.d.ts +++ b/packages/bcp/types/cosmwasmconnector.d.ts @@ -1,13 +1,13 @@ import { ChainConnector, ChainId } from "@iov/bcp"; import { CosmosBech32Prefix } from "./address"; -import { CosmosConnection } from "./cosmosconnection"; +import { CosmWasmConnection } from "./cosmwasmconnection"; import { TokenInfos } from "./types"; /** * A helper to connect to a cosmos-based chain at a given url */ -export declare function createCosmosConnector( +export declare function createCosmWasmConnector( url: string, prefix: CosmosBech32Prefix, tokenInfo: TokenInfos, expectedChainId?: ChainId, -): ChainConnector; +): ChainConnector; diff --git a/packages/bcp/types/index.d.ts b/packages/bcp/types/index.d.ts index 4c607b18..91313392 100644 --- a/packages/bcp/types/index.d.ts +++ b/packages/bcp/types/index.d.ts @@ -1,3 +1,3 @@ -export { cosmosCodec, CosmosCodec } from "./cosmoscodec"; -export { CosmosConnection } from "./cosmosconnection"; -export { createCosmosConnector } from "./cosmosconnector"; +export { cosmWasmCodec, CosmWasmCodec } from "./cosmwasmcodec"; +export { CosmWasmConnection } from "./cosmwasmconnection"; +export { createCosmWasmConnector } from "./cosmwasmconnector";