diff --git a/package.json b/package.json index 813b25e..90f1301 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@weiroll/weiroll.js", - "version": "0.1.0", + "version": "0.2.0", "description": "The weiroll planner in JS", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index e035436..5da8d38 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,10 +6,7 @@ export { ContractFunction, FunctionCall, Value, - StaticValue, - ReturnValue -} from './contract'; - -export { + LiteralValue, + ReturnValue, Planner } from './planner'; \ No newline at end of file diff --git a/src/planner.ts b/src/planner.ts index 10b68df..c87c2de 100644 --- a/src/planner.ts +++ b/src/planner.ts @@ -53,6 +53,9 @@ function abiEncodeSingle(param: ParamType, value: any): LiteralValue { function buildCall(contract: Contract, fragment: FunctionFragment): ContractFunction { return function(...args: Array): FunctionCall { + if(args.length != fragment.inputs.length) { + throw new Error(`Function ${fragment.name} has ${fragment.inputs.length} arguments but ${args.length} provided`); + } const encodedArgs = args.map((arg, idx) => { const param = fragment.inputs[idx]; if(isReturnValue(arg)) { diff --git a/tests/test_planner.ts b/tests/test_planner.ts index 5d5cef3..e62fa41 100644 --- a/tests/test_planner.ts +++ b/tests/test_planner.ts @@ -148,4 +148,9 @@ describe('Planner', () => { expect(state[0]).to.equal(hexDataSlice(defaultAbiCoder.encode(['string'], ["Hello, "]), 32)); expect(state[1]).to.equal(hexDataSlice(defaultAbiCoder.encode(['string'], ["world!"]), 32)); }); + + it('requires argument counts to match the function definition', () => { + const planner = new Planner(); + expect(() => planner.addCommand(Math.add(1))).to.throw(); + }) }); diff --git a/tsconfig.json b/tsconfig.json index 694d472..21979fc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "outDir": "./dist/", "sourceMap": true, "noImplicitAny": true, - "module": "es6", + "module": "commonjs", "target": "es5", "jsx": "react", "allowJs": true,