diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index 16162e1004c..e7998168f6c 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -240,6 +240,9 @@ func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error) { if cx.Varg { panic("variadic calls not yet supported") } + if len(msg.Args) != len(ft.Params) { + panic(fmt.Sprintf("wrong number of arguments in call to %s: want %d got %d", fnc, len(ft.Params), len(msg.Args))) + } for i, arg := range msg.Args { argType := ft.Params[i].Type atv := convertArgToGno(arg, argType) diff --git a/gno.land/pkg/sdk/vm/keeper_test.go b/gno.land/pkg/sdk/vm/keeper_test.go index 294efa66fa5..bc6bc285704 100644 --- a/gno.land/pkg/sdk/vm/keeper_test.go +++ b/gno.land/pkg/sdk/vm/keeper_test.go @@ -395,3 +395,44 @@ func main() { expectedString := fmt.Sprintf("hello world! %s\n", addr.String()) assert.Equal(t, res, expectedString) } + +func TestNumberOfArgsError(t *testing.T) { + env := setupTestEnv() + ctx := env.ctx + + // Give "addr1" some gnots. + addr := crypto.AddressFromPreimage([]byte("addr1")) + acc := env.acck.NewAccountWithAddress(ctx, addr) + env.acck.SetAccount(ctx, acc) + env.bank.SetCoins(ctx, addr, std.MustParseCoins("10000000ugnot")) + assert.True(t, env.bank.GetCoins(ctx, addr).IsEqual(std.MustParseCoins("10000000ugnot"))) + + // Create test package. + files := []*std.MemFile{ + { + Name: "test.gno", + Body: `package test + +import "std" + +func Echo(msg string) string { + return "echo:"+msg +}`, + }, + } + pkgPath := "gno.land/r/test" + msg1 := NewMsgAddPackage(addr, pkgPath, files) + err := env.vmk.AddPackage(ctx, msg1) + assert.NoError(t, err) + + // Call Echo function with wrong number of arguments + coins := std.MustParseCoins("1ugnot") + msg2 := NewMsgCall(addr, coins, pkgPath, "Echo", []string{"hello world", "extra arg"}) + assert.PanicsWithValue( + t, + func() { + env.vmk.Call(ctx, msg2) + }, + "wrong number of arguments in call to Echo: want 1 got 2", + ) +}