Skip to content

Commit

Permalink
chore: address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Aug 16, 2023
1 parent 3a38c42 commit 59e3314
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
5 changes: 2 additions & 3 deletions src/contract_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
tag: string;
Expand Down Expand Up @@ -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`
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
17 changes: 14 additions & 3 deletions test/unit/contract_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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", () => {
Expand All @@ -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", () => {
Expand Down

0 comments on commit 59e3314

Please sign in to comment.