throw error on failed post, plus format and lint

This commit is contained in:
Ethan Frey 2020-01-23 14:36:36 +01:00
parent 7440bfb6f1
commit 870d9acb66
9 changed files with 14 additions and 17 deletions

View File

@ -24,6 +24,7 @@
"docs": "shx rm -rf docs && typedoc --options typedoc.js", "docs": "shx rm -rf docs && typedoc --options typedoc.js",
"format": "prettier --write --loglevel warn \"./src/**/*.ts\"", "format": "prettier --write --loglevel warn \"./src/**/*.ts\"",
"lint": "eslint --max-warnings 0 \"**/*.{js,ts}\" && tslint -t verbose --project .", "lint": "eslint --max-warnings 0 \"**/*.{js,ts}\" && tslint -t verbose --project .",
"autolint": "eslint --max-warnings 0 \"**/*.{js,ts}\" --fix",
"move-types": "shx rm -rf ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", "move-types": "shx rm -rf ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts",
"format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"",
"build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types",

View File

@ -18,7 +18,7 @@ import { Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding"; import { Encoding } from "@iov/encoding";
import { marshalTx, unmarshalTx } from "@tendermint/amino-js"; import { marshalTx, unmarshalTx } from "@tendermint/amino-js";
import { isValidAddress, pubkeyToAddress, CosmosBech32Prefix } from "./address"; import { CosmosBech32Prefix, isValidAddress, pubkeyToAddress } from "./address";
import { Caip5 } from "./caip5"; import { Caip5 } from "./caip5";
import { parseTx } from "./decode"; import { parseTx } from "./decode";
import { buildSignedTx, buildUnsignedTx } from "./encode"; import { buildSignedTx, buildUnsignedTx } from "./encode";

View File

@ -14,9 +14,9 @@ import { Secp256k1 } from "@iov/crypto";
import { Encoding } from "@iov/encoding"; import { Encoding } from "@iov/encoding";
import { HdPaths, Secp256k1HdWallet, UserProfile } from "@iov/keycontrol"; import { HdPaths, Secp256k1HdWallet, UserProfile } from "@iov/keycontrol";
import { cosmosCodec, CosmosCodec } from "./cosmoscodec";
import { CosmosConnection } from "./cosmosconnection";
import { CosmosBech32Prefix } from "./address"; import { CosmosBech32Prefix } from "./address";
import { CosmosCodec, cosmosCodec } from "./cosmoscodec";
import { CosmosConnection } from "./cosmosconnection";
import { TokenInfos } from "./types"; import { TokenInfos } from "./types";
const { fromBase64, toHex } = Encoding; const { fromBase64, toHex } = Encoding;
@ -197,11 +197,9 @@ describe("CosmosConnection", () => {
const nonce = await connection.getNonce({ address: faucetAddress }); const nonce = await connection.getNonce({ address: faucetAddress });
// TODO: we need to use custom codecs everywhere // TODO: we need to use custom codecs everywhere
const codec = new CosmosCodec(defaultPrefix, defaultTokens); const codec = new CosmosCodec(defaultPrefix, defaultTokens);
console.log("nonce:", nonce);
const signed = await profile.signTransaction(faucet, unsigned, codec, nonce); const signed = await profile.signTransaction(faucet, unsigned, codec, nonce);
const postableBytes = codec.bytesToPost(signed); const postableBytes = codec.bytesToPost(signed);
const response = await connection.postTx(postableBytes); const response = await connection.postTx(postableBytes);
console.log(response);
const { transactionId } = response; const { transactionId } = response;
const blockInfo = await response.blockInfo.waitFor(info => !isBlockInfoPending(info)); const blockInfo = await response.blockInfo.waitFor(info => !isBlockInfoPending(info));
expect(blockInfo.state).toEqual(TransactionState.Succeeded); expect(blockInfo.state).toEqual(TransactionState.Succeeded);
@ -263,7 +261,6 @@ describe("CosmosConnection", () => {
const signed = await profile.signTransaction(faucet, unsigned, codec, nonce); const signed = await profile.signTransaction(faucet, unsigned, codec, nonce);
const postableBytes = codec.bytesToPost(signed); const postableBytes = codec.bytesToPost(signed);
const response = await connection.postTx(postableBytes); const response = await connection.postTx(postableBytes);
console.log(response);
const { transactionId } = response; const { transactionId } = response;
const blockInfo = await response.blockInfo.waitFor(info => !isBlockInfoPending(info)); const blockInfo = await response.blockInfo.waitFor(info => !isBlockInfoPending(info));
expect(blockInfo.state).toEqual(TransactionState.Succeeded); expect(blockInfo.state).toEqual(TransactionState.Succeeded);

View File

@ -213,8 +213,10 @@ export class CosmosConnection implements BlockchainConnection {
} }
public async postTx(tx: PostableBytes): Promise<PostTxResponse> { public async postTx(tx: PostableBytes): Promise<PostTxResponse> {
// TODO: we need to check errors here... bad chain-id breaks this const { code, txhash, raw_log } = await this.restClient.postTx(tx);
const { txhash, raw_log } = await this.restClient.postTx(tx); if (code !== 0) {
throw new Error(raw_log);
}
const transactionId = txhash as TransactionId; const transactionId = txhash as TransactionId;
const firstEvent: BlockInfo = { state: TransactionState.Pending }; const firstEvent: BlockInfo = { state: TransactionState.Pending };
let blockInfoInterval: NodeJS.Timeout; let blockInfoInterval: NodeJS.Timeout;

View File

@ -1,8 +1,8 @@
import { ChainConnector, ChainId } from "@iov/bcp"; import { ChainConnector, ChainId } from "@iov/bcp";
import { CosmosBech32Prefix } from "./address";
import { cosmosCodec } from "./cosmoscodec"; import { cosmosCodec } from "./cosmoscodec";
import { CosmosConnection } from "./cosmosconnection"; import { CosmosConnection } from "./cosmosconnection";
import { CosmosBech32Prefix } from "./address";
import { TokenInfos } from "./types"; import { TokenInfos } from "./types";
/** /**

View File

@ -12,7 +12,6 @@ import {
SendTransaction, SendTransaction,
SignatureBytes, SignatureBytes,
SignedTransaction, SignedTransaction,
TokenTicker,
TransactionId, TransactionId,
UnsignedTransaction, UnsignedTransaction,
} from "@iov/bcp"; } from "@iov/bcp";
@ -20,12 +19,10 @@ import { Encoding } from "@iov/encoding";
import amino from "@tendermint/amino-js"; import amino from "@tendermint/amino-js";
import { TxsResponse } from "./restclient"; import { TxsResponse } from "./restclient";
import { isAminoStdTx, TokenInfos, coinToAmount } from "./types"; import { coinToAmount, isAminoStdTx, TokenInfos } from "./types";
const { fromBase64 } = Encoding; const { fromBase64 } = Encoding;
const atom = "ATOM" as TokenTicker;
export function decodePubkey(pubkey: amino.PubKey): PubkeyBundle { export function decodePubkey(pubkey: amino.PubKey): PubkeyBundle {
return { return {
algo: Algorithm.Secp256k1, algo: Algorithm.Secp256k1,

View File

@ -13,7 +13,7 @@ import { Secp256k1 } from "@iov/crypto";
import { Encoding } from "@iov/encoding"; import { Encoding } from "@iov/encoding";
import amino from "@tendermint/amino-js"; import amino from "@tendermint/amino-js";
import { AminoTx, TokenInfos, amountToCoin } from "./types"; import { AminoTx, amountToCoin, TokenInfos } from "./types";
const { toBase64 } = Encoding; const { toBase64 } = Encoding;

View File

@ -27,10 +27,10 @@ export declare class CosmosConnection implements BlockchainConnection {
private static initialize; private static initialize;
private readonly restClient; private readonly restClient;
private readonly chainData; private readonly chainData;
private readonly primaryToken;
private readonly supportedTokens;
private readonly _prefix; private readonly _prefix;
private readonly tokenInfo; private readonly tokenInfo;
private readonly primaryToken;
private readonly supportedTokens;
private get prefix(); private get prefix();
private constructor(); private constructor();
disconnect(): void; disconnect(): void;

View File

@ -1,6 +1,6 @@
import { ChainConnector, ChainId } from "@iov/bcp"; import { ChainConnector, ChainId } from "@iov/bcp";
import { CosmosConnection } from "./cosmosconnection";
import { CosmosBech32Prefix } from "./address"; import { CosmosBech32Prefix } from "./address";
import { CosmosConnection } from "./cosmosconnection";
import { TokenInfos } from "./types"; import { TokenInfos } from "./types";
/** /**
* A helper to connect to a cosmos-based chain at a given url * A helper to connect to a cosmos-based chain at a given url