fix test build break

This commit is contained in:
Solovyov1796 2024-08-12 11:44:39 +08:00 committed by 0g-wh
parent 4ebbb886bf
commit 94ddf20305
17 changed files with 54 additions and 122 deletions

View File

@ -48,9 +48,6 @@ func (suite *tallyHandlerSuite) SetupTest() {
suite.tallier = NewTallyHandler(
suite.app.GetGovKeeper(),
stakingKeeper,
suite.app.GetSavingsKeeper(),
suite.app.GetEarnKeeper(),
suite.app.GetLiquidKeeper(),
suite.app.GetBankKeeper(),
)
}

View File

@ -7,9 +7,9 @@ import (
"github.com/0glabs/0g-chain/client/grpc/util"
)
// KavaGrpcClient enables the usage of kava grpc query clients and query utils
type KavaGrpcClient struct {
config KavaGrpcClientConfig
// ZgChainGrpcClient enables the usage of kava grpc query clients and query utils
type ZgChainGrpcClient struct {
config ZgChainGrpcClientConfig
// Query clients for cosmos and kava modules
Query *query.QueryClient
@ -18,18 +18,18 @@ type KavaGrpcClient struct {
*util.Util
}
// KavaGrpcClientConfig is a configuration struct for a KavaGrpcClient
type KavaGrpcClientConfig struct {
// ZgChainGrpcClientConfig is a configuration struct for a ZgChainGrpcClient
type ZgChainGrpcClientConfig struct {
// note: add future config options here
}
// NewClient creates a new KavaGrpcClient via a grpc url
func NewClient(grpcUrl string) (*KavaGrpcClient, error) {
// NewClient creates a new ZgChainGrpcClient via a grpc url
func NewClient(grpcUrl string) (*ZgChainGrpcClient, error) {
return NewClientWithConfig(grpcUrl, NewDefaultConfig())
}
// NewClientWithConfig creates a new KavaGrpcClient via a grpc url and config
func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpcClient, error) {
// NewClientWithConfig creates a new ZgChainGrpcClient via a grpc url and config
func NewClientWithConfig(grpcUrl string, config ZgChainGrpcClientConfig) (*ZgChainGrpcClient, error) {
if grpcUrl == "" {
return nil, errors.New("grpc url cannot be empty")
}
@ -37,7 +37,7 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
if error != nil {
return nil, error
}
client := &KavaGrpcClient{
client := &ZgChainGrpcClient{
Query: query,
Util: util.NewUtil(query),
config: config,
@ -45,6 +45,6 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
return client, nil
}
func NewDefaultConfig() KavaGrpcClientConfig {
return KavaGrpcClientConfig{}
func NewDefaultConfig() ZgChainGrpcClientConfig {
return ZgChainGrpcClientConfig{}
}

View File

@ -61,21 +61,11 @@ type QueryClient struct {
// kava module query clients
Auction auctiontypes.QueryClient
Bep3 bep3types.QueryClient
Cdp cdptypes.QueryClient
Committee committeetypes.QueryClient
Community communitytypes.QueryClient
Earn earntypes.QueryClient
Evmutil evmutiltypes.QueryClient
Hard hardtypes.QueryClient
Incentive incentivetypes.QueryClient
Issuance issuancetypes.QueryClient
Kavadist kavadisttypes.QueryClient
Liquid liquidtypes.QueryClient
Pricefeed pricefeedtypes.QueryClient
Savings savingstypes.QueryClient
Swap swaptypes.QueryClient
Precisebank precisebanktypes.QueryClient
}
@ -107,21 +97,11 @@ func NewQueryClient(grpcEndpoint string) (*QueryClient, error) {
IbcClient: ibcclienttypes.NewQueryClient(conn),
IbcTransfer: ibctransfertypes.NewQueryClient(conn),
Auction: auctiontypes.NewQueryClient(conn),
Bep3: bep3types.NewQueryClient(conn),
Cdp: cdptypes.NewQueryClient(conn),
Committee: committeetypes.NewQueryClient(conn),
Community: communitytypes.NewQueryClient(conn),
Earn: earntypes.NewQueryClient(conn),
Evmutil: evmutiltypes.NewQueryClient(conn),
Hard: hardtypes.NewQueryClient(conn),
Incentive: incentivetypes.NewQueryClient(conn),
Issuance: issuancetypes.NewQueryClient(conn),
Kavadist: kavadisttypes.NewQueryClient(conn),
Liquid: liquidtypes.NewQueryClient(conn),
Pricefeed: pricefeedtypes.NewQueryClient(conn),
Savings: savingstypes.NewQueryClient(conn),
Swap: swaptypes.NewQueryClient(conn),
Precisebank: precisebanktypes.NewQueryClient(conn),
}
return client, nil

View File

@ -55,20 +55,10 @@ func TestNewQueryClient_ValidClient(t *testing.T) {
require.NotNil(t, client.IbcTransfer)
// validate kava clients
require.NotNil(t, client.Auction)
require.NotNil(t, client.Bep3)
require.NotNil(t, client.Cdp)
require.NotNil(t, client.Committee)
require.NotNil(t, client.Community)
require.NotNil(t, client.Earn)
require.NotNil(t, client.Evmutil)
require.NotNil(t, client.Hard)
require.NotNil(t, client.Incentive)
require.NotNil(t, client.Issuance)
require.NotNil(t, client.Kavadist)
require.NotNil(t, client.Liquid)
require.NotNil(t, client.Pricefeed)
require.NotNil(t, client.Savings)
require.NotNil(t, client.Swap)
})
}

View File

@ -12,6 +12,7 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
simappparams "cosmossdk.io/simapp/params"
"github.com/0glabs/0g-chain/client/rest"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

1
go.mod
View File

@ -53,7 +53,6 @@ require (
cosmossdk.io/core v0.6.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/simapp v0.0.0-20231127212628-044ff4d8c015 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect

View File

@ -5,7 +5,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
// communitytypes "github.com/0glabs/0g-chain/x/community/types"
)
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_NonAuthority() {

View File

@ -25,7 +25,10 @@ func setupConvertToCoinTest(
) (denom string, initialFunds sdk.Coins, user *testutil.SigningAccount) {
// we expect a denom to be registered to the allowed denoms param
// and for the funded account to have a balance for that denom
params, err := suite.ZgChain.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
params, err := suite.ZgChain.Grpc.Query.Evmutil.Params(
context.Background(),
&evmutiltypes.QueryParamsRequest{},
)
suite.NoError(err)
suite.GreaterOrEqual(
len(params.Params.AllowedCosmosDenoms), 1,
@ -74,7 +77,7 @@ func (suite *IntegrationTestSuite) setupAccountWithCosmosCoinERC20Balance(
sdkBalance = sdkBalance.Sub(convertAmount)
// query for the deployed contract
deployedContracts, err := suite.ZgChain.Evmutil.DeployedCosmosCoinContracts(
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
context.Background(),
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
)
@ -110,7 +113,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
suite.NoError(res.Err)
// query for the deployed contract
deployedContracts, err := suite.ZgChain.Evmutil.DeployedCosmosCoinContracts(
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
context.Background(),
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
)
@ -192,18 +195,18 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
suite.NoError(err)
// submit the eip712 message to the chain.
res, err := suite.ZgChain.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
TxBytes: txBytes,
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
})
suite.NoError(err)
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Tx, res.TxResponse.TxHash, 12*time.Second)
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 12*time.Second)
suite.Require().NoError(err)
// query for the deployed contract
deployedContracts, err := suite.ZgChain.Evmutil.DeployedCosmosCoinContracts(
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
context.Background(),
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
)
@ -246,14 +249,14 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
suite.NoError(err)
// submit the eip712 message to the chain
res, err = suite.ZgChain.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
res, err = suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
TxBytes: txBytes,
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
})
suite.NoError(err)
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Tx, res.TxResponse.TxHash, 6*time.Second)
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
suite.NoError(err)
// check erc20 balance

View File

@ -85,18 +85,18 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
suite.NoError(err)
// broadcast tx
res, err := suite.ZgChain.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
TxBytes: txBytes,
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
})
suite.NoError(err)
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Tx, res.TxResponse.TxHash, 6*time.Second)
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
suite.NoError(err)
// check that the message was processed & the gas denom is transferred.
balRes, err := suite.ZgChain.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
balRes, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
Address: receiver.String(),
Denom: chaincfg.GasDenom,
})

View File

@ -6,18 +6,19 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/0glabs/0g-chain/chaincfg"
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
)
func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() {
// ARRANGE
// setup kava account
funds := ukava(1e5) // .1 KAVA
kavaAcc := suite.Kava.NewFundedAccount("balance-test", sdk.NewCoins(funds))
// setup 0g account
funds := chaincfg.MakeCoinForGasDenom(1e5)
zgAcc := suite.ZgChain.NewFundedAccount("balance-test", sdk.NewCoins(funds))
// ACT
rsp, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
Address: kavaAcc.SdkAddress.String(),
rsp, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
Address: zgAcc.SdkAddress.String(),
Denom: funds.Denom,
})
@ -28,7 +29,7 @@ func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() {
func (suite *IntegrationTestSuite) TestGrpcClientQueryKavaModule_EvmParams() {
// ACT
rsp, err := suite.Kava.Grpc.Query.Evmutil.Params(
rsp, err := suite.ZgChain.Grpc.Query.Evmutil.Params(
context.Background(), &evmutiltypes.QueryParamsRequest{},
)

View File

@ -1,20 +1,21 @@
package e2e_test
import (
"github.com/0glabs/0g-chain/chaincfg"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (suite *IntegrationTestSuite) TestGrpcClientUtil_Account() {
// ARRANGE
// setup kava account
kavaAcc := suite.Kava.NewFundedAccount("account-test", sdk.NewCoins(ukava(1e5)))
// setup 0g account
zgAcc := suite.ZgChain.NewFundedAccount("account-test", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e5)))
// ACT
rsp, err := suite.Kava.Grpc.BaseAccount(kavaAcc.SdkAddress.String())
rsp, err := suite.ZgChain.Grpc.BaseAccount(zgAcc.SdkAddress.String())
// ASSERT
suite.Require().NoError(err)
suite.Equal(kavaAcc.SdkAddress.String(), rsp.Address)
suite.Equal(zgAcc.SdkAddress.String(), rsp.Address)
suite.Greater(rsp.AccountNumber, uint64(1))
suite.Equal(uint64(0), rsp.Sequence)
}

View File

@ -47,7 +47,7 @@ func (suite *IntegrationTestSuite) TestChainID() {
suite.Equal(expectedEvmNetworkId, evmNetworkId)
// SDK query
nodeInfo, err := suite.ZgChain.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
nodeInfo, err := suite.ZgChain.Grpc.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
suite.NoError(err)
suite.Equal(suite.ZgChain.ChainID, nodeInfo.DefaultNodeInfo.Network)
}
@ -62,7 +62,7 @@ func (suite *IntegrationTestSuite) TestFundedAccount() {
suite.Equal(acc.EvmAddress.Hex(), util.SdkToEvmAddress(acc.SdkAddress).Hex())
// check balance via SDK query
res, err := suite.ZgChain.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
res, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
acc.SdkAddress, chaincfg.GasDenom,
))
suite.NoError(err)

View File

@ -8,10 +8,10 @@ import (
func (suite *IntegrationTestSuite) TestUpgrade_PreciseBankReserveTransfer() {
suite.SkipIfUpgradeDisabled()
beforeUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight)
// beforeUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
// afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight)
grpcClient := suite.Kava.Grpc
// grpcClient := suite.Kava.Grpc
// -----------------------------
// Get initial reserve balances

View File

@ -21,14 +21,11 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/0glabs/0g-chain/app"
chainparams "github.com/0glabs/0g-chain/app/params"
"github.com/0glabs/0g-chain/client/grpc"
"github.com/0glabs/0g-chain/tests/e2e/runner"
"github.com/0glabs/0g-chain/tests/util"
committeetypes "github.com/0glabs/0g-chain/x/committee/types"
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
)
// Chain wraps query clients & accounts for a network
@ -46,23 +43,9 @@ type Chain struct {
EncodingConfig chainparams.EncodingConfig
Auth authtypes.QueryClient
Authz authz.QueryClient
Bank banktypes.QueryClient
Committee committeetypes.QueryClient
Distribution distrtypes.QueryClient
Evm evmtypes.QueryClient
Evmutil evmutiltypes.QueryClient
Gov govv1types.QueryClient
Mint minttypes.QueryClient
Staking stakingtypes.QueryClient
Tm tmservice.ServiceClient
Tx txtypes.ServiceClient
Upgrade upgradetypes.QueryClient
TmSignClient tmclient.SignClient
Grpc *grpc.KavaGrpcClient
Grpc *grpc.ZgChainGrpcClient
}
// NewChain creates the query clients & signing account management for a chain run on a set of ports.
@ -94,7 +77,7 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
client, err := grpc.NewClient(details.GrpcUrl)
if err != nil {
chain.t.Fatalf("failed to create kava grpc client: %s", err)
chain.t.Fatalf("failed to create 0g-chain grpc client: %s", err)
}
chain.Grpc = client
@ -108,21 +91,6 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
return chain, err
}
chain.Auth = authtypes.NewQueryClient(grpcConn)
chain.Authz = authz.NewQueryClient(grpcConn)
chain.Bank = banktypes.NewQueryClient(grpcConn)
chain.Committee = committeetypes.NewQueryClient(grpcConn)
chain.Distribution = distrtypes.NewQueryClient(grpcConn)
chain.Evm = evmtypes.NewQueryClient(grpcConn)
chain.Evmutil = evmutiltypes.NewQueryClient(grpcConn)
chain.Gov = govv1types.NewQueryClient(grpcConn)
chain.Mint = minttypes.NewQueryClient(grpcConn)
chain.Staking = stakingtypes.NewQueryClient(grpcConn)
chain.Tm = tmservice.NewServiceClient(grpcConn)
chain.Tx = txtypes.NewServiceClient(grpcConn)
chain.Upgrade = upgradetypes.NewQueryClient(grpcConn)
// initialize accounts map
chain.accounts = make(map[string]*SigningAccount)
// setup the signing account for the initially funded account (used to fund all other accounts)

View File

@ -27,7 +27,7 @@ func (suite *E2eTestSuite) InitZgChainEvmData() {
}
// expect the erc20 to be enabled for conversion to sdk.Coin
params, err := suite.ZgChain.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
params, err := suite.ZgChain.Grpc.Query.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
if err != nil {
panic(fmt.Sprintf("failed to fetch evmutil params during init: %s", err))
}

View File

@ -198,10 +198,10 @@ func (suite *MsgServerSuite) TestConvertERC20ToCoin_Bep3() {
{
name: "invalid - invalid initiator address",
msg: types.MsgConvertERC20ToCoin{
Initiator: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
Receiver: invokerCosmosAddr.String(),
KavaERC20Address: contractAddr.String(),
Amount: sdkmath.NewInt(12e8),
Initiator: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
Receiver: invokerCosmosAddr.String(),
ZgChainERC20Address: contractAddr.String(),
Amount: sdkmath.NewInt(12e8),
},
userErc20Balance: sdkmath.NewInt(2e18),
errArgs: errArgs{
@ -214,7 +214,7 @@ func (suite *MsgServerSuite) TestConvertERC20ToCoin_Bep3() {
msg: types.MsgConvertERC20ToCoin{
Initiator: invoker.String(),
Receiver: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
KavaERC20Address: contractAddr.String(),
ZgChainERC20Address: contractAddr.String(),
Amount: sdkmath.NewInt(12e8),
},
userErc20Balance: sdkmath.NewInt(2e18),
@ -228,7 +228,7 @@ func (suite *MsgServerSuite) TestConvertERC20ToCoin_Bep3() {
msg: types.MsgConvertERC20ToCoin{
Initiator: invoker.String(),
Receiver: invokerCosmosAddr.String(),
KavaERC20Address: invokerCosmosAddr.String(),
ZgChainERC20Address: invokerCosmosAddr.String(),
Amount: sdkmath.NewInt(12e8),
},
userErc20Balance: sdkmath.NewInt(2e18),

View File

@ -1,7 +0,0 @@
package types
// MoneyMarketInterestRates is a slice of MoneyMarketInterestRate
type MoneyMarketInterestRates []MoneyMarketInterestRate
// InterestFactors is a slice of InterestFactor
type InterestFactors []InterestFactor