Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1526481
add authz native support
reecepbcups Dec 1, 2023
421b08c
`x/bank` support
reecepbcups Dec 1, 2023
5342317
cleanup bank queries
reecepbcups Dec 1, 2023
069779d
fix authz to SDK v50
reecepbcups Dec 1, 2023
c57a3c5
fix e2e
reecepbcups Dec 1, 2023
46c1c39
WIP of todos
reecepbcups Dec 2, 2023
f20e1e8
full bank suite testing
reecepbcups Dec 3, 2023
c1d1d0d
fix test
reecepbcups Dec 4, 2023
32e08ba
build TokenFactory off ChainNode
reecepbcups Dec 4, 2023
e6ea937
crisis, distr, slashing, and staking txs+queries
reecepbcups Dec 4, 2023
2fb0a4f
updated todo
reecepbcups Dec 5, 2023
720d1cd
move gRPC conn on node startup
reecepbcups Dec 6, 2023
d36acc8
rename all to modules_
reecepbcups Dec 6, 2023
7d0bfe9
add circuit & feegrant txs + queries
reecepbcups Dec 6, 2023
809d695
x/upgrade
reecepbcups Dec 6, 2023
c2a4a6c
WIP: x/gov
reecepbcups Dec 6, 2023
4317009
distribution test
reecepbcups Dec 9, 2023
59bf214
fix distribution
reecepbcups Dec 9, 2023
d5bee5e
Merge branch 'main' into reece/complete-core
reecepbcups Dec 9, 2023
f1c330e
backup
reecepbcups Dec 9, 2023
264939e
comment out bad feegrant for now
reecepbcups Dec 10, 2023
fe405d2
govv1 & govv1beta1 query types
reecepbcups Dec 10, 2023
03e390c
add SDK v50 gov test
reecepbcups Dec 10, 2023
c6cdd0c
wip: circuit
reecepbcups Dec 11, 2023
8648f3c
move cosmwasm to its own module section
reecepbcups Dec 30, 2023
059a87e
Add `x/auth` queries
reecepbcups Dec 30, 2023
b21efd0
add `vesting` txs + test
reecepbcups Dec 30, 2023
4341133
Merge branch 'main' into reece/complete-core
reecepbcups Dec 30, 2023
609856d
cleanup / move functions to better suited files
reecepbcups Dec 30, 2023
8d920bd
use `c.GetNode()` as Cosmos getFullNode
reecepbcups Dec 30, 2023
60c69d0
fully test `auth`
reecepbcups Dec 30, 2023
2dd180b
Use <Module>Query<Path> format (i.e. `AuthQueryAccount`)
reecepbcups Dec 30, 2023
8c603c0
remove todo log
reecepbcups Dec 30, 2023
8c6cb9a
rm circuit module
reecepbcups Dec 30, 2023
79d8959
testStaking
reecepbcups Dec 30, 2023
7e076dc
test slashing
reecepbcups Dec 30, 2023
2b43cb4
deprecate `TokenFactoryGetAdmin`
reecepbcups Dec 30, 2023
e127b6f
cleanup `testFeeGrant`
reecepbcups Dec 30, 2023
eecbc6d
final self review touchups
reecepbcups Dec 30, 2023
7cef1a9
cleanup `AuthPrintAccountInfo`
reecepbcups Jan 9, 2024
7953959
use path.Join
reecepbcups Jan 9, 2024
c9a62ef
`PrefixMsgTypeIfRequired`
reecepbcups Jan 9, 2024
7c9f8fd
Merge branch 'main' into reece/complete-core
reecepbcups Jan 9, 2024
2544c5f
Merge branch 'main' into reece/complete-core
reecepbcups Jan 9, 2024
3af2926
del[0]
reecepbcups Jan 9, 2024
99c1ff2
query users delegations, iter all for `found`
reecepbcups Jan 9, 2024
42d7856
supplyOf.IsGTE supply
reecepbcups Jan 9, 2024
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
383 changes: 35 additions & 348 deletions chain/cosmos/chain_node.go

Large diffs are not rendered by default.

