Skip to content

Commit

Permalink
fix incorrect re-throw
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiruse committed Dec 23, 2022
1 parent 4df8852 commit f2943b2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@terran-one/cw-simulate",
"version": "2.8.1-rc.1",
"version": "2.8.1-rc.2",
"description": "Mock blockchain environment for simulating CosmWasm interactions",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/CWSimulateApp.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { QuerierBase } from '@terran-one/cosmwasm-vm-js';
import { Err, Ok, Result } from 'ts-results';
import { Err, Result } from 'ts-results';
import { WasmModule, WasmQuery } from './modules/wasm';
import { BankModule, BankQuery } from './modules/bank';
import { fromImmutable, toImmutable, Transactional, TransactionalLens } from './store/transactional';
import { Transactional, TransactionalLens } from './store/transactional';
import { AppResponse, Binary } from './types';

export interface CWSimulateAppOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/wasm/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class Contract {
instantiateMsg: any,
logs: DebugLog[]
): Result<ContractResponse, string> {
if (!this._vm) throw new Error(`No VM for contract ${this.address}`);
if (!this._vm) throw new NoVMError(this.address);
const vm = this._vm;
const env = this.getExecutionEnv();
const info = { sender, funds };
Expand All @@ -72,7 +72,7 @@ export default class Contract {
): Result<ContractResponse, string>
{
const vm = this._vm;
if (!vm) throw new Error(`No VM for contract ${this.address}`);
if (!vm) throw new NoVMError(this.address);
vm.resetDebugInfo();

const env = this.getExecutionEnv();
Expand Down
6 changes: 3 additions & 3 deletions src/store/transactional.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isCollection, isList, isMap, List, Map } from "immutable";
import { Ok, Result } from "ts-results";
import { isArrayLike } from "../util";
import { Err, Ok, Result } from "ts-results";
import { fromRustResult, isArrayLike, isRustResult, isTSResult } from "../util";

// NEVER_IMMUTIFY is a string because that's easily serializable with different algorithms - symbols are not
export type NeverImmutify = typeof NEVER_IMMUTIFY;
Expand Down Expand Up @@ -66,7 +66,7 @@ export class Transactional {
})
.catch(reason => {
this._data = snapshot;
return reason;
throw reason;
})
}
else {
Expand Down
3 changes: 3 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ export function toRustResult<T>(res: Result<T, string>): RustResult<T> {
return { error: res.val }
}
}

export const isRustResult = <T = unknown>(value: any): value is RustResult<T> => 'ok' in value || 'err' in value;
export const isTSResult = <T = unknown, E = string>(value: any): value is Result<T, E> => typeof value.ok === 'boolean' && typeof value.err === 'boolean' && 'val' in value;

0 comments on commit f2943b2

Please sign in to comment.