From b634c0edf4a8492fe22f313333d4d42ec45704ee Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Fri, 17 Feb 2023 15:23:36 +0800 Subject: [PATCH 1/7] feat: adjust gas price change --- go.mod | 2 +- go.sum | 4 ++-- sdk/client/tx.go | 40 +++++++++++++++++++++++----------------- sdk/types/type.go | 2 ++ 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index f0132f1b3..3eb393e04 100644 --- a/go.mod +++ b/go.mod @@ -228,7 +228,7 @@ require ( replace ( github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 - github.com/cosmos/cosmos-sdk => github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230214050107-c8beb3e72b61 + github.com/cosmos/cosmos-sdk => github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230216105555-b94a14479b11 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/tendermint/tendermint => github.com/bnb-chain/gnfd-tendermint v0.0.1 ) diff --git a/go.sum b/go.sum index ec61e1750..95a08e00a 100644 --- a/go.sum +++ b/go.sum @@ -218,8 +218,8 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230214050107-c8beb3e72b61 h1:L+oI2VYN0GxQDqossulvO0InsZ/cBkPBSzRZg8iOP0Y= -github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230214050107-c8beb3e72b61/go.mod h1:NlIOmju3uhTOJ2YAzLPidpmh7sAgJ+J9dkUlSysHmjw= +github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230216105555-b94a14479b11 h1:2BDa9ntopNBk6kQWoGTbX6TzJckyek0K9bk9NcHBIhw= +github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230216105555-b94a14479b11/go.mod h1:NlIOmju3uhTOJ2YAzLPidpmh7sAgJ+J9dkUlSysHmjw= github.com/bnb-chain/gnfd-tendermint v0.0.1 h1:KWFuxWv8m6t1vUi3ADyVcEG0qVnEzQt1tjA6dk/b7+Q= github.com/bnb-chain/gnfd-tendermint v0.0.1/go.mod h1:/v9z9F6cq0+f7EGG92lYSLBcPYQDILoK91X8YM28hWo= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= diff --git a/sdk/client/tx.go b/sdk/client/tx.go index b66d21cbc..6ed2af885 100644 --- a/sdk/client/tx.go +++ b/sdk/client/tx.go @@ -15,8 +15,6 @@ import ( "google.golang.org/grpc" ) -const GasMultiplier = float64(1.2) - type TransactionClient interface { BroadcastTx(msgs []sdk.Msg, txOpt *types.TxOption, opts ...grpc.CallOption) (*tx.BroadcastTxResponse, error) SimulateTx(msgs []sdk.Msg, txOpt *types.TxOption, opts ...grpc.CallOption) (*tx.SimulateResponse, error) @@ -30,7 +28,7 @@ func (c *GreenfieldClient) BroadcastTx(msgs []sdk.Msg, txOpt *types.TxOption, op txBuilder := txConfig.NewTxBuilder() // txBuilder holds tx info - if err := c.constructTxWithGasLimit(msgs, txOpt, txConfig, txBuilder); err != nil { + if err := c.constructTxWithGas(msgs, txOpt, txConfig, txBuilder); err != nil { return nil, err } @@ -95,7 +93,7 @@ func (c *GreenfieldClient) simulateTx(txBytes []byte, opts ...grpc.CallOption) ( func (c *GreenfieldClient) SignTx(msgs []sdk.Msg, txOpt *types.TxOption) ([]byte, error) { txConfig := authtx.NewTxConfig(c.codec, []signing.SignMode{signing.SignMode_SIGN_MODE_EIP_712}) txBuilder := txConfig.NewTxBuilder() - if err := c.constructTxWithGasLimit(msgs, txOpt, txConfig, txBuilder); err != nil { + if err := c.constructTxWithGas(msgs, txOpt, txConfig, txBuilder); err != nil { return nil, err } return c.signTx(txConfig, txBuilder) @@ -173,9 +171,6 @@ func (c *GreenfieldClient) constructTx(msgs []sdk.Msg, txOpt *types.TxOption, tx if txOpt.Memo != "" { txBuilder.SetMemo(txOpt.Memo) } - if !txOpt.FeeAmount.IsZero() { - txBuilder.SetFeeAmount(txOpt.FeeAmount) - } if !txOpt.FeePayer.Empty() { txBuilder.SetFeePayer(txOpt.FeePayer) } @@ -184,17 +179,11 @@ func (c *GreenfieldClient) constructTx(msgs []sdk.Msg, txOpt *types.TxOption, tx return c.setSingerInfo(txBuilder) } -func (c *GreenfieldClient) constructTxWithGasLimit(msgs []sdk.Msg, txOpt *types.TxOption, txConfig client.TxConfig, txBuilder client.TxBuilder) error { - // construct a tx with txOpt excluding GasLimit - err := c.constructTx(msgs, txOpt, txBuilder) - if err != nil { +func (c *GreenfieldClient) constructTxWithGas(msgs []sdk.Msg, txOpt *types.TxOption, txConfig client.TxConfig, txBuilder client.TxBuilder) error { + // construct a tx with txOpt excluding GasLimit and + if err := c.constructTx(msgs, txOpt, txBuilder); err != nil { return err } - if txOpt != nil && txOpt.GasLimit != 0 { - txBuilder.SetGasLimit(txOpt.GasLimit) - return nil - } - txBytes, err := txConfig.TxEncoder()(txBuilder.GetTx()) if err != nil { return err @@ -203,7 +192,24 @@ func (c *GreenfieldClient) constructTxWithGasLimit(msgs []sdk.Msg, txOpt *types. if err != nil { return err } - txBuilder.SetGasLimit(uint64(GasMultiplier * float64(simulateRes.GasInfo.GetGasUsed()))) + + gasLimit := simulateRes.GasInfo.GetGasUsed() + gasPrice, err := sdk.ParseCoinsNormalized(simulateRes.GasInfo.GetMinGasPrices()) + if err != nil { + return err + } + txBuilder.SetGasLimit(gasLimit) + price := gasPrice.AmountOf(types.Denom) + feeAmount := sdk.NewCoins(sdk.NewInt64Coin(types.Denom, sdk.NewInt(int64(gasLimit)).Mul(price).Int64())) + txBuilder.SetFeeAmount(feeAmount) + if txOpt != nil { + if txOpt.GasLimit != 0 { + txBuilder.SetGasLimit(txOpt.GasLimit) + } + if !txOpt.FeeAmount.IsZero() { + txBuilder.SetFeeAmount(txOpt.FeeAmount) + } + } return nil } diff --git a/sdk/types/type.go b/sdk/types/type.go index e0b977722..24a905a97 100644 --- a/sdk/types/type.go +++ b/sdk/types/type.go @@ -5,6 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" ) +const Denom = "bnb" + type TxOption struct { Mode *tx.BroadcastMode GasLimit uint64 From e755c50f68bbe9faa387d5c7510d14f6fd52d48e Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Fri, 17 Feb 2023 16:16:13 +0800 Subject: [PATCH 2/7] feat: debug --- app/config.go | 2 +- sdk/client/test/config.go | 2 +- sdk/client/tx.go | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/config.go b/app/config.go index 55fea15db..5cdb10b5d 100644 --- a/app/config.go +++ b/app/config.go @@ -41,7 +41,7 @@ func NewDefaultAppConfig() *AppConfig { // own app.toml to override, or use this default value. // // In simapp, we set the min gas prices to 0. - srvCfg.MinGasPrices = "0stake" + srvCfg.MinGasPrices = "10bnb" return &AppConfig{ Config: *srvCfg, diff --git a/sdk/client/test/config.go b/sdk/client/test/config.go index af023ef6f..e2bad1f0c 100644 --- a/sdk/client/test/config.go +++ b/sdk/client/test/config.go @@ -1,7 +1,7 @@ package test const ( - TEST_PRIVATE_KEY = "3018f5ceec22c2a1389fe3a0933b52f3fc31450c5322002dd76477964797fb13" + TEST_PRIVATE_KEY = "e3938842a7ce2fe84826c697ec16703840601c7d20751a9617e0df38d083b814" TEST_ADDR = "0x76d244CE05c3De4BbC6fDd7F56379B145709ade9" TEST_ADDR2 = "0x5dEfC28ce1Ed331D56aB6F607f78708880e11Bea" TEST_ADDR3 = "0x593107F1D5D10A68D3C3722C35ADa2eb779D44A4" diff --git a/sdk/client/tx.go b/sdk/client/tx.go index 6ed2af885..484ca8681 100644 --- a/sdk/client/tx.go +++ b/sdk/client/tx.go @@ -2,6 +2,7 @@ package client import ( "context" + "fmt" "github.com/bnb-chain/greenfield/sdk/types" "github.com/cosmos/cosmos-sdk/client" @@ -193,14 +194,20 @@ func (c *GreenfieldClient) constructTxWithGas(msgs []sdk.Msg, txOpt *types.TxOpt return err } + fmt.Printf("gs info %s", simulateRes.GasInfo.String()) + gasLimit := simulateRes.GasInfo.GetGasUsed() gasPrice, err := sdk.ParseCoinsNormalized(simulateRes.GasInfo.GetMinGasPrices()) if err != nil { return err } + + fmt.Printf("gaslimit %d", gasLimit) + fmt.Printf("gasPrice %s", gasPrice.String()) + txBuilder.SetGasLimit(gasLimit) - price := gasPrice.AmountOf(types.Denom) - feeAmount := sdk.NewCoins(sdk.NewInt64Coin(types.Denom, sdk.NewInt(int64(gasLimit)).Mul(price).Int64())) + feeAmount := sdk.NewCoins(sdk.NewInt64Coin(types.Denom, sdk.NewInt(int64(gasLimit)).Mul(gasPrice[0].Amount).Int64())) + fmt.Printf("feeAmount %s", feeAmount.String()) txBuilder.SetFeeAmount(feeAmount) if txOpt != nil { if txOpt.GasLimit != 0 { From a142d2f562537e1577e607120dbcf8ee08d44a1b Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Fri, 17 Feb 2023 16:41:47 +0800 Subject: [PATCH 3/7] feat: check gas price --- sdk/client/tx.go | 31 +++++++++++++------------------ sdk/types/errors.go | 1 + 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/sdk/client/tx.go b/sdk/client/tx.go index 484ca8681..24e59a366 100644 --- a/sdk/client/tx.go +++ b/sdk/client/tx.go @@ -2,12 +2,11 @@ package client import ( "context" - "fmt" - "github.com/bnb-chain/greenfield/sdk/types" "github.com/cosmos/cosmos-sdk/client" clitx "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -194,29 +193,25 @@ func (c *GreenfieldClient) constructTxWithGas(msgs []sdk.Msg, txOpt *types.TxOpt return err } - fmt.Printf("gs info %s", simulateRes.GasInfo.String()) - gasLimit := simulateRes.GasInfo.GetGasUsed() + if txOpt != nil && txOpt.GasLimit != 0 { + gasLimit = txOpt.GasLimit + } gasPrice, err := sdk.ParseCoinsNormalized(simulateRes.GasInfo.GetMinGasPrices()) if err != nil { return err } - - fmt.Printf("gaslimit %d", gasLimit) - fmt.Printf("gasPrice %s", gasPrice.String()) - + if gasPrice.IsZero() { + return errors.Wrap(types.SimulatedGasPriceError, "gas price is 0 ") + } + feeAmount := sdk.NewCoins(sdk.NewInt64Coin("gweibnb", + sdk.NewInt(int64(gasLimit)).Mul(gasPrice[0].Amount).Int64()), + ) + if txOpt != nil && !txOpt.FeeAmount.IsZero() { + feeAmount = txOpt.FeeAmount + } txBuilder.SetGasLimit(gasLimit) - feeAmount := sdk.NewCoins(sdk.NewInt64Coin(types.Denom, sdk.NewInt(int64(gasLimit)).Mul(gasPrice[0].Amount).Int64())) - fmt.Printf("feeAmount %s", feeAmount.String()) txBuilder.SetFeeAmount(feeAmount) - if txOpt != nil { - if txOpt.GasLimit != 0 { - txBuilder.SetGasLimit(txOpt.GasLimit) - } - if !txOpt.FeeAmount.IsZero() { - txBuilder.SetFeeAmount(txOpt.FeeAmount) - } - } return nil } diff --git a/sdk/types/errors.go b/sdk/types/errors.go index 8f66cc6e2..d4dd178dc 100644 --- a/sdk/types/errors.go +++ b/sdk/types/errors.go @@ -5,4 +5,5 @@ import "errors" var ( KeyManagerNotInitError = errors.New("Key manager is not initialized yet ") ChainIdNotSetError = errors.New("ChainID is not set yet ") + SimulatedGasPriceError = errors.New("Simulated gas price is 0 ") ) From 7371dde7d291fa4254255ab31576e8ce074ebf14 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Fri, 17 Feb 2023 16:46:43 +0800 Subject: [PATCH 4/7] feat: renaming --- app/config.go | 2 +- sdk/client/tx.go | 10 +++++----- sdk/types/type.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/config.go b/app/config.go index 5cdb10b5d..55fea15db 100644 --- a/app/config.go +++ b/app/config.go @@ -41,7 +41,7 @@ func NewDefaultAppConfig() *AppConfig { // own app.toml to override, or use this default value. // // In simapp, we set the min gas prices to 0. - srvCfg.MinGasPrices = "10bnb" + srvCfg.MinGasPrices = "0stake" return &AppConfig{ Config: *srvCfg, diff --git a/sdk/client/tx.go b/sdk/client/tx.go index 24e59a366..c123bb16f 100644 --- a/sdk/client/tx.go +++ b/sdk/client/tx.go @@ -28,7 +28,7 @@ func (c *GreenfieldClient) BroadcastTx(msgs []sdk.Msg, txOpt *types.TxOption, op txBuilder := txConfig.NewTxBuilder() // txBuilder holds tx info - if err := c.constructTxWithGas(msgs, txOpt, txConfig, txBuilder); err != nil { + if err := c.constructTxWithGasInfo(msgs, txOpt, txConfig, txBuilder); err != nil { return nil, err } @@ -93,7 +93,7 @@ func (c *GreenfieldClient) simulateTx(txBytes []byte, opts ...grpc.CallOption) ( func (c *GreenfieldClient) SignTx(msgs []sdk.Msg, txOpt *types.TxOption) ([]byte, error) { txConfig := authtx.NewTxConfig(c.codec, []signing.SignMode{signing.SignMode_SIGN_MODE_EIP_712}) txBuilder := txConfig.NewTxBuilder() - if err := c.constructTxWithGas(msgs, txOpt, txConfig, txBuilder); err != nil { + if err := c.constructTxWithGasInfo(msgs, txOpt, txConfig, txBuilder); err != nil { return nil, err } return c.signTx(txConfig, txBuilder) @@ -179,7 +179,7 @@ func (c *GreenfieldClient) constructTx(msgs []sdk.Msg, txOpt *types.TxOption, tx return c.setSingerInfo(txBuilder) } -func (c *GreenfieldClient) constructTxWithGas(msgs []sdk.Msg, txOpt *types.TxOption, txConfig client.TxConfig, txBuilder client.TxBuilder) error { +func (c *GreenfieldClient) constructTxWithGasInfo(msgs []sdk.Msg, txOpt *types.TxOption, txConfig client.TxConfig, txBuilder client.TxBuilder) error { // construct a tx with txOpt excluding GasLimit and if err := c.constructTx(msgs, txOpt, txBuilder); err != nil { return err @@ -202,9 +202,9 @@ func (c *GreenfieldClient) constructTxWithGas(msgs []sdk.Msg, txOpt *types.TxOpt return err } if gasPrice.IsZero() { - return errors.Wrap(types.SimulatedGasPriceError, "gas price is 0 ") + return errors.Wrap(types.SimulatedGasPriceError, "gas price is 0. ") } - feeAmount := sdk.NewCoins(sdk.NewInt64Coin("gweibnb", + feeAmount := sdk.NewCoins(sdk.NewInt64Coin(types.Denom, sdk.NewInt(int64(gasLimit)).Mul(gasPrice[0].Amount).Int64()), ) if txOpt != nil && !txOpt.FeeAmount.IsZero() { diff --git a/sdk/types/type.go b/sdk/types/type.go index 24a905a97..6fc35b8f2 100644 --- a/sdk/types/type.go +++ b/sdk/types/type.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" ) -const Denom = "bnb" +const Denom = "gweibnb" type TxOption struct { Mode *tx.BroadcastMode From 0872fc03a5869d0bc2bbaedcc0c653e1f41e3591 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Sat, 18 Feb 2023 12:33:43 +0800 Subject: [PATCH 5/7] feat: fix denom type --- sdk/client/test/config.go | 4 ++-- sdk/types/type.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/client/test/config.go b/sdk/client/test/config.go index e2bad1f0c..d77e5e784 100644 --- a/sdk/client/test/config.go +++ b/sdk/client/test/config.go @@ -1,7 +1,7 @@ package test const ( - TEST_PRIVATE_KEY = "e3938842a7ce2fe84826c697ec16703840601c7d20751a9617e0df38d083b814" + TEST_PRIVATE_KEY = "8da3b29b606557eea3a4a1ed08d75441c942862f15fef4955538e3d2c0b38b89" TEST_ADDR = "0x76d244CE05c3De4BbC6fDd7F56379B145709ade9" TEST_ADDR2 = "0x5dEfC28ce1Ed331D56aB6F607f78708880e11Bea" TEST_ADDR3 = "0x593107F1D5D10A68D3C3722C35ADa2eb779D44A4" @@ -10,5 +10,5 @@ const ( TEST_GRPC_ADDR = "localhost:9090" TEST_RPC_ADDR = "http://0.0.0.0:26750" TEST_CHAIN_ID = "greenfield_9000-121" - TEST_TOKEN_NAME = "bnb" + TEST_TOKEN_NAME = "BNB" ) diff --git a/sdk/types/type.go b/sdk/types/type.go index 6fc35b8f2..38f216f38 100644 --- a/sdk/types/type.go +++ b/sdk/types/type.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" ) -const Denom = "gweibnb" +const Denom = "BNB" type TxOption struct { Mode *tx.BroadcastMode From 9f68ab456de7985cad5c8c0f089c55fd00c0bdab Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Mon, 20 Feb 2023 10:39:49 +0800 Subject: [PATCH 6/7] feat: fix ci --- e2e/tests/payment_test.go | 1 - sdk/client/gnfd_client.go | 13 +++++++------ sdk/client/gnfd_client_option.go | 3 ++- sdk/client/tendermint_client_test.go | 3 ++- sdk/client/test/bank/client_query_test.go | 5 +++-- sdk/client/test/config.go | 2 +- sdk/client/test/crosschain/client_query_test.go | 5 +++-- sdk/client/test/gashub/client_query_test.go | 5 +++-- sdk/client/test/oracle/client_query_test.go | 5 +++-- sdk/client/test/staking/client_query_test.go | 5 +++-- sdk/client/tx.go | 3 +-- sdk/client/tx_test.go | 7 ++++--- sdk/keys/key_manager.go | 8 +++----- sdk/types/codec.go | 9 +++++---- sdk/types/errors.go | 4 +++- sdk/types/msgTypes.go | 9 +++++---- 16 files changed, 48 insertions(+), 39 deletions(-) diff --git a/e2e/tests/payment_test.go b/e2e/tests/payment_test.go index 71955699b..e8755fa87 100644 --- a/e2e/tests/payment_test.go +++ b/e2e/tests/payment_test.go @@ -1,6 +1,5 @@ package tests -// Basic imports import ( "context" "testing" diff --git a/sdk/client/gnfd_client.go b/sdk/client/gnfd_client.go index 35b3f1dc2..24a476eb6 100644 --- a/sdk/client/gnfd_client.go +++ b/sdk/client/gnfd_client.go @@ -3,12 +3,6 @@ package client import ( _ "encoding/json" - "github.com/bnb-chain/greenfield/sdk/keys" - "github.com/bnb-chain/greenfield/sdk/types" - bridgetypes "github.com/bnb-chain/greenfield/x/bridge/types" - paymenttypes "github.com/bnb-chain/greenfield/x/payment/types" - sptypes "github.com/bnb-chain/greenfield/x/sp/types" - storagetypes "github.com/bnb-chain/greenfield/x/storage/types" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -25,6 +19,13 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "google.golang.org/grpc" + + "github.com/bnb-chain/greenfield/sdk/keys" + "github.com/bnb-chain/greenfield/sdk/types" + bridgetypes "github.com/bnb-chain/greenfield/x/bridge/types" + paymenttypes "github.com/bnb-chain/greenfield/x/payment/types" + sptypes "github.com/bnb-chain/greenfield/x/sp/types" + storagetypes "github.com/bnb-chain/greenfield/x/storage/types" ) // AuthQueryClient is a type to define the auth types Query Client diff --git a/sdk/client/gnfd_client_option.go b/sdk/client/gnfd_client_option.go index 94f5e768c..0440911d3 100644 --- a/sdk/client/gnfd_client_option.go +++ b/sdk/client/gnfd_client_option.go @@ -1,8 +1,9 @@ package client import ( - "github.com/bnb-chain/greenfield/sdk/keys" "google.golang.org/grpc" + + "github.com/bnb-chain/greenfield/sdk/keys" ) // GreenfieldClientOption configures how we set up the greenfield client. diff --git a/sdk/client/tendermint_client_test.go b/sdk/client/tendermint_client_test.go index af7fe741a..75606f3ce 100644 --- a/sdk/client/tendermint_client_test.go +++ b/sdk/client/tendermint_client_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - "github.com/bnb-chain/greenfield/sdk/client/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/types" + + "github.com/bnb-chain/greenfield/sdk/client/test" ) func TestGetABCIInfo(t *testing.T) { diff --git a/sdk/client/test/bank/client_query_test.go b/sdk/client/test/bank/client_query_test.go index 2799fe095..c1e327b4a 100644 --- a/sdk/client/test/bank/client_query_test.go +++ b/sdk/client/test/bank/client_query_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/stretchr/testify/assert" + gnfdclient "github.com/bnb-chain/greenfield/sdk/client" "github.com/bnb-chain/greenfield/sdk/client/test" "github.com/bnb-chain/greenfield/sdk/keys" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/assert" ) func TestBankBalance(t *testing.T) { diff --git a/sdk/client/test/config.go b/sdk/client/test/config.go index d77e5e784..ac87cd944 100644 --- a/sdk/client/test/config.go +++ b/sdk/client/test/config.go @@ -1,7 +1,7 @@ package test const ( - TEST_PRIVATE_KEY = "8da3b29b606557eea3a4a1ed08d75441c942862f15fef4955538e3d2c0b38b89" + TEST_PRIVATE_KEY = "6752fbe14067d97ea9cda842327d382a568bd5a38e5c0365ebc439e901716f89" TEST_ADDR = "0x76d244CE05c3De4BbC6fDd7F56379B145709ade9" TEST_ADDR2 = "0x5dEfC28ce1Ed331D56aB6F607f78708880e11Bea" TEST_ADDR3 = "0x593107F1D5D10A68D3C3722C35ADa2eb779D44A4" diff --git a/sdk/client/test/crosschain/client_query_test.go b/sdk/client/test/crosschain/client_query_test.go index 963fc0296..29c10b389 100644 --- a/sdk/client/test/crosschain/client_query_test.go +++ b/sdk/client/test/crosschain/client_query_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - gnfdclient "github.com/bnb-chain/greenfield/sdk/client" - "github.com/bnb-chain/greenfield/sdk/client/test" crosschaintypes "github.com/cosmos/cosmos-sdk/x/crosschain/types" "github.com/stretchr/testify/assert" + + gnfdclient "github.com/bnb-chain/greenfield/sdk/client" + "github.com/bnb-chain/greenfield/sdk/client/test" ) func TestCrosschainParams(t *testing.T) { diff --git a/sdk/client/test/gashub/client_query_test.go b/sdk/client/test/gashub/client_query_test.go index a6d9741a3..1f5582d46 100644 --- a/sdk/client/test/gashub/client_query_test.go +++ b/sdk/client/test/gashub/client_query_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - gnfdclient "github.com/bnb-chain/greenfield/sdk/client" - "github.com/bnb-chain/greenfield/sdk/client/test" gashubtypes "github.com/cosmos/cosmos-sdk/x/gashub/types" "github.com/stretchr/testify/assert" + + gnfdclient "github.com/bnb-chain/greenfield/sdk/client" + "github.com/bnb-chain/greenfield/sdk/client/test" ) func TestGashubParams(t *testing.T) { diff --git a/sdk/client/test/oracle/client_query_test.go b/sdk/client/test/oracle/client_query_test.go index ef3587836..128d72b70 100644 --- a/sdk/client/test/oracle/client_query_test.go +++ b/sdk/client/test/oracle/client_query_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - gnfdclient "github.com/bnb-chain/greenfield/sdk/client" - "github.com/bnb-chain/greenfield/sdk/client/test" oracletypes "github.com/cosmos/cosmos-sdk/x/oracle/types" "github.com/stretchr/testify/assert" + + gnfdclient "github.com/bnb-chain/greenfield/sdk/client" + "github.com/bnb-chain/greenfield/sdk/client/test" ) func TestOracleParams(t *testing.T) { diff --git a/sdk/client/test/staking/client_query_test.go b/sdk/client/test/staking/client_query_test.go index 57c2f6ad5..1e021cb14 100644 --- a/sdk/client/test/staking/client_query_test.go +++ b/sdk/client/test/staking/client_query_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - gnfdclient "github.com/bnb-chain/greenfield/sdk/client" - "github.com/bnb-chain/greenfield/sdk/client/test" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/assert" + + gnfdclient "github.com/bnb-chain/greenfield/sdk/client" + "github.com/bnb-chain/greenfield/sdk/client/test" ) func TestStakingValidator(t *testing.T) { diff --git a/sdk/client/tx.go b/sdk/client/tx.go index c123bb16f..e200101a8 100644 --- a/sdk/client/tx.go +++ b/sdk/client/tx.go @@ -6,7 +6,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" clitx "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -202,7 +201,7 @@ func (c *GreenfieldClient) constructTxWithGasInfo(msgs []sdk.Msg, txOpt *types.T return err } if gasPrice.IsZero() { - return errors.Wrap(types.SimulatedGasPriceError, "gas price is 0. ") + return types.SimulatedGasPriceError } feeAmount := sdk.NewCoins(sdk.NewInt64Coin(types.Denom, sdk.NewInt(int64(gasLimit)).Mul(gasPrice[0].Amount).Int64()), diff --git a/sdk/client/tx_test.go b/sdk/client/tx_test.go index d7e0a7842..23fdf0907 100644 --- a/sdk/client/tx_test.go +++ b/sdk/client/tx_test.go @@ -3,15 +3,16 @@ package client import ( "testing" - "github.com/bnb-chain/greenfield/sdk/client/test" - "github.com/bnb-chain/greenfield/sdk/keys" - "github.com/bnb-chain/greenfield/sdk/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/assert" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + + "github.com/bnb-chain/greenfield/sdk/client/test" + "github.com/bnb-chain/greenfield/sdk/keys" + "github.com/bnb-chain/greenfield/sdk/types" ) func TestSendTokenSucceedWithSimulatedGas(t *testing.T) { diff --git a/sdk/keys/key_manager.go b/sdk/keys/key_manager.go index 345d204fd..4f419353f 100644 --- a/sdk/keys/key_manager.go +++ b/sdk/keys/key_manager.go @@ -3,16 +3,14 @@ package keys import ( "encoding/hex" "fmt" + "strings" "github.com/cosmos/cosmos-sdk/crypto/hd" ctypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/evmos/ethermint/crypto/ethsecp256k1" - ethHd "github.com/evmos/ethermint/crypto/hd" - - "strings" - "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/go-bip39" + "github.com/evmos/ethermint/crypto/ethsecp256k1" + ethHd "github.com/evmos/ethermint/crypto/hd" ) const ( diff --git a/sdk/types/codec.go b/sdk/types/codec.go index 31c23907d..d05b41855 100644 --- a/sdk/types/codec.go +++ b/sdk/types/codec.go @@ -1,10 +1,6 @@ package types import ( - bridgetypes "github.com/bnb-chain/greenfield/x/bridge/types" - paymenttypes "github.com/bnb-chain/greenfield/x/payment/types" - sptypes "github.com/bnb-chain/greenfield/x/sp/types" - storagetypes "github.com/bnb-chain/greenfield/x/storage/types" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -17,6 +13,11 @@ import ( proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + bridgetypes "github.com/bnb-chain/greenfield/x/bridge/types" + paymenttypes "github.com/bnb-chain/greenfield/x/payment/types" + sptypes "github.com/bnb-chain/greenfield/x/sp/types" + storagetypes "github.com/bnb-chain/greenfield/x/storage/types" ) func Cdc() *codec.ProtoCodec { diff --git a/sdk/types/errors.go b/sdk/types/errors.go index d4dd178dc..e50a14fd5 100644 --- a/sdk/types/errors.go +++ b/sdk/types/errors.go @@ -1,6 +1,8 @@ package types -import "errors" +import ( + "errors" +) var ( KeyManagerNotInitError = errors.New("Key manager is not initialized yet ") diff --git a/sdk/types/msgTypes.go b/sdk/types/msgTypes.go index db3334ae8..640896a8d 100644 --- a/sdk/types/msgTypes.go +++ b/sdk/types/msgTypes.go @@ -1,10 +1,6 @@ package types import ( - bridgetypes "github.com/bnb-chain/greenfield/x/bridge/types" - paymenttypes "github.com/bnb-chain/greenfield/x/payment/types" - sptypes "github.com/bnb-chain/greenfield/x/sp/types" - storagetypes "github.com/bnb-chain/greenfield/x/storage/types" authztypes "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -13,6 +9,11 @@ import ( oracletypes "github.com/cosmos/cosmos-sdk/x/oracle/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + bridgetypes "github.com/bnb-chain/greenfield/x/bridge/types" + paymenttypes "github.com/bnb-chain/greenfield/x/payment/types" + sptypes "github.com/bnb-chain/greenfield/x/sp/types" + storagetypes "github.com/bnb-chain/greenfield/x/storage/types" ) type ( From d43196ee670d11fbfbeef68d7d918e34f364b285 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Mon, 20 Feb 2023 11:24:57 +0800 Subject: [PATCH 7/7] feat: lint --- sdk/client/test/config.go | 2 +- sdk/client/tx.go | 4 +++- sdk/client/tx_test.go | 9 ++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sdk/client/test/config.go b/sdk/client/test/config.go index ac87cd944..b897e1a97 100644 --- a/sdk/client/test/config.go +++ b/sdk/client/test/config.go @@ -1,7 +1,7 @@ package test const ( - TEST_PRIVATE_KEY = "6752fbe14067d97ea9cda842327d382a568bd5a38e5c0365ebc439e901716f89" + TEST_PRIVATE_KEY = "ff0911d998e6f12cf4b0a88d90cc411aa3be06c9dc5a2b35834f0e25a44e2275" TEST_ADDR = "0x76d244CE05c3De4BbC6fDd7F56379B145709ade9" TEST_ADDR2 = "0x5dEfC28ce1Ed331D56aB6F607f78708880e11Bea" TEST_ADDR3 = "0x593107F1D5D10A68D3C3722C35ADa2eb779D44A4" diff --git a/sdk/client/tx.go b/sdk/client/tx.go index e200101a8..5eb1d1cf6 100644 --- a/sdk/client/tx.go +++ b/sdk/client/tx.go @@ -2,7 +2,7 @@ package client import ( "context" - "github.com/bnb-chain/greenfield/sdk/types" + "github.com/cosmos/cosmos-sdk/client" clitx "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,6 +12,8 @@ import ( authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "google.golang.org/grpc" + + "github.com/bnb-chain/greenfield/sdk/types" ) type TransactionClient interface { diff --git a/sdk/client/tx_test.go b/sdk/client/tx_test.go index 23fdf0907..5cbe9adf7 100644 --- a/sdk/client/tx_test.go +++ b/sdk/client/tx_test.go @@ -43,11 +43,10 @@ func TestSendTokenWithTxOptionSucceed(t *testing.T) { assert.NoError(t, err) mode := tx.BroadcastMode_BROADCAST_MODE_BLOCK txOpt := &types.TxOption{ - Mode: &mode, - GasLimit: 123456, - Memo: "test", - FeeAmount: sdk.NewCoins(sdk.NewInt64Coin(test.TEST_TOKEN_NAME, 1)), - FeePayer: payerAddr, + Mode: &mode, + GasLimit: 123456, + Memo: "test", + FeePayer: payerAddr, } response, err := gnfdCli.BroadcastTx([]sdk.Msg{transfer}, txOpt) assert.NoError(t, err)