Skip to content

Commit f2943b2

Browse files
committed
fix incorrect re-throw
1 parent 4df8852 commit f2943b2

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@terran-one/cw-simulate",
3-
"version": "2.8.1-rc.1",
3+
"version": "2.8.1-rc.2",
44
"description": "Mock blockchain environment for simulating CosmWasm interactions",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

src/CWSimulateApp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { QuerierBase } from '@terran-one/cosmwasm-vm-js';
2-
import { Err, Ok, Result } from 'ts-results';
2+
import { Err, Result } from 'ts-results';
33
import { WasmModule, WasmQuery } from './modules/wasm';
44
import { BankModule, BankQuery } from './modules/bank';
5-
import { fromImmutable, toImmutable, Transactional, TransactionalLens } from './store/transactional';
5+
import { Transactional, TransactionalLens } from './store/transactional';
66
import { AppResponse, Binary } from './types';
77

88
export interface CWSimulateAppOptions {

src/modules/wasm/contract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class Contract {
5050
instantiateMsg: any,
5151
logs: DebugLog[]
5252
): Result<ContractResponse, string> {
53-
if (!this._vm) throw new Error(`No VM for contract ${this.address}`);
53+
if (!this._vm) throw new NoVMError(this.address);
5454
const vm = this._vm;
5555
const env = this.getExecutionEnv();
5656
const info = { sender, funds };
@@ -72,7 +72,7 @@ export default class Contract {
7272
): Result<ContractResponse, string>
7373
{
7474
const vm = this._vm;
75-
if (!vm) throw new Error(`No VM for contract ${this.address}`);
75+
if (!vm) throw new NoVMError(this.address);
7676
vm.resetDebugInfo();
7777

7878
const env = this.getExecutionEnv();

src/store/transactional.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isCollection, isList, isMap, List, Map } from "immutable";
2-
import { Ok, Result } from "ts-results";
3-
import { isArrayLike } from "../util";
2+
import { Err, Ok, Result } from "ts-results";
3+
import { fromRustResult, isArrayLike, isRustResult, isTSResult } from "../util";
44

55
// NEVER_IMMUTIFY is a string because that's easily serializable with different algorithms - symbols are not
66
export type NeverImmutify = typeof NEVER_IMMUTIFY;
@@ -66,7 +66,7 @@ export class Transactional {
6666
})
6767
.catch(reason => {
6868
this._data = snapshot;
69-
return reason;
69+
throw reason;
7070
})
7171
}
7272
else {

src/util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ export function toRustResult<T>(res: Result<T, string>): RustResult<T> {
2626
return { error: res.val }
2727
}
2828
}
29+
30+
export const isRustResult = <T = unknown>(value: any): value is RustResult<T> => 'ok' in value || 'err' in value;
31+
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 commit comments

Comments
 (0)