From 59e3314d7482fbc45c228d760fab4a4bbcbd61b6 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 16 Aug 2023 15:35:04 -0400 Subject: [PATCH] chore: address PR feedback --- package.json | 2 +- src/contract_spec.ts | 5 ++--- src/index.ts | 2 +- test/unit/contract_spec.ts | 17 ++++++++++++++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 191e21c3..221caf5b 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "build:prod": "cross-env NODE_ENV=production yarn _build", "build:node": "yarn _babel && yarn build:ts", "build:ts": "tsc -p ./tsconfig.json", - "build:test": "yarn tsc -p ./test/tsconfig.json", + "build:test": "tsc -p ./test/tsconfig.json", "build:browser": "webpack -c ./webpack.config.browser.js", "build:docs": "cross-env NODE_ENV=docs yarn _babel", "clean": "rm -rf lib/ dist/ coverage/ .nyc_output/ jsdoc/", diff --git a/src/contract_spec.ts b/src/contract_spec.ts index ac5d9244..5548b4d1 100644 --- a/src/contract_spec.ts +++ b/src/contract_spec.ts @@ -28,8 +28,7 @@ import { ScIntType, XdrLargeInt, xdr } from "stellar-base"; import { Address } from "stellar-base"; import { Contract } from "stellar-base"; -//@ts-ignore Does exist -import { ScInt, scValToBigInt } from "stellar-base"; +import { scValToBigInt } from "stellar-base"; export interface Union { tag: string; @@ -664,7 +663,7 @@ function stringToScVal(str: string, ty: xdr.ScSpecType): xdr.ScVal { default: throw new TypeError( - `invalid type (${ty.name}) specified for string value` + `invalid type ${ty.name} specified for string value` ); } } diff --git a/src/index.ts b/src/index.ts index 1ea94203..48d6f096 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ const version = require("../package.json").version; // Expose all types export * from "./soroban_rpc"; -export * from "./contract_spec"; +export { ContractSpec } from "./contract_spec"; // stellar-sdk classes to expose export { Server } from "./server"; diff --git a/test/unit/contract_spec.ts b/test/unit/contract_spec.ts index 42be72c6..02a12111 100644 --- a/test/unit/contract_spec.ts +++ b/test/unit/contract_spec.ts @@ -5,9 +5,17 @@ import { expect } from "chai"; const publicKey = "GCBVOLOM32I7OD5TWZQCIXCXML3TK56MDY7ZMTAILIBQHHKPCVU42XYW"; const addr = Address.fromString(publicKey); +let SPEC: ContractSpec; -describe("Can parse base64 entries", function () { - const SPEC = new ContractSpec(spec); +before(() => { + SPEC = new ContractSpec(spec); +}) + +it("throws if no entries", () => { + expect(() => new ContractSpec([])).to.throw(/Contract spec must have at least one entry/i); +}); + +describe("Can round trip custom types", function () { function getResultType(funcName: string): xdr.ScSpecTypeDef { let fn = SPEC.findEntry(funcName).value(); @@ -142,8 +150,10 @@ describe("Can parse base64 entries", function () { const map = new Map(); map.set(1, true); map.set(2, false); - // map.set(3, 'hahaha') // should throw an error roundtrip("map", map); + + map.set(3, "hahaha") + expect(() => roundtrip("map", map)).to.throw(/invalid type scSpecTypeBool specified for string value/i); }); it("vec", () => { @@ -163,6 +173,7 @@ describe("Can parse base64 entries", function () { it("u256", () => { roundtrip("u256", 1n); + expect(() =>roundtrip("u256", -1n)).to.throw(/expected a positive value, got: -1/i) }); it("i256", () => {