Skip to content

Commit

Permalink
Merge branch 'main' of github.com:weiroll/weiroll.js into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachnid committed Jun 18, 2021
2 parents d1a0c03 + b01216f commit 1d3cc59
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@weiroll/weiroll.js",
"version": "0.1.1",
"version": "0.2.0",
"description": "The weiroll planner in JS",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/planner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function abiEncodeSingle(param: ParamType, value: any): LiteralValue {

function buildCall(contract: Contract, fragment: FunctionFragment): ContractFunction {
return function(...args: Array<any>): 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)) {
Expand Down
5 changes: 5 additions & 0 deletions tests/test_planner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
});

0 comments on commit 1d3cc59

Please sign in to comment.