Skip to content

Commit

Permalink
Merge update wasmd v0.11.1 (#65)
Browse files Browse the repository at this point in the history
MERGING wasmd v0.10.0..v0.11.1:

* wasmd v0.10.0

* go-cosmwasm 0.11.0-alpha1 and fix compiler issues

* Updated contracts from cosmwasm v0.11.0-alpha3

https://github.com/CosmWasm/cosmwasm/releases/tag/v0.11.0-alpha3

* Return TimeNanos along with BlockInfo

* Fix gas on tests

* Fix reflect tests

* Error message cleanup

* Cleanup from pr review

* Update go-cosmwasm to v0.11.0-alpha2, contracts to v0.11.0-alpha4

* Update code/tests to new version

* Fix old contract naming in integration tests

* Implemented files called general_consts.go to all modules that heavly relied on  the duplicated "CLientID : 1"
Future duplicated variables across the entire module can also be added to it, centralizing therefore all os those kind of values.

* Closes #10 Implemented files called general_consts.go to all modules that heavly relied on the duplicated "ClientID : 1"

* Add more queries on reflect contract

* Test QuerySmart and QueryRaw reflected via contract

* Add test for the response of StakingQuery::Validators

* Add test for StakingQuery::AllDelegations

* Cleanup from PR comments

* Add tests for StakingQuery::{Delegation,BondedDenom}

* Increment x/wasm error codes by 1

* Return raw stored bytes for raw queries

* Update raw query REST response

* Use json.RawMessage for better encoding of REST interface on raw queries

* Test QueryContractState based on binary

* Test nil key and adapt docs

* Better calculation of Delegation.CanRedelegate

* Wrote gnarly query to get outstanding rewards for delegator

* Update app.go for new constructor

* Minor PR cleanup

* Ensure the DelegationQuery doesn't modify the state

* Extra safe we do not write during the query

* Prevent integer overflow

* Review feedback

* Add test showing WasmQuery::Raw fails for missing responses

* Update to go-cosmwasm v0.11.0-rc and raw query tests pass

* Update to go-cosmwasm v0.11.0

* Download newest contracts

* Base64 encoded return data on wasm raw query REST endpoint

* Manually encode as base64 as auto-encoded doesn't work

FIXES FOR MERGING:

* fix: add more properties to wasm keeper constructor

- add encodeRouter, queryRouter, distribution keeper
- update go.sum

* fix: replace contracts with cosmwasm version 0.12.0

* fix: add a newline in the end of download_releases.sh

* fix: replace contract for perf_check

Co-authored-by: Yongwoo Lee <whylee@linecorp.com>
Co-authored-by: Ethan Frey <ethanfrey@users.noreply.github.com>
Co-authored-by: Gustavo H. M. Silva <gustavohmsilva@tuta.io>
Co-authored-by: Simon Warta <simon@warta.it>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
  • Loading branch information
6 people authored Jan 8, 2021
1 parent 3f2267d commit e8d32e8
Show file tree
Hide file tree
Showing 42 changed files with 691 additions and 236 deletions.
3 changes: 2 additions & 1 deletion alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

const (
firstCodeID = 1
DefaultParamspace = types.DefaultParamspace
ModuleName = types.ModuleName
StoreKey = types.StoreKey
Expand Down Expand Up @@ -114,7 +115,7 @@ type (
CodeInfo = types.CodeInfo
ContractInfo = types.ContractInfo
CreatedAt = types.AbsoluteTxPosition
WasmConfig = types.WasmConfig
Config = types.WasmConfig
MessageHandler = keeper.MessageHandler
BankEncoder = keeper.BankEncoder
CustomEncoder = keeper.CustomEncoder
Expand Down
12 changes: 3 additions & 9 deletions client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,10 @@ func queryContractStateRawHandlerFn(cliCtx context.CLIContext) http.HandlerFunc
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
// parse res
var resultData []types.Model
err = json.Unmarshal(res, &resultData)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, resultData)
// ensure this is base64 encoded
encoded := base64.StdEncoding.EncodeToString(res)
rest.PostProcessResponse(w, cliCtx, encoded)
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func GetTestData() ([]byte, []byte, []byte, error) {
wasmCode, err := ioutil.ReadFile("../../internal/keeper/testdata/contract.wasm")
wasmCode, err := ioutil.ReadFile("../../internal/keeper/testdata/hackatom.wasm")

if err != nil {
return nil, nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestInitGenesis(t *testing.T) {

initCmd := MsgInstantiateContract{
Sender: creator,
CodeID: 1,
CodeID: firstCodeID,
InitMsg: initMsgBz,
InitFunds: deposit,
}
Expand Down
37 changes: 20 additions & 17 deletions internal/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ import (
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/staking"

"github.com/line/link-modules/x/wasm/internal/types"
)

const firstCodeID = 1

func TestGenesisExportImport(t *testing.T) {
srcKeeper, srcCtx, srcStoreKeys, srcCleanup := setupKeeper(t)
defer srcCleanup()
wasmCode, err := ioutil.ReadFile("./testdata/contract.wasm")
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

// store some test data
Expand Down Expand Up @@ -115,7 +118,7 @@ func TestGenesisExportImport(t *testing.T) {
}

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

myCodeInfo := types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode))
Expand All @@ -126,7 +129,7 @@ func TestFailFastImport(t *testing.T) {
"happy path: code info correct": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand All @@ -141,7 +144,7 @@ func TestFailFastImport(t *testing.T) {
"happy path: code ids can contain gaps": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}, {
Expand All @@ -164,7 +167,7 @@ func TestFailFastImport(t *testing.T) {
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}, {
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand All @@ -179,7 +182,7 @@ func TestFailFastImport(t *testing.T) {
},
"prevent code hash mismatch": {src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: types.CodeInfoFixture(func(i *types.CodeInfo) { i.CodeHash = make([]byte, sha256.Size) }),
CodesBytes: wasmCode,
}},
Expand All @@ -188,12 +191,12 @@ func TestFailFastImport(t *testing.T) {
"prevent duplicate codeIDs": {src: types.GenesisState{
Codes: []types.Code{
{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
},
{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
},
Expand All @@ -203,7 +206,7 @@ func TestFailFastImport(t *testing.T) {
"happy path: code id in info and contract do match": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand All @@ -224,7 +227,7 @@ func TestFailFastImport(t *testing.T) {
"happy path: code info with two contracts": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand Down Expand Up @@ -259,7 +262,7 @@ func TestFailFastImport(t *testing.T) {
"prevent duplicate contract address": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand All @@ -278,7 +281,7 @@ func TestFailFastImport(t *testing.T) {
"prevent duplicate contract model keys": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand Down Expand Up @@ -326,7 +329,7 @@ func TestFailFastImport(t *testing.T) {
"prevent contract id seq init value == count contracts": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand Down Expand Up @@ -406,7 +409,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
keeper, ctx, _, dstCleanup := setupKeeper(t)
defer dstCleanup()

wasmCode, err := ioutil.ReadFile("./testdata/contract.wasm")
wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)

wasmCodeHash := sha256.Sum256(wasmCode)
Expand Down Expand Up @@ -455,7 +458,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
adminAddr, _ := sdk.AccAddressFromBech32("cosmos1h5t8zxmjr30e9dqghtlpl40f2zz5cgey6esxtn")

expContractInfo := types.ContractInfo{
CodeID: 1,
CodeID: firstCodeID,
Creator: contractCreatorAddr,
Admin: adminAddr,
Label: "ȀĴnZV芢毤",
Expand All @@ -465,7 +468,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {

expHistory := []types.ContractCodeHistoryEntry{{
Operation: types.GenesisContractCodeHistoryType,
CodeID: 1,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
},
}
Expand Down Expand Up @@ -498,7 +501,7 @@ func setupKeeper(t *testing.T) (Keeper, sdk.Context, []sdk.StoreKey, func()) {
cdc := MakeTestCodec()
pk := params.NewKeeper(cdc, keyParams, tkeyParams)
wasmConfig := types.DefaultWasmConfig()
srcKeeper := NewKeeper(cdc, keyWasm, pk.Subspace(types.DefaultParamspace), auth.AccountKeeper{}, nil, staking.Keeper{}, nil, nil, nil, tempDir, wasmConfig, "", nil, nil)
srcKeeper := NewKeeper(cdc, keyWasm, pk.Subspace(types.DefaultParamspace), auth.AccountKeeper{}, nil, staking.Keeper{}, distribution.Keeper{}, nil, nil, nil, tempDir, wasmConfig, "", nil, nil)
srcKeeper.setParams(ctx, types.DefaultParams())

return srcKeeper, ctx, []sdk.StoreKey{keyWasm, keyParams}, cleanup
Expand Down
4 changes: 2 additions & 2 deletions internal/keeper/ioutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
)

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

wasmGzipped, err := ioutil.ReadFile("./testdata/contract.wasm.gzip")
wasmGzipped, err := ioutil.ReadFile("./testdata/hackatom.wasm.gzip")
require.NoError(t, err)

const maxSize = 400_000
Expand Down
Loading

0 comments on commit e8d32e8

Please sign in to comment.