123 changes: 33 additions & 90 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
cosmosproto "github.com/cosmos/gogoproto/proto"
chanTypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
dockertypes "github.com/docker/docker/api/types"
volumetypes "github.com/docker/docker/api/types/volume"
Expand All @@ -38,8 +36,6 @@ import (
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

// CosmosChain is a local docker testnet for a Cosmos SDK chain.
Expand All @@ -55,6 +51,7 @@ type CosmosChain struct {
// Additional processes that need to be run on a per-chain basis.
Sidecars SidecarProcesses

cdc *codec.ProtoCodec
log *zap.Logger
keyring keyring.Keyring
findTxMu sync.Mutex
Expand Down Expand Up @@ -104,10 +101,16 @@ func NewCosmosChain(testName string, chainConfig ibc.ChainConfig, numValidators
numValidators: numValidators,
numFullNodes: numFullNodes,
log: log,
cdc: cdc,
keyring: kr,
}
}

// GetCodec returns the codec for the chain.
func (c *CosmosChain) GetCodec() *codec.ProtoCodec {
return c.cdc
}
Comment on lines +108 to +111
Copy link
Copy Markdown
Member Author

@reecepbcups reecepbcups Dec 30, 2023

Choose a reason for hiding this comment

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

Required for module_auth.go (converting the any types -> accounts)


// Nodes returns all nodes, including validators and fullnodes.
func (c *CosmosChain) Nodes() ChainNodes {
return append(c.Validators, c.FullNodes...)
Expand Down Expand Up @@ -313,7 +316,7 @@ func (c *CosmosChain) BuildRelayerWallet(ctx context.Context, keyName string) (i

// Implements Chain interface
func (c *CosmosChain) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error {
return c.getFullNode().SendFunds(ctx, keyName, amount)
return c.getFullNode().BankSend(ctx, keyName, amount)
}

// Implements Chain interface
Expand Down Expand Up @@ -375,24 +378,32 @@ func (c *CosmosChain) SendIBCTransfer(
return tx, nil
}

// ExecQueryToResponse is a helper to convert a query to its response.
func (c *CosmosChain) ExecQueryToResponse(ctx context.Context, chain *CosmosChain, cmd []string, res interface{}) error {
rCmd := make([]string, 0)
for _, c := range cmd {
if c != "" {
rCmd = append(rCmd, c)
}
}

stdout, stderr, err := chain.getFullNode().ExecQuery(ctx, rCmd...)
if err != nil {
fmt.Println("HandleQuery err: ", string(stdout), string(stderr), err.Error())
return err
}

return json.Unmarshal(stdout, &res)
}

// GetGovernanceAddress performs a query to get the address of the chain's x/gov module
func (c *CosmosChain) GetGovernanceAddress(ctx context.Context) (string, error) {
return c.GetModuleAddress(ctx, govtypes.ModuleName)
}

// GetModuleAddress performs a query to get the address of the specified chain module
func (c *CosmosChain) GetModuleAddress(ctx context.Context, moduleName string) (string, error) {
return c.getFullNode().GetModuleAddress(ctx, moduleName)
}

// QueryProposal returns the state and details of a governance proposal.
func (c *CosmosChain) QueryProposal(ctx context.Context, proposalID string) (*ProposalResponse, error) {
return c.getFullNode().QueryProposal(ctx, proposalID)
}

// QueryProposal returns the state and details of an IBC-Go v8 / SDK v50 governance proposal.
func (c *CosmosChain) QueryProposalV8(ctx context.Context, proposalID string) (*ProposalResponseV8, error) {
return c.getFullNode().QueryProposalV8(ctx, proposalID)
return c.AuthGetModuleAddress(ctx, moduleName)
}

// PushNewWasmClientProposal submits a new wasm client governance proposal to the chain
Expand Down Expand Up @@ -443,38 +454,6 @@ func (c *CosmosChain) SubmitProposal(ctx context.Context, keyName string, prop T
return c.txProposal(txHash)
}

// Build a gov v1 proposal type.
//
// The proposer field should only be set for IBC-Go v8 / SDK v50 chains.
func (c *CosmosChain) BuildProposal(messages []cosmosproto.Message, title, summary, metadata, depositStr, proposer string, expedited bool) (TxProposalv1, error) {
var propType TxProposalv1
rawMsgs := make([]json.RawMessage, len(messages))

for i, msg := range messages {
msg, err := c.Config().EncodingConfig.Codec.MarshalInterfaceJSON(msg)
if err != nil {
return propType, err
}
rawMsgs[i] = msg
}

propType = TxProposalv1{
Messages: rawMsgs,
Metadata: metadata,
Deposit: depositStr,
Title: title,
Summary: summary,
}

// SDK v50 only
if proposer != "" {
propType.Proposer = proposer
propType.Expedited = expedited
}

return propType, nil
}

// TextProposal submits a text governance proposal to the chain.
func (c *CosmosChain) TextProposal(ctx context.Context, keyName string, prop TextProposal) (tx TxProposal, _ error) {
txHash, err := c.getFullNode().TextProposal(ctx, keyName, prop)
Expand Down Expand Up @@ -565,47 +544,6 @@ func (c *CosmosChain) ExportState(ctx context.Context, height int64) (string, er
return c.getFullNode().ExportState(ctx, height)
}

// GetBalance fetches the current balance for a specific account address and denom.
// Implements Chain interface
func (c *CosmosChain) GetBalance(ctx context.Context, address string, denom string) (sdkmath.Int, error) {
params := &bankTypes.QueryBalanceRequest{Address: address, Denom: denom}
grpcAddress := c.getFullNode().hostGRPCPort
conn, err := grpc.Dial(grpcAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return sdkmath.Int{}, err
}
defer conn.Close()

queryClient := bankTypes.NewQueryClient(conn)
res, err := queryClient.Balance(ctx, params)

if err != nil {
return sdkmath.Int{}, err
}

return res.Balance.Amount, nil
}

// AllBalances fetches an account address's balance for all denoms it holds
func (c *CosmosChain) AllBalances(ctx context.Context, address string) (types.Coins, error) {
params := bankTypes.QueryAllBalancesRequest{Address: address}
grpcAddress := c.getFullNode().hostGRPCPort
conn, err := grpc.Dial(grpcAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, err
}
defer conn.Close()

queryClient := bankTypes.NewQueryClient(conn)
res, err := queryClient.AllBalances(ctx, &params)

if err != nil {
return nil, err
}

return res.GetBalances(), nil
}

func (c *CosmosChain) GetTransaction(txhash string) (*types.TxResponse, error) {
fn := c.getFullNode()
return fn.GetTransaction(fn.CliContext(), txhash)
Expand Down Expand Up @@ -1258,12 +1196,17 @@ func (c *CosmosChain) StartAllValSidecars(ctx context.Context) error {
}

func (c *CosmosChain) VoteOnProposalAllValidators(ctx context.Context, proposalID string, vote string) error {
propID, err := strconv.ParseUint(proposalID, 10, 64)
if err != nil {
return fmt.Errorf("failed to parse proposalID %s: %w", proposalID, err)
}

var eg errgroup.Group
for _, n := range c.Nodes() {
if n.Validator {
n := n
eg.Go(func() error {
return n.VoteOnProposal(ctx, valKey, proposalID, vote)
return n.VoteOnProposal(ctx, valKey, propID, vote)
})
}
}
Expand Down
7 changes: 7 additions & 0 deletions chain/cosmos/module_TODO.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cosmos

// TODO: convert all to tn or c CosmosChain? (i think tn so we can chose the server to run it on)
// TODO: convert all queries to either <Module>GetFunc or <Module>QueryFunc

// TODO:
// - move anything from chain_node to its respective module
130 changes: 130 additions & 0 deletions chain/cosmos/module_auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package cosmos

import (
"context"
"encoding/json"
"fmt"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"

cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
)

func (c *CosmosChain) AuthGetAccount(ctx context.Context, addr string) (*cdctypes.Any, error) {
res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).Account(ctx, &authtypes.QueryAccountRequest{
Address: addr,
})
return res.Account, err
}

func (c *CosmosChain) AuthParams(ctx context.Context, addr string) (*authtypes.Params, error) {
res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).Params(ctx, &authtypes.QueryParamsRequest{})
return &res.Params, err
}

func (c *CosmosChain) AuthModuleAccounts(ctx context.Context, addr string) ([]*cdctypes.Any, error) {
res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).ModuleAccounts(ctx, &authtypes.QueryModuleAccountsRequest{})
return res.Accounts, err
}

// AuthGetModuleAccount performs a query to get the account details of the specified chain module
func (c *CosmosChain) AuthGetModuleAccount(ctx context.Context, moduleName string) (QueryModuleAccountResponse, error) {
node := c.GetNode()
stdout, _, err := node.ExecQuery(ctx, "auth", "module-account", moduleName)
if err != nil {
return QueryModuleAccountResponse{}, err
}

queryRes := QueryModuleAccountResponse{}
err = json.Unmarshal(stdout, &queryRes)
if err != nil {
return QueryModuleAccountResponse{}, err
}
return queryRes, nil
}

// GetModuleAddress performs a query to get the address of the specified chain module
func (c *CosmosChain) AuthGetModuleAddress(ctx context.Context, moduleName string) (string, error) {
queryRes, err := c.AuthGetModuleAccount(ctx, moduleName)
if err != nil {
return "", err
}
return queryRes.Account.BaseAccount.Address, nil
}

func (c *CosmosChain) AuthBech32Prefix(ctx context.Context) (string, error) {
res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).Bech32Prefix(ctx, &authtypes.Bech32PrefixRequest{})
return res.Bech32Prefix, err
}

// AddressBytesToString
func (c *CosmosChain) AuthAddressBytesToString(ctx context.Context, addrBz []byte) (string, error) {
res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).AddressBytesToString(ctx, &authtypes.AddressBytesToStringRequest{
AddressBytes: addrBz,
})
return res.AddressString, err
}

// AddressStringToBytes
func (c *CosmosChain) AuthAddressStringToBytes(ctx context.Context, addr string) ([]byte, error) {
res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).AddressStringToBytes(ctx, &authtypes.AddressStringToBytesRequest{
AddressString: addr,
})
return res.AddressBytes, err
}

