Skip to content

Commit

Permalink
fix view function response (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored Mar 21, 2024
1 parent 502c395 commit d6fddfa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func (vm *VM) ExecuteViewFunction(
env types.Env,
gasLimit uint64,
payload types.ViewFunction,
) (string, error) {
) (types.ViewOutput, error) {
envBz, err := env.BcsSerialize()
if err != nil {
return "", err
return types.ViewOutput{}, err
}

bz, err := payload.BcsSerialize()
if err != nil {
return "", err
return types.ViewOutput{}, err
}

res, err := api.ExecuteViewFunction(
Expand All @@ -86,10 +86,10 @@ func (vm *VM) ExecuteViewFunction(
bz,
)
if err != nil {
return "", err
return types.ViewOutput{}, err
}

return types.DeserializeString(res)
return types.BcsDeserializeViewOutput(res)
}

// Execute calls a given contract.
Expand Down
4 changes: 2 additions & 2 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func Test_QueryContract(t *testing.T) {
payload,
)
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("\"%d\"", mintAmount), res)
require.Equal(t, fmt.Sprintf("\"%d\"", mintAmount), res.Ret)
}

func Test_DecodeResource(t *testing.T) {
Expand Down Expand Up @@ -590,5 +590,5 @@ func Test_OracleAPI(t *testing.T) {
payload,
)
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("[\"%d\",\"%d\",\"%d\"]", price, updatedAt, decimals), res)
require.Equal(t, fmt.Sprintf("[\"%d\",\"%d\",\"%d\"]", price, updatedAt, decimals), res.Ret)
}

0 comments on commit d6fddfa

Please sign in to comment.