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 the instantiate_permission in the CodeInfoResponse #395

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* (x/upgrade) [\#377] (https://github.com/line/lbm-sdk/pull/377) To smoothen the update to the latest stable release, the SDK includes vesion map for managing migrations between SDK versions.
* (x/wasm) [\#358] (https://github.com/line/lbm-sdk/pull/358) change wasm metrics method to using prometheus directly
* (x/feegrant) [\#380] (https://github.com/line/lbm-sdk/pull/380) Feegrant module
* (x/wasm) [\#395] (https://github.com/line/lbm-sdk/pull/395) Add the instantiate_permission in the CodeInfoResponse

### Improvements
* (slashing) [\#347](https://github.com/line/lbm-sdk/pull/347) Introduce VoterSetCounter
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31011,6 +31011,27 @@ paths:
type: string
builder:
type: string
instantiate_permission:
type: object
properties:
permission:
type: string
enum:
- ACCESS_TYPE_UNSPECIFIED
- ACCESS_TYPE_NOBODY
- ACCESS_TYPE_ONLY_ADDRESS
- ACCESS_TYPE_EVERYBODY
default: ACCESS_TYPE_UNSPECIFIED
description: >-
- ACCESS_TYPE_UNSPECIFIED: AccessTypeUnspecified
placeholder for empty value
- ACCESS_TYPE_NOBODY: AccessTypeNobody forbidden
- ACCESS_TYPE_ONLY_ADDRESS: AccessTypeOnlyAddress restricted to an address
- ACCESS_TYPE_EVERYBODY: AccessTypeEverybody unrestricted
title: AccessType permission types
address:
type: string
description: AccessConfig access control type.
title: CodeInfoResponse contains code meta data from CodeInfo
pagination:
description: pagination defines the pagination in the response.
Expand Down Expand Up @@ -31297,6 +31318,27 @@ paths:
type: string
builder:
type: string
instantiate_permission:
type: object
properties:
permission:
type: string
enum:
- ACCESS_TYPE_UNSPECIFIED
- ACCESS_TYPE_NOBODY
- ACCESS_TYPE_ONLY_ADDRESS
- ACCESS_TYPE_EVERYBODY
default: ACCESS_TYPE_UNSPECIFIED
description: >-
- ACCESS_TYPE_UNSPECIFIED: AccessTypeUnspecified
placeholder for empty value
- ACCESS_TYPE_NOBODY: AccessTypeNobody forbidden
- ACCESS_TYPE_ONLY_ADDRESS: AccessTypeOnlyAddress restricted to an address
- ACCESS_TYPE_EVERYBODY: AccessTypeEverybody unrestricted
title: AccessType permission types
address:
type: string
description: AccessConfig access control type.
title: CodeInfoResponse contains code meta data from CodeInfo
data:
type: string
Expand Down Expand Up @@ -53733,6 +53775,42 @@ definitions:
description: |-
AbsoluteTxPosition is a unique transaction position that allows for global
ordering of transactions.
lbm.wasm.v1.AccessConfig:
type: object
properties:
permission:
type: string
enum:
- ACCESS_TYPE_UNSPECIFIED
- ACCESS_TYPE_NOBODY
- ACCESS_TYPE_ONLY_ADDRESS
- ACCESS_TYPE_EVERYBODY
default: ACCESS_TYPE_UNSPECIFIED
description: >-
- ACCESS_TYPE_UNSPECIFIED: AccessTypeUnspecified placeholder for empty
value
- ACCESS_TYPE_NOBODY: AccessTypeNobody forbidden
- ACCESS_TYPE_ONLY_ADDRESS: AccessTypeOnlyAddress restricted to an address
- ACCESS_TYPE_EVERYBODY: AccessTypeEverybody unrestricted
title: AccessType permission types
address:
type: string
description: AccessConfig access control type.
lbm.wasm.v1.AccessType:
type: string
enum:
- ACCESS_TYPE_UNSPECIFIED
- ACCESS_TYPE_NOBODY
- ACCESS_TYPE_ONLY_ADDRESS
- ACCESS_TYPE_EVERYBODY
default: ACCESS_TYPE_UNSPECIFIED
description: >-
- ACCESS_TYPE_UNSPECIFIED: AccessTypeUnspecified placeholder for empty
value
- ACCESS_TYPE_NOBODY: AccessTypeNobody forbidden
- ACCESS_TYPE_ONLY_ADDRESS: AccessTypeOnlyAddress restricted to an address
- ACCESS_TYPE_EVERYBODY: AccessTypeEverybody unrestricted
title: AccessType permission types
lbm.wasm.v1.CodeInfoResponse:
type: object
properties:
Expand All @@ -53748,6 +53826,27 @@ definitions:
type: string
builder:
type: string
instantiate_permission:
type: object
properties:
permission:
type: string
enum:
- ACCESS_TYPE_UNSPECIFIED
- ACCESS_TYPE_NOBODY
- ACCESS_TYPE_ONLY_ADDRESS
- ACCESS_TYPE_EVERYBODY
default: ACCESS_TYPE_UNSPECIFIED
description: >-
- ACCESS_TYPE_UNSPECIFIED: AccessTypeUnspecified placeholder for
empty value
- ACCESS_TYPE_NOBODY: AccessTypeNobody forbidden
- ACCESS_TYPE_ONLY_ADDRESS: AccessTypeOnlyAddress restricted to an address
- ACCESS_TYPE_EVERYBODY: AccessTypeEverybody unrestricted
title: AccessType permission types
address:
type: string
description: AccessConfig access control type.
title: CodeInfoResponse contains code meta data from CodeInfo
lbm.wasm.v1.ContractCodeHistoryEntry:
type: object
Expand Down Expand Up @@ -54104,6 +54203,27 @@ definitions:
type: string
builder:
type: string
instantiate_permission:
type: object
properties:
permission:
type: string
enum:
- ACCESS_TYPE_UNSPECIFIED
- ACCESS_TYPE_NOBODY
- ACCESS_TYPE_ONLY_ADDRESS
- ACCESS_TYPE_EVERYBODY
default: ACCESS_TYPE_UNSPECIFIED
description: >-
- ACCESS_TYPE_UNSPECIFIED: AccessTypeUnspecified placeholder
for empty value
- ACCESS_TYPE_NOBODY: AccessTypeNobody forbidden
- ACCESS_TYPE_ONLY_ADDRESS: AccessTypeOnlyAddress restricted to an address
- ACCESS_TYPE_EVERYBODY: AccessTypeEverybody unrestricted
title: AccessType permission types
address:
type: string
description: AccessConfig access control type.
title: CodeInfoResponse contains code meta data from CodeInfo
data:
type: string
Expand All @@ -54129,6 +54249,27 @@ definitions:
type: string
builder:
type: string
instantiate_permission:
type: object
properties:
permission:
type: string
enum:
- ACCESS_TYPE_UNSPECIFIED
- ACCESS_TYPE_NOBODY
- ACCESS_TYPE_ONLY_ADDRESS
- ACCESS_TYPE_EVERYBODY
default: ACCESS_TYPE_UNSPECIFIED
description: >-
- ACCESS_TYPE_UNSPECIFIED: AccessTypeUnspecified placeholder
for empty value
- ACCESS_TYPE_NOBODY: AccessTypeNobody forbidden
- ACCESS_TYPE_ONLY_ADDRESS: AccessTypeOnlyAddress restricted to an address
- ACCESS_TYPE_EVERYBODY: AccessTypeEverybody unrestricted
title: AccessType permission types
address:
type: string
description: AccessConfig access control type.
title: CodeInfoResponse contains code meta data from CodeInfo
pagination:
description: pagination defines the pagination in the response.
Expand Down
1 change: 1 addition & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -11414,6 +11414,7 @@ CodeInfoResponse contains code meta data from CodeInfo
| `data_hash` | [bytes](#bytes) | | |
| `source` | [string](#string) | | |
| `builder` | [string](#string) | | |
| `instantiate_permission` | [AccessConfig](#lbm.wasm.v1.AccessConfig) | | |



Expand Down
11 changes: 6 additions & 5 deletions proto/lbm/wasm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ message QueryCodeRequest {
message CodeInfoResponse {
option (gogoproto.equal) = true;

uint64 code_id = 1 [(gogoproto.customname) = "CodeID",
uint64 code_id = 1 [(gogoproto.customname) = "CodeID",
(gogoproto.jsontag) = "id"]; // id for legacy support
string creator = 2;
bytes data_hash = 3 [(gogoproto.casttype) = "github.com/line/ostracon/libs/bytes.HexBytes"];
string source = 4;
string builder = 5;
string creator = 2;
bytes data_hash = 3 [(gogoproto.casttype) = "github.com/line/ostracon/libs/bytes.HexBytes"];
string source = 4;
string builder = 5;
AccessConfig instantiate_permission = 6 [(gogoproto.nullable) = false];
}

// QueryCodeResponse is the response type for the Query/Code RPC method
Expand Down
11 changes: 6 additions & 5 deletions x/wasm/keeper/legacy_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ func queryCodeList(ctx sdk.Context, keeper types.ViewKeeper) ([]types.CodeInfoRe
var info []types.CodeInfoResponse
keeper.IterateCodeInfos(ctx, func(i uint64, res types.CodeInfo) bool {
info = append(info, types.CodeInfoResponse{
CodeID: i,
Creator: res.Creator,
DataHash: res.CodeHash,
Source: res.Source,
Builder: res.Builder,
CodeID: i,
Creator: res.Creator,
DataHash: res.CodeHash,
Source: res.Source,
Builder: res.Builder,
InstantiatePermission: res.InstantiateConfig,
})
return false
})
Expand Down
1 change: 1 addition & 0 deletions x/wasm/keeper/legacy_querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ func TestLegacyQueryCodeList(t *testing.T) {
require.Len(t, got, len(spec.codeIDs))
for i, exp := range spec.codeIDs {
assert.EqualValues(t, exp, got[i]["id"])
assert.NotNil(t, got[i]["instantiate_permission"])
}
})
}
Expand Down
22 changes: 12 additions & 10 deletions x/wasm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,12 @@ func (q GrpcQuerier) Codes(c context.Context, req *types.QueryCodesRequest) (*ty
return false, err
}
r = append(r, types.CodeInfoResponse{
CodeID: binary.BigEndian.Uint64(key),
Creator: c.Creator,
DataHash: c.CodeHash,
Source: c.Source,
Builder: c.Builder,
CodeID: binary.BigEndian.Uint64(key),
Creator: c.Creator,
DataHash: c.CodeHash,
Source: c.Source,
Builder: c.Builder,
InstantiatePermission: c.InstantiateConfig,
})
}
return true, nil
Expand Down Expand Up @@ -272,11 +273,12 @@ func queryCode(ctx sdk.Context, codeID uint64, keeper types.ViewKeeper) (*types.
return nil, nil
}
info := types.CodeInfoResponse{
CodeID: codeID,
Creator: res.Creator,
DataHash: res.CodeHash,
Source: res.Source,
Builder: res.Builder,
CodeID: codeID,
Creator: res.Creator,
DataHash: res.CodeHash,
Source: res.Source,
Builder: res.Builder,
InstantiatePermission: res.InstantiateConfig,
}

code, err := keeper.GetByteCode(ctx, codeID)
Expand Down
55 changes: 55 additions & 0 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"io/ioutil"
"testing"
"time"
Expand Down Expand Up @@ -448,6 +450,59 @@ func TestQueryContractHistory(t *testing.T) {
}
}

func TestQueryCode(t *testing.T) {
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil)
keeper := keepers.WasmKeeper

codeID := uint64(1)
require.NoError(t, keeper.importCode(ctx, codeID,
types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)), wasmCode))

specs := map[string]struct {
req *types.QueryCodeRequest
expErr error
}{
"req nil": {
req: nil,
expErr: status.Error(codes.InvalidArgument, "empty request"),
},
"req.CodeId=0": {
req: &types.QueryCodeRequest{CodeId: 0},
expErr: sdkErrors.Wrap(types.ErrInvalid, "code id"),
},
"not exist codeID": {
req: &types.QueryCodeRequest{CodeId: 2},
expErr: types.ErrNotFound,
},
"code codeID": {
req: &types.QueryCodeRequest{CodeId: 1},
expErr: nil,
},
}

for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
xCtx, _ := ctx.CacheContext()

q := Querier(keeper)
got, err := q.Code(sdk.WrapSDKContext(xCtx), spec.req)
if spec.expErr != nil {
assert.Nil(t, got)
assert.NotNil(t, err)
assert.EqualError(t, err, spec.expErr.Error())
} else {
assert.Nil(t, err)
assert.NotNil(t, got)
assert.EqualValues(t, got.CodeID, codeID)
assert.NotNil(t, got.InstantiatePermission)
}
})
}
}

func TestQueryCodeList(t *testing.T) {
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)
Expand Down
Loading