// AccountInfo
func (c *CosmosChain) AuthAccountInfo(ctx context.Context, addr string) (*authtypes.BaseAccount, error) {
res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).AccountInfo(ctx, &authtypes.QueryAccountInfoRequest{
Address: addr,
})
return res.Info, err
}

func (c *CosmosChain) AuthPrintAccountInfo(chain *CosmosChain, res *codectypes.Any) error {
switch res.TypeUrl {
case "/cosmos.auth.v1beta1.ModuleAccount":
var modAcc authtypes.ModuleAccount
err := chain.GetCodec().Unmarshal(res.Value, &modAcc)
fmt.Printf("modAcc: %+v\n", modAcc)
return err
Comment thread
jtieri marked this conversation as resolved.
Outdated

case "/cosmos.vesting.v1beta1.VestingAccount":
var vestingAcc vestingtypes.BaseVestingAccount
err := chain.GetCodec().Unmarshal(res.Value, &vestingAcc)
fmt.Printf("BaseVestingAccount: %+v\n", vestingAcc)
return err

case "/cosmos.vesting.v1beta1.PeriodicVestingAccount":
var vestingAcc vestingtypes.PeriodicVestingAccount
err := chain.GetCodec().Unmarshal(res.Value, &vestingAcc)
fmt.Printf("PeriodicVestingAccount: %+v\n", vestingAcc)
return err

case "/cosmos.vesting.v1beta1.ContinuousVestingAccount":
var vestingAcc vestingtypes.ContinuousVestingAccount
err := chain.GetCodec().Unmarshal(res.Value, &vestingAcc)
fmt.Printf("ContinuousVestingAccount: %+v\n", vestingAcc)
return err

case "/cosmos.vesting.v1beta1.DelayedVestingAccount":
var vestingAcc vestingtypes.DelayedVestingAccount
err := chain.GetCodec().Unmarshal(res.Value, &vestingAcc)
fmt.Printf("DelayedVestingAccount: %+v\n", vestingAcc)
return err

case "/cosmos.vesting.v1beta1.PermanentLockedAccount":
var vestingAcc vestingtypes.PermanentLockedAccount
err := chain.GetCodec().Unmarshal(res.Value, &vestingAcc)
fmt.Printf("PermanentLockedAccount: %+v\n", vestingAcc)
return err

default:
var baseAcc authtypes.BaseAccount
err := chain.GetCodec().Unmarshal(res.Value, &baseAcc)
fmt.Printf("baseAcc: %+v\n", baseAcc)
return err
}
}
Loading