Skip to content

Commit

Permalink
refactor: Remove deprecated sdk.WrapSDKContext
Browse files Browse the repository at this point in the history
The sdk.WrapSDKContext function is deprecated and has been removed from the codebase. This change refactors the affected code to use the recommended alternatives, ensuring compatibility with future SDK versions and maintaining code quality.
  • Loading branch information
poorphd committed Jul 1, 2024
1 parent 868b183 commit 8772522
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 85 deletions.
8 changes: 4 additions & 4 deletions x/coinswap/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func (s *TestSuite) TestGRPCParams() {
resp, err := s.queryClient.Params(sdk.WrapSDKContext(s.ctx), &types.QueryParamsRequest{})
resp, err := s.queryClient.Params(s.ctx, &types.QueryParamsRequest{})
s.Require().NoError(err)
s.Require().Equal(s.keeper.GetParams(s.ctx), resp.Params)
}
Expand All @@ -17,7 +17,7 @@ func (s *TestSuite) TestGRPCPool() {
poolId := types.GetPoolId(denomBTC)
pool, _ := s.app.CoinswapKeeper.GetPool(s.ctx, poolId)

resp, err := s.queryClient.LiquidityPool(sdk.WrapSDKContext(s.ctx), &types.QueryLiquidityPoolRequest{LptDenom: pool.LptDenom})
resp, err := s.queryClient.LiquidityPool(s.ctx, &types.QueryLiquidityPoolRequest{LptDenom: pool.LptDenom})
s.Require().NoError(err)
s.Require().Equal(pool.Id, resp.Pool.Id)
s.Require().Equal(pool.EscrowAddress, resp.Pool.EscrowAddress)
Expand All @@ -36,12 +36,12 @@ func (s *TestSuite) TestGRPCPool() {

func (s *TestSuite) TestGRPCPools() {
_, _ = createReservePool(s, denomBTC)
resp, err := s.queryClient.LiquidityPools(sdk.WrapSDKContext(s.ctx), &types.QueryLiquidityPoolsRequest{})
resp, err := s.queryClient.LiquidityPools(s.ctx, &types.QueryLiquidityPoolsRequest{})
s.Require().NoError(err)
s.Require().Len(resp.Pools, 1)

_, _ = createReservePool(s, denomETH)
resp, err = s.queryClient.LiquidityPools(sdk.WrapSDKContext(s.ctx), &types.QueryLiquidityPoolsRequest{})
resp, err = s.queryClient.LiquidityPools(s.ctx, &types.QueryLiquidityPoolsRequest{})
s.Require().NoError(err)
s.Require().Len(resp.Pools, 2)
}
25 changes: 8 additions & 17 deletions x/csr/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package keeper_test

import (
"github.com/Canto-Network/Canto/v7/x/csr/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/evmos/ethermint/tests"
)

// Special edge case for when the request made is null, cannot be routed to the query client
func (suite *KeeperTestSuite) TestKeeperCSRs() {
suite.SetupTest()
ctx := sdk.WrapSDKContext(suite.ctx)
res, err := suite.app.CSRKeeper.CSRs(ctx, nil)
res, err := suite.app.CSRKeeper.CSRs(suite.ctx, nil)
suite.Require().Error(err)
suite.Require().Nil(res)
}
Expand Down Expand Up @@ -114,10 +112,9 @@ func (suite *KeeperTestSuite) TestCSRs() {
suite.Run(tc.name, func() {
suite.SetupTest()

ctx := sdk.WrapSDKContext(suite.ctx)
tc.prepare()

response, err := suite.queryClient.CSRs(ctx, request)
response, err := suite.queryClient.CSRs(suite.ctx, request)
if tc.pass {
suite.Require().NoError(err)
suite.Require().Equal(expectedResponse.Pagination.Total, response.Pagination.Total)
Expand All @@ -132,8 +129,7 @@ func (suite *KeeperTestSuite) TestCSRs() {
// Special edge case for when the request made is null, cannot be routed to the query client
func (suite *KeeperTestSuite) TestKeeperCSRsByNFT() {
suite.SetupTest()
ctx := sdk.WrapSDKContext(suite.ctx)
res, err := suite.app.CSRKeeper.CSRByNFT(ctx, nil)
res, err := suite.app.CSRKeeper.CSRByNFT(suite.ctx, nil)
suite.Require().Error(err)
suite.Require().Nil(res)
}
Expand Down Expand Up @@ -190,10 +186,9 @@ func (suite *KeeperTestSuite) TestCSRByNFT() {
suite.Run(tc.name, func() {
suite.SetupTest()

ctx := sdk.WrapSDKContext(suite.ctx)
tc.prepare()

response, err := suite.queryClient.CSRByNFT(ctx, request)
response, err := suite.queryClient.CSRByNFT(suite.ctx, request)
if tc.pass {
suite.Require().NoError(err)
} else {
Expand All @@ -207,8 +202,7 @@ func (suite *KeeperTestSuite) TestCSRByNFT() {
// Special edge case for when the request made is null, cannot be routed to the query client
func (suite *KeeperTestSuite) TestKeeperCSRsByContract() {
suite.SetupTest()
ctx := sdk.WrapSDKContext(suite.ctx)
res, err := suite.app.CSRKeeper.CSRByContract(ctx, nil)
res, err := suite.app.CSRKeeper.CSRByContract(suite.ctx, nil)
suite.Require().Error(err)
suite.Require().Nil(res)
}
Expand Down Expand Up @@ -284,10 +278,9 @@ func (suite *KeeperTestSuite) TestCSRByContract() {
suite.Run(tc.name, func() {
suite.SetupTest()

ctx := sdk.WrapSDKContext(suite.ctx)
tc.prepare()

response, err := suite.queryClient.CSRByContract(ctx, request)
response, err := suite.queryClient.CSRByContract(suite.ctx, request)
if tc.pass {
suite.Require().NoError(err)
} else {
Expand All @@ -300,24 +293,22 @@ func (suite *KeeperTestSuite) TestCSRByContract() {

// Test the query service for params
func (suite *KeeperTestSuite) TestQueryParams() {
ctx := sdk.WrapSDKContext(suite.ctx)
expectedParams := types.DefaultParams()
expectedParams.EnableCsr = true

res, err := suite.queryClient.Params(ctx, &types.QueryParamsRequest{})
res, err := suite.queryClient.Params(suite.ctx, &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().Equal(expectedParams, res.Params)
}

// Test the query service that retrieves the turnstile address
func (suite *KeeperTestSuite) TestQueryTurnstile() {
suite.Commit()
ctx := sdk.WrapSDKContext(suite.ctx)

address, found := suite.app.CSRKeeper.GetTurnstile(suite.ctx)
suite.Require().True(found)

res, err := suite.queryClient.Turnstile(ctx, &types.QueryTurnstileRequest{})
res, err := suite.queryClient.Turnstile(suite.ctx, &types.QueryTurnstileRequest{})
suite.Require().NoError(err)
suite.Require().Equal(address.String(), res.Address)
}
4 changes: 1 addition & 3 deletions x/epochs/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/Canto-Network/Canto/v7/x/epochs/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
)

Expand Down Expand Up @@ -182,10 +181,9 @@ func (suite *KeeperTestSuite) TestCurrentEpoch() {
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
suite.SetupTest() // reset

ctx := sdk.WrapSDKContext(suite.ctx)
tc.malleate()

res, err := suite.queryClient.CurrentEpoch(ctx, req)
res, err := suite.queryClient.CurrentEpoch(suite.ctx, req)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(expRes, res)
Expand Down
4 changes: 2 additions & 2 deletions x/erc20/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"math/big"

errorsmod "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -183,7 +183,7 @@ func (k Keeper) CallEVMWithData(
return nil, errorsmod.Wrapf(sdkerrors.ErrJSONMarshal, "failed to marshal tx args: %s", err.Error())
}

gasRes, err := k.evmKeeper.EstimateGas(sdk.WrapSDKContext(ctx), &evmtypes.EthCallRequest{
gasRes, err := k.evmKeeper.EstimateGas(ctx, &evmtypes.EthCallRequest{
Args: args,
GasCap: config.DefaultGasCap,
})
Expand Down
3 changes: 1 addition & 2 deletions x/erc20/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ func (suite *KeeperTestSuite) TestEvmHooksRegisteredCoin() {
sender,
)

ctx := sdk.WrapSDKContext(suite.ctx)
_, err := suite.app.Erc20Keeper.ConvertCoin(ctx, convertCoin)
_, err := suite.app.Erc20Keeper.ConvertCoin(suite.ctx, convertCoin)
suite.Require().NoError(err, tc.name)
suite.Commit()

Expand Down
10 changes: 3 additions & 7 deletions x/erc20/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper_test
import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/evmos/ethermint/tests"

Expand Down Expand Up @@ -66,10 +65,9 @@ func (suite *KeeperTestSuite) TestTokenPairs() {
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
suite.SetupTest() // reset

ctx := sdk.WrapSDKContext(suite.ctx)
tc.malleate()

res, err := suite.queryClient.TokenPairs(ctx, req)
res, err := suite.queryClient.TokenPairs(suite.ctx, req)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(expRes.Pagination, res.Pagination)
Expand Down Expand Up @@ -146,10 +144,9 @@ func (suite *KeeperTestSuite) TestTokenPair() {
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
suite.SetupTest() // reset

ctx := sdk.WrapSDKContext(suite.ctx)
tc.malleate()

res, err := suite.queryClient.TokenPair(ctx, req)
res, err := suite.queryClient.TokenPair(suite.ctx, req)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(expRes, res)
Expand All @@ -161,10 +158,9 @@ func (suite *KeeperTestSuite) TestTokenPair() {
}

func (suite *KeeperTestSuite) TestQueryParams() {
ctx := sdk.WrapSDKContext(suite.ctx)
expParams := types.DefaultParams()

res, err := suite.queryClient.Params(ctx, &types.QueryParamsRequest{})
res, err := suite.queryClient.Params(suite.ctx, &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().Equal(expParams, res.Params)
}
20 changes: 8 additions & 12 deletions x/erc20/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ func (suite *KeeperTestSuite) MintFeeCollector(coins sdk.Coins) {

// DeployContract deploys the ERC20MinterBurnerDecimalsContract.
func (suite *KeeperTestSuite) DeployContract(name, symbol string, decimals uint8) (common.Address, error) {
ctx := sdk.WrapSDKContext(suite.ctx)
chainID := suite.app.EvmKeeper.ChainID()

ctorArgs, err := contracts.ERC20MinterBurnerDecimalsContract.ABI.Pack("", name, symbol, decimals)
Expand All @@ -225,7 +224,7 @@ func (suite *KeeperTestSuite) DeployContract(name, symbol string, decimals uint8
return common.Address{}, err
}

res, err := suite.queryClientEvm.EstimateGas(ctx, &evm.EthCallRequest{
res, err := suite.queryClientEvm.EstimateGas(suite.ctx, &evm.EthCallRequest{
Args: args,
GasCap: uint64(config.DefaultGasCap),
})
Expand Down Expand Up @@ -253,7 +252,7 @@ func (suite *KeeperTestSuite) DeployContract(name, symbol string, decimals uint8
return common.Address{}, err
}

rsp, err := suite.app.EvmKeeper.EthereumTx(ctx, erc20DeployTx)
rsp, err := suite.app.EvmKeeper.EthereumTx(suite.ctx, erc20DeployTx)
if err != nil {
return common.Address{}, err
}
Expand All @@ -263,7 +262,6 @@ func (suite *KeeperTestSuite) DeployContract(name, symbol string, decimals uint8
}

func (suite *KeeperTestSuite) DeployContractMaliciousDelayed(name string, symbol string) common.Address {
ctx := sdk.WrapSDKContext(suite.ctx)
chainID := suite.app.EvmKeeper.ChainID()

ctorArgs, err := contracts.ERC20MaliciousDelayedContract.ABI.Pack("", big.NewInt(1000000000000000000))
Expand All @@ -276,7 +274,7 @@ func (suite *KeeperTestSuite) DeployContractMaliciousDelayed(name string, symbol
})
suite.Require().NoError(err)

res, err := suite.queryClientEvm.EstimateGas(ctx, &evm.EthCallRequest{
res, err := suite.queryClientEvm.EstimateGas(suite.ctx, &evm.EthCallRequest{
Args: args,
GasCap: uint64(config.DefaultGasCap),
})
Expand All @@ -299,14 +297,13 @@ func (suite *KeeperTestSuite) DeployContractMaliciousDelayed(name string, symbol
erc20DeployTx.From = suite.address.Hex()
err = erc20DeployTx.Sign(ethtypes.LatestSignerForChainID(chainID), suite.signer)
suite.Require().NoError(err)
rsp, err := suite.app.EvmKeeper.EthereumTx(ctx, erc20DeployTx)
rsp, err := suite.app.EvmKeeper.EthereumTx(suite.ctx, erc20DeployTx)
suite.Require().NoError(err)
suite.Require().Empty(rsp.VmError)
return crypto.CreateAddress(suite.address, nonce)
}

func (suite *KeeperTestSuite) DeployContractDirectBalanceManipulation(name string, symbol string) common.Address {
ctx := sdk.WrapSDKContext(suite.ctx)
chainID := suite.app.EvmKeeper.ChainID()

ctorArgs, err := contracts.ERC20DirectBalanceManipulationContract.ABI.Pack("", big.NewInt(1000000000000000000))
Expand All @@ -319,7 +316,7 @@ func (suite *KeeperTestSuite) DeployContractDirectBalanceManipulation(name strin
})
suite.Require().NoError(err)

res, err := suite.queryClientEvm.EstimateGas(ctx, &evm.EthCallRequest{
res, err := suite.queryClientEvm.EstimateGas(suite.ctx, &evm.EthCallRequest{
Args: args,
GasCap: uint64(config.DefaultGasCap),
})
Expand All @@ -342,7 +339,7 @@ func (suite *KeeperTestSuite) DeployContractDirectBalanceManipulation(name strin
erc20DeployTx.From = suite.address.Hex()
err = erc20DeployTx.Sign(ethtypes.LatestSignerForChainID(chainID), suite.signer)
suite.Require().NoError(err)
rsp, err := suite.app.EvmKeeper.EthereumTx(ctx, erc20DeployTx)
rsp, err := suite.app.EvmKeeper.EthereumTx(suite.ctx, erc20DeployTx)
suite.Require().NoError(err)
suite.Require().Empty(rsp.VmError)
return crypto.CreateAddress(suite.address, nonce)
Expand Down Expand Up @@ -402,12 +399,11 @@ func (suite *KeeperTestSuite) GrantERC20Token(contractAddr, from, to common.Addr
}

func (suite *KeeperTestSuite) sendTx(contractAddr, from common.Address, transferData []byte) *evm.MsgEthereumTx {
ctx := sdk.WrapSDKContext(suite.ctx)
chainID := suite.app.EvmKeeper.ChainID()

args, err := json.Marshal(&evm.TransactionArgs{To: &contractAddr, From: &from, Data: (*hexutil.Bytes)(&transferData)})
suite.Require().NoError(err)
res, err := suite.queryClientEvm.EstimateGas(ctx, &evm.EthCallRequest{
res, err := suite.queryClientEvm.EstimateGas(suite.ctx, &evm.EthCallRequest{
Args: args,
GasCap: uint64(config.DefaultGasCap),
})
Expand All @@ -434,7 +430,7 @@ func (suite *KeeperTestSuite) sendTx(contractAddr, from common.Address, transfer
ercTransferTx.From = suite.address.Hex()
err = ercTransferTx.Sign(ethtypes.LatestSignerForChainID(chainID), suite.signer)
suite.Require().NoError(err)
rsp, err := suite.app.EvmKeeper.EthereumTx(ctx, ercTransferTx)
rsp, err := suite.app.EvmKeeper.EthereumTx(suite.ctx, ercTransferTx)
suite.Require().NoError(err)
suite.Require().Empty(rsp.VmError)
return ercTransferTx
Expand Down
Loading

0 comments on commit 8772522

Please sign in to comment.