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

chore: fixing all the modules and wasmbindings #452

Merged
merged 5 commits into from
Sep 6, 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
2 changes: 1 addition & 1 deletion pkg/coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func SplitCoins(coins sdk.Coins, ratio sdk.Dec) (stack1, stack2 sdk.Coins) {
for _, coin := range coins {
stack1Coin := sdk.Coin{
Denom: coin.Denom,
Amount: coin.Amount.ToDec().Mul(ratio).TruncateInt(),
Amount: sdk.NewDecFromInt(coin.Amount).Mul(ratio).TruncateInt(),
}
stack2Coin := coin.Sub(stack1Coin)

Expand Down
2 changes: 1 addition & 1 deletion proto/archway/genmsg/v1/genmsg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package archway.genmsg.v1;
import "google/protobuf/any.proto";


option go_package = "github.com/archway-network/archway/x/genmsg/v1";
option go_package = "github.com/archway-network/archway/x/genmsg/types";

// GenesisState represents the messages to be processed during genesis by the genmsg module.
message GenesisState {
Expand Down
15 changes: 8 additions & 7 deletions wasmbinding/gov/query_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
sdk "github.com/cosmos/cosmos-sdk/types"
sdkErrors "github.com/cosmos/cosmos-sdk/types/errors"

govTypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

"github.com/archway-network/archway/wasmbinding/gov/types"
wasmTypes "github.com/archway-network/archway/wasmbinding/gov/types"
)

// KeeperReaderExpected defines the x/gov keeper expected read operations.
Expand All @@ -29,16 +30,16 @@
}

// GetVote returns the vote weighted options for a given proposal and voter.
func (h QueryHandler) GetVote(ctx sdk.Context, req types.VoteRequest) (types.VoteResponse, error) {
func (h QueryHandler) GetVote(ctx sdk.Context, req wasmTypes.VoteRequest) (wasmTypes.VoteResponse, error) {
if err := req.Validate(); err != nil {
return types.VoteResponse{}, fmt.Errorf("vote: %w", err)
return wasmTypes.VoteResponse{}, fmt.Errorf("vote: %w", err)
}

vote, found := h.govKeeper.GetVote(ctx, req.ProposalID, req.MustGetVoter())
if !found {
err := sdkErrors.Wrap(govTypes.ErrInvalidVote, fmt.Errorf("vote not found for proposal %d and voter %s", req.ProposalID, req.Voter).Error())
return types.VoteResponse{}, err
err := sdkErrors.Wrap(types.ErrInvalidVote, fmt.Errorf("vote not found for proposal %d and voter %s", req.ProposalID, req.Voter).Error())

Check failure on line 40 in wasmbinding/gov/query_handler.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: sdkErrors.Wrap is deprecated: functionality of this package has been moved to it's own module: (staticcheck)
return wasmTypes.VoteResponse{}, err
}

return types.NewVoteResponse(vote), nil
return wasmTypes.NewVoteResponse(vote), nil
}
17 changes: 12 additions & 5 deletions wasmbinding/gov/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package gov_test

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

govTypes "github.com/cosmos/cosmos-sdk/x/gov/types"
sdk "github.com/cosmos/cosmos-sdk/types"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
legacyGovTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

e2eTesting "github.com/archway-network/archway/e2e/testing"
"github.com/archway-network/archway/wasmbinding/gov"
Expand All @@ -27,11 +28,17 @@ func TestGovWASMBindings(t *testing.T) {
depositor := accAddrs[0]
voter := accAddrs[1]

govAccount := keeper.GetGovernanceAccount(ctx)
params := keeper.GetParams(ctx)

// Store a proposal
proposalId := govTypes.DefaultStartingProposalID
textProposal := govTypes.NewTextProposal("foo", "bar")
proposal, pErr := govTypes.NewProposal(textProposal, proposalId, time.Now().UTC(), time.Now().UTC())
textProposal := legacyGovTypes.NewTextProposal("foo", "bar")
proposalContentMsg, pErr := govTypes.NewLegacyContent(textProposal, govAccount.String())
require.NoError(t, pErr)

proposal, err := govTypes.NewProposal([]sdk.Msg{proposalContentMsg}, proposalId, ctx.BlockHeader().Time, ctx.BlockHeader().Time.Add(*params.MaxDepositPeriod), "", "Text Proposal", "Description", depositor)
require.NoError(t, err)
keeper.SetProposal(ctx, proposal)

// Make a deposit
Expand All @@ -40,7 +47,7 @@ func TestGovWASMBindings(t *testing.T) {

// Vote
keeper.ActivateVotingPeriod(ctx, proposal)
vote := govTypes.NewVote(proposalId, voter, govTypes.NewNonSplitVoteOption(govTypes.OptionYes))
vote := govTypes.NewVote(proposalId, voter, govTypes.NewNonSplitVoteOption(govTypes.OptionYes), "")
keeper.SetVote(ctx, vote)

t.Run("Query vote on proposal", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions wasmbinding/gov/types/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

govTypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

type VoteRequest struct {
Expand Down Expand Up @@ -119,7 +119,7 @@ func NewVoteResponse(vote govTypes.Vote) VoteResponse {
}

for _, option := range vote.Options {
resp.Vote.Options = append(resp.Vote.Options, NewWeightedVoteOption(option))
resp.Vote.Options = append(resp.Vote.Options, NewWeightedVoteOption(*option))
}

return resp
Expand All @@ -141,6 +141,6 @@ func NewWeightedVoteOption(voteOption govTypes.WeightedVoteOption) WeightedVoteO

return WeightedVoteOption{
Option: option,
Weight: voteOption.Weight.String(),
Weight: voteOption.Weight,
}
}
4 changes: 2 additions & 2 deletions wasmbinding/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
wasmdTypes "github.com/CosmWasm/wasmd/x/wasm/types"
voterTypes "github.com/archway-network/voter/src/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkGov "github.com/cosmos/cosmos-sdk/x/gov/types"
sdkGov "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/stretchr/testify/require"

e2eTesting "github.com/archway-network/archway/e2e/testing"
Expand All @@ -22,8 +22,8 @@ func TestGovQuerier(t *testing.T) {
chain.GetApp().GovKeeper.SetVote(chain.GetContext(), sdkGov.Vote{
ProposalId: 1,
Voter: chain.GetAccount(1).Address.String(),
Option: 0,
Options: nil,
Metadata: "",
})
acc := chain.GetAccount(0)
codeID := chain.UploadContract(acc, "../contracts/go/voter/code.wasm", wasmdTypes.DefaultUploadAccess)
Expand Down
17 changes: 11 additions & 6 deletions wasmbinding/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"time"

wasmVmTypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkErrors "github.com/cosmos/cosmos-sdk/types/errors"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
legacyGovTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -58,22 +60,25 @@ func TestWASMBindingPlugins(t *testing.T) {
})

t.Run("Query gov vote", func(t *testing.T) {
govAccount := govKeeper.GetGovernanceAccount(ctx)
proposalId := govTypes.DefaultStartingProposalID
textProposal := govTypes.NewTextProposal("foo", "bar")
accAddrs, _ := e2eTesting.GenAccounts(2)
depositor := accAddrs[0]
textProposal := legacyGovTypes.NewTextProposal("foo", "bar")

anyTime := time.Now().UTC()
proposal, pErr := govTypes.NewProposal(textProposal, proposalId, anyTime, anyTime)
proposalContentMsg, pErr := govTypes.NewLegacyContent(textProposal, govAccount.String())
require.NoError(t, pErr)
proposal, pErr := govTypes.NewProposal([]sdk.Msg{proposalContentMsg}, proposalId, anyTime, anyTime, "", "Text Proposal", "Description", depositor)
require.NoError(t, pErr)
govKeeper.SetProposal(ctx, proposal)

accAddrs, _ := e2eTesting.GenAccounts(2)
depositor := accAddrs[0]
deposit := govTypes.NewDeposit(proposalId, depositor, nil)
govKeeper.SetDeposit(ctx, deposit)

voter := accAddrs[1]
govKeeper.ActivateVotingPeriod(ctx, proposal)
vote := govTypes.NewVote(proposalId, voter, govTypes.NewNonSplitVoteOption(govTypes.OptionYes))
vote := govTypes.NewVote(proposalId, voter, govTypes.NewNonSplitVoteOption(govTypes.OptionYes), "")
govKeeper.SetVote(ctx, vote)

_, err := queryPlugin.Custom(ctx, []byte(fmt.Sprintf("{\"gov_vote\": {\"proposal_id\": %d, \"voter\": \"%s\"}}", proposalId, voter)))
Expand Down
14 changes: 7 additions & 7 deletions x/genmsg/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"

v1 "github.com/archway-network/archway/x/genmsg/v1"
"github.com/archway-network/archway/x/genmsg/types"
)

func anyToMsg(ir types.InterfaceRegistry, anyMsg *types.Any) (sdk.Msg, error) {
func anyToMsg(ir codectypes.InterfaceRegistry, anyMsg *codectypes.Any) (sdk.Msg, error) {
var sdkMsg sdk.Msg
err := ir.UnpackAny(anyMsg, &sdkMsg)
if err != nil {
Expand All @@ -22,9 +22,9 @@ func anyToMsg(ir types.InterfaceRegistry, anyMsg *types.Any) (sdk.Msg, error) {
return sdkMsg, nil
}

func validateGenesis(cdc codec.JSONCodec, genesis *v1.GenesisState) error {
func validateGenesis(cdc codec.JSONCodec, genesis *types.GenesisState) error {
interfaceRegistryProvider, ok := cdc.(interface {
InterfaceRegistry() types.InterfaceRegistry
InterfaceRegistry() codectypes.InterfaceRegistry
})
if !ok {
return fmt.Errorf("codec does not implement InterfaceRegistry")
Expand All @@ -39,9 +39,9 @@ func validateGenesis(cdc codec.JSONCodec, genesis *v1.GenesisState) error {
return nil
}

func initGenesis(context sdk.Context, cdc codec.JSONCodec, router MessageRouter, genesis *v1.GenesisState) error {
func initGenesis(context sdk.Context, cdc codec.JSONCodec, router MessageRouter, genesis *types.GenesisState) error {
interfaceRegistryProvider, ok := cdc.(interface {
InterfaceRegistry() types.InterfaceRegistry
InterfaceRegistry() codectypes.InterfaceRegistry
})
if !ok {
return fmt.Errorf("codec does not implement InterfaceRegistry")
Expand Down
16 changes: 8 additions & 8 deletions x/genmsg/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/require"

v1 "github.com/archway-network/archway/x/genmsg/v1"
"github.com/archway-network/archway/x/genmsg/types"
)

type mockRouter struct {
Expand All @@ -21,22 +21,22 @@ type mockRouter struct {
func (m mockRouter) Handler(msg sdk.Msg) baseapp.MsgServiceHandler { return m.handler(msg) }

func makeCodec(_ *testing.T) codec.JSONCodec {
ir := types.NewInterfaceRegistry()
ir := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(ir)
ir.RegisterInterface(sdk.MsgInterfaceProtoName, (*sdk.Msg)(nil), &banktypes.MsgSend{})
return cdc
}

func newGenesisFromMsgs(t *testing.T, cdc codec.JSONCodec, msgs ...proto.Message) *v1.GenesisState {
genesis := new(v1.GenesisState)
func newGenesisFromMsgs(t *testing.T, cdc codec.JSONCodec, msgs ...proto.Message) *types.GenesisState {
genesis := new(types.GenesisState)
for _, msg := range msgs {
anyProto, err := types.NewAnyWithValue(msg)
anyProto, err := codectypes.NewAnyWithValue(msg)
require.NoError(t, err)
genesis.Messages = append(genesis.Messages, anyProto)
}
genesisJSON, err := cdc.MarshalJSON(genesis)
require.NoError(t, err)
genesis = new(v1.GenesisState)
genesis = new(types.GenesisState)
require.NoError(t, cdc.UnmarshalJSON(genesisJSON, genesis))
return genesis
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func Test_initGenesis(t *testing.T) {
func Test_validateGenesis(t *testing.T) {
cdc := makeCodec(t)
t.Run("works - empty", func(t *testing.T) {
err := validateGenesis(cdc, &v1.GenesisState{})
err := validateGenesis(cdc, &types.GenesisState{})
require.NoError(t, err)
})
t.Run("works - with messages", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions x/genmsg/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/archway-network/archway/app"
e2eTesting "github.com/archway-network/archway/e2e/testing"
"github.com/archway-network/archway/x/genmsg"
v1 "github.com/archway-network/archway/x/genmsg/v1"
"github.com/archway-network/archway/x/genmsg/types"
)

func TestIntegration(t *testing.T) {
Expand All @@ -25,7 +25,7 @@ func TestIntegration(t *testing.T) {
}
anyMsg, err := codectypes.NewAnyWithValue(testMsg)
require.NoError(t, err)
genesis[genmsg.ModuleName] = cdc.MustMarshalJSON(&v1.GenesisState{Messages: []*codectypes.Any{anyMsg}})
genesis[genmsg.ModuleName] = cdc.MustMarshalJSON(&types.GenesisState{Messages: []*codectypes.Any{anyMsg}})
}))
bankQuery := banktypes.NewQueryClient(chain.Client())
resp, err := bankQuery.Balance(sdk.WrapSDKContext(chain.GetContext()), &banktypes.QueryBalanceRequest{
Expand Down
14 changes: 7 additions & 7 deletions x/genmsg/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

v1 "github.com/archway-network/archway/x/genmsg/v1"
"github.com/archway-network/archway/x/genmsg/types"
)

const (
Expand All @@ -40,19 +40,19 @@ type AppModule struct {
func (a AppModule) Name() string { return ModuleName }

func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(new(v1.GenesisState))
return cdc.MustMarshalJSON(new(types.GenesisState))
}

func (AppModule) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
state := new(v1.GenesisState)
state := new(types.GenesisState)
if err := cdc.UnmarshalJSON(bz, state); err != nil {
return fmt.Errorf("failed to unmarshal x/%s genesis state: %w", ModuleName, err)
}
return validateGenesis(cdc, state)
}

func (a AppModule) InitGenesis(context sdk.Context, codec codec.JSONCodec, message json.RawMessage) []abci.ValidatorUpdate {
state := new(v1.GenesisState)
state := new(types.GenesisState)
codec.MustUnmarshalJSON(message, state)
err := initGenesis(context, codec, a.router, state)
if err != nil {
Expand All @@ -62,7 +62,7 @@ func (a AppModule) InitGenesis(context sdk.Context, codec codec.JSONCodec, messa
}

func (a AppModule) ExportGenesis(_ sdk.Context, codec codec.JSONCodec) json.RawMessage {
return codec.MustMarshalJSON(new(v1.GenesisState))
return codec.MustMarshalJSON(new(types.GenesisState))
}

func (a AppModule) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
Expand All @@ -81,4 +81,4 @@ func (a AppModule) ConsensusVersion() uint64 { return 0 }

func (a AppModule) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {}

func (a AppModule) RegisterInterfaces(_ types.InterfaceRegistry) {}
func (a AppModule) RegisterInterfaces(_ codectypes.InterfaceRegistry) {}
15 changes: 8 additions & 7 deletions x/genmsg/v1/genmsg.pb.go → x/genmsg/types/genmsg.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading