Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add calculate instantiate cost function into get contract env api #835

Merged
merged 8 commits into from
Jan 6, 2023

Conversation

loloicci
Copy link
Member

@loloicci loloicci commented Dec 16, 2022

Description

This PR makes GetContractEnv wasm API for x/wasm able to calculate instantiate cost. This function uses the input length in the calculation, so this PR adds it and arg for return as new args of the GetContractEnv.

Motivation and context

This is used for costing instantiate cost to callings of dynamic functions (Finschia/cosmwasm#257). It also works as the limit of the length of inputs of callings of dynamic functions.

How has this been tested?

This PR modifies some unit tests.

Checklist:

  • I followed the contributing guidelines and code of conduct.
  • I have added a relevant changelog to CHANGELOG.md
  • I have added tests to cover my changes.
  • I have updated the documentation accordingly.
  • I have updated API documentation client/docs/swagger-ui/swagger.yaml (not needed)

@loloicci loloicci self-assigned this Dec 16, 2022
@da1suk8
Copy link
Member

da1suk8 commented Dec 22, 2022

LGTM
If the dependencies have been updated and the test has passed, approve it.

@loloicci loloicci marked this pull request as ready for review December 26, 2022 04:01
@codecov
Copy link

codecov bot commented Dec 26, 2022

Codecov Report

Merging #835 (cd1576b) into dynamic_link (3b508ec) will increase coverage by 0.00%.
The diff coverage is 93.10%.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##           dynamic_link     #835   +/-   ##
=============================================
  Coverage         61.08%   61.08%           
=============================================
  Files               873      873           
  Lines             98602    98628   +26     
=============================================
+ Hits              60231    60249   +18     
- Misses            34767    34785   +18     
+ Partials           3604     3594   -10     
Impacted Files Coverage Δ
x/wasm/types/types.go 57.20% <ø> (ø)
x/wasm/keeper/api.go 95.34% <93.10%> (+12.99%) ⬆️
x/token/msgs.go 30.45% <0.00%> (-6.60%) ⬇️
x/token/validation.go 70.90% <0.00%> (-5.46%) ⬇️
x/foundation/msgs.go 42.78% <0.00%> (-0.49%) ⬇️
x/foundation/foundation.go 74.72% <0.00%> (-0.37%) ⬇️
x/wasm/keeper/keeper.go 86.16% <0.00%> (+0.36%) ⬆️
x/collection/msgs.go 38.51% <0.00%> (+1.11%) ⬆️

This is caused by a bug fix for the gas value for human address API in x/wasm/keeper/api.wasm.
This API is used in the hackatom contract.

correspond bug fix:
--- a/x/wasm/keeper/api.go
+++ b/x/wasm/keeper/api.go
@@ -27,7 +26,8 @@ var (
 )

 func (a cosmwasmAPIImpl) humanAddress(canon []byte) (string, uint64, error) {
-       gas := a.gasMultiplier.FromWasmVMGas(5)
+       gasMultiplier := a.keeper.getGasMultiplier(*a.ctx)
+       gas := gasMultiplier.ToWasmVMGas(5)
        if err := sdk.VerifyAddressFormat(canon); err != nil {
                return "", gas, err
        }
Copy link
Contributor

@shiki-tak shiki-tak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants