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

fix: cherry-pick fill ContractHistory querier result's Updated field (#62) #85

Merged
merged 2 commits into from
Aug 18, 2023
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 @@
* [\#81](https://github.com/Finschia/wasmd/pull/81) Apply Finschia/finschia-sdk#1063

### Bug Fixes
* [\#85](https://github.com/Finschia/wasmd/pull/85) cherry-pick fill ContractHistory querier result's Updated field (#62)
* [\#52](https://github.com/Finschia/wasmd/pull/52) fix cli_test error of wasmplus and add cli_test ci

### Breaking Changes
Expand Down
4 changes: 3 additions & 1 deletion x/wasm/client/testutil/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ func (s *IntegrationTestSuite) TestGetCmdGetContractHistory() {

codeID, err := strconv.ParseUint(s.codeID, 10, 64)
s.Require().NoError(err)
s.Require().True(s.setupHeight > 0)
codeUpdateHeight := uint64(s.setupHeight)

testCases := map[string]struct {
args []string
Expand All @@ -410,7 +412,7 @@ func (s *IntegrationTestSuite) TestGetCmdGetContractHistory() {
{
Operation: types.ContractCodeHistoryOperationTypeInit,
CodeID: codeID,
Updated: nil,
Updated: &types.AbsoluteTxPosition{BlockHeight: codeUpdateHeight, TxIndex: 0},
Msg: []byte(fmt.Sprintf("{\"verifier\":\"%s\",\"beneficiary\":\"%s\"}", s.verifier, s.beneficiary)),
},
},
Expand Down
4 changes: 0 additions & 4 deletions x/wasm/keeper/legacy_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ func queryCodeList(ctx sdk.Context, keeper types.ViewKeeper) ([]types.CodeInfoRe
//nolint:unparam
func queryContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress, keeper types.ViewKeeper) ([]types.ContractCodeHistoryEntry, error) {
history := keeper.GetContractHistory(ctx, contractAddr)
// redact response
for i := range history {
history[i].Updated = nil
}
return history, nil
}

Expand Down
14 changes: 9 additions & 5 deletions x/wasm/keeper/legacy_querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,43 +233,47 @@ func TestLegacyQueryContractHistory(t *testing.T) {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeGenesis,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}},
expContent: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeGenesis,
CodeID: firstCodeID,
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}},
},
"response with multiple entries": {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeInit,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 2,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
Msg: []byte(`"migrate message 1"`),
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 3,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 5, TxIndex: 6},
Msg: []byte(`"migrate message 2"`),
}},
expContent: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeInit,
CodeID: firstCodeID,
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 2,
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
Msg: []byte(`"migrate message 1"`),
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 3,
Updated: &types.AbsoluteTxPosition{BlockHeight: 5, TxIndex: 6},
Msg: []byte(`"migrate message 2"`),
}},
},
Expand All @@ -278,7 +282,7 @@ func TestLegacyQueryContractHistory(t *testing.T) {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeGenesis,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}},
expContent: []types.ContractCodeHistoryEntry{},
Expand Down
1 change: 0 additions & 1 deletion x/wasm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func (q grpcQuerier) ContractHistory(c context.Context, req *types.QueryContract
if err := q.cdc.Unmarshal(value, &e); err != nil {
return false, err
}
e.Updated = nil // redact
r = append(r, e)
}
return true, nil
Expand Down
22 changes: 14 additions & 8 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,58 +330,62 @@ func TestQueryContractHistory(t *testing.T) {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeGenesis,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}},
req: types.QueryContractHistoryRequest{Address: myContractBech32Addr},
expContent: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeGenesis,
CodeID: firstCodeID,
Msg: []byte(`"init message"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
}},
},
"response with multiple entries": {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeInit,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 2,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
Msg: []byte(`"migrate message 1"`),
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 3,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 5, TxIndex: 6},
Msg: []byte(`"migrate message 2"`),
}},
req: types.QueryContractHistoryRequest{Address: myContractBech32Addr},
expContent: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeInit,
CodeID: firstCodeID,
Msg: []byte(`"init message"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 2,
Msg: []byte(`"migrate message 1"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 3,
Msg: []byte(`"migrate message 2"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 5, TxIndex: 6},
}},
},
"with pagination offset": {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeInit,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 2,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
Msg: []byte(`"migrate message 1"`),
}},
req: types.QueryContractHistoryRequest{
Expand All @@ -394,18 +398,19 @@ func TestQueryContractHistory(t *testing.T) {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 2,
Msg: []byte(`"migrate message 1"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
}},
},
"with pagination limit": {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeInit,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 2,
Updated: types.NewAbsoluteTxPosition(ctx),
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
Msg: []byte(`"migrate message 1"`),
}},
req: types.QueryContractHistoryRequest{
Expand All @@ -418,6 +423,7 @@ func TestQueryContractHistory(t *testing.T) {
Operation: types.ContractCodeHistoryOperationTypeInit,
CodeID: firstCodeID,
Msg: []byte(`"init message"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
}},
},
"unknown contract address": {
Expand Down