Skip to content

Commit

Permalink
Merge pull request #73 from 0glabs/dev
Browse files Browse the repository at this point in the history
merge dev changes
  • Loading branch information
0g-wh authored Aug 23, 2024
2 parents 83d0ab3 + 17bd9a6 commit 66539dc
Show file tree
Hide file tree
Showing 23 changed files with 209 additions and 239 deletions.
42 changes: 42 additions & 0 deletions Dockerfile-node
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM --platform=linux/amd64 ubuntu:24.04

# Install dependencies
RUN apt-get update && \
apt-get install -y \
git \
sudo \
wget \
jq \
make \
gcc \
unzip && \
rm -rf /var/lib/apt/lists/*

# Install Go
RUN wget https://golang.org/dl/go1.22.5.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.22.5.linux-amd64.tar.gz && \
rm go1.22.5.linux-amd64.tar.gz
# Set Go environment variables
ENV GOPATH=/root/go
ENV PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
# Create Go workspace directory
RUN mkdir -p /root/go

WORKDIR /root

# https://docs.0g.ai/0g-doc/run-a-node/validator-node
RUN git clone -b v0.2.3 https://github.com/0glabs/0g-chain.git
RUN ./0g-chain/networks/testnet/install.sh

RUN 0gchaind config chain-id zgtendermint_16600-2

RUN 0gchaind init testnetnode --chain-id zgtendermint_16600-2

RUN rm ~/.0gchain/config/genesis.json
RUN wget -P ~/.0gchain/config https://github.com/0glabs/0g-chain/releases/download/v0.2.3/genesis.json

RUN 0gchaind validate-genesis

RUN sed -i 's|seeds = ""|seeds = "[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656"|' $HOME/.0gchain/config/config.toml

ENTRYPOINT ["0gchaind", "start"]
3 changes: 0 additions & 3 deletions app/tally_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
Expand Down
24 changes: 12 additions & 12 deletions client/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,33 +18,33 @@ 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")
}
query, error := query.NewQueryClient(grpcUrl)
if error != nil {
return nil, error
}
client := &KavaGrpcClient{
client := &ZgChainGrpcClient{
Query: query,
Util: util.NewUtil(query),
config: config,
}
return client, nil
}

func NewDefaultConfig() KavaGrpcClientConfig {
return KavaGrpcClientConfig{}
func NewDefaultConfig() ZgChainGrpcClientConfig {
return ZgChainGrpcClientConfig{}
}
20 changes: 0 additions & 20 deletions client/grpc/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,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
}

// NewQueryClient creates a new QueryClient and initializes all the module query clients
Expand Down Expand Up @@ -105,21 +95,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),
}
return client, nil
}
10 changes: 0 additions & 10 deletions client/grpc/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
1 change: 1 addition & 0 deletions client/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.3.0
cosmossdk.io/simapp v0.0.0-20231127212628-044ff4d8c015
github.com/cenkalti/backoff/v4 v4.1.3
github.com/cometbft/cometbft v0.37.4
github.com/cometbft/cometbft-db v0.9.1
Expand Down Expand Up @@ -52,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
Expand Down Expand Up @@ -234,7 +234,7 @@ replace (
// Use go-ethereum fork with precompiles
github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc2
// Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support
github.com/evmos/ethermint => github.com/0glabs/ethermint v0.21.0-0g.v3.0.2
github.com/evmos/ethermint => github.com/0glabs/ethermint v0.21.0-0g.v3.0.3
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
// Downgraded to avoid bugs in following commits which causes "version does not exist" errors
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3/go.mod h1:wMEGFFFN
git.sr.ht/~sircmpwn/go-bare v0.0.0-20210406120253-ab86bc2846d9/go.mod h1:BVJwbDfVjCjoFiKrhkei6NdGcZYpkDkdyCdg1ukytRA=
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.3 h1:Wx3tVMTuFaaHDeJT/OzT7QLfAIpeaZsG9R6XoTOyKCw=
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.3/go.mod h1:BWo24B8cApWcO2/widWYIdt3CPxbh+HCSypCPpjTjog=
github.com/0glabs/ethermint v0.21.0-0g.v3.0.2 h1:4YI5wzzRdAvZ27PMLityxooICEE1bkG+7HgNQUm6JyM=
github.com/0glabs/ethermint v0.21.0-0g.v3.0.2/go.mod h1:HYQUhvcZBIG71H3xlxQSk0XyQEjeaHsduOj6O2QImrE=
github.com/0glabs/ethermint v0.21.0-0g.v3.0.3 h1:QNrXBQV5L/9FvYRUzJRXMV745xBmJhIP0aEdo0u8x+8=
github.com/0glabs/ethermint v0.21.0-0g.v3.0.3/go.mod h1:HYQUhvcZBIG71H3xlxQSk0XyQEjeaHsduOj6O2QImrE=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package zg.validatorvesting.v1beta1;
package zgc.validatorvesting.v1beta1;

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/e2e_community_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
19 changes: 11 additions & 8 deletions tests/e2e/e2e_convert_cosmos_coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}},
)
Expand Down Expand Up @@ -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}},
)
Expand Down Expand Up @@ -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}},
)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/e2e_evm_contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
13 changes: 7 additions & 6 deletions tests/e2e/e2e_grpc_client_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand All @@ -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{},
)

Expand Down
9 changes: 5 additions & 4 deletions tests/e2e/e2e_grpc_client_util_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading

0 comments on commit 66539dc

Please sign in to comment.