Remove default codec

This commit is contained in:
Simon Warta 2020-02-10 17:59:17 +01:00
parent 97363cd404
commit 69c57c9758
3 changed files with 19 additions and 35 deletions

View File

@ -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);

View File

@ -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<SendTransaction>({
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<SendTransaction>({
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);

View File

@ -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;