-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update contract rent deposit logic + add query endpoint (#625)
* Update contract rent deposit logic + add query endpoint * fmt --------- Co-authored-by: Cyson <cyson@Cysons-MBP.attlocal.net>
- Loading branch information
Xingchen Liao
and
Cyson
authored
Mar 3, 2023
1 parent
a19ab6c
commit 8778cb7
Showing
11 changed files
with
814 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package query | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/sei-protocol/sei-chain/x/dex/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdGetRegisteredContract() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "get-registered-contract [contract address]", | ||
Short: "Query Registered Contract", | ||
Long: strings.TrimSpace(` | ||
List the registered contract information specified by contract address. | ||
`), | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
contractAddr := args[0] | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
params := &types.QueryRegisteredContractRequest{ | ||
ContractAddr: contractAddr, | ||
} | ||
|
||
res, err := queryClient.GetRegisteredContract(cmd.Context(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/sei-protocol/sei-chain/x/dex/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k KeeperWrapper) GetRegisteredContract(c context.Context, req *types.QueryRegisteredContractRequest) (*types.QueryRegisteredContractResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
ctx := sdk.UnwrapSDKContext(c) | ||
|
||
contractInfo, err := k.GetContract(ctx, req.ContractAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.QueryRegisteredContractResponse{ContractInfo: &contractInfo}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package query_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
keepertest "github.com/sei-protocol/sei-chain/testutil/keeper" | ||
"github.com/sei-protocol/sei-chain/x/dex/keeper/query" | ||
"github.com/sei-protocol/sei-chain/x/dex/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRegisteredContractQuery(t *testing.T) { | ||
keeper, ctx := keepertest.DexKeeper(t) | ||
wrapper := query.KeeperWrapper{Keeper: keeper} | ||
wctx := sdk.WrapSDKContext(ctx) | ||
expectedContractInfo := types.ContractInfoV2{ | ||
Creator: keepertest.TestAccount, | ||
ContractAddr: keepertest.TestContract, | ||
CodeId: 1, | ||
RentBalance: 1000000, | ||
} | ||
err := keeper.SetContract(ctx, &types.ContractInfoV2{ | ||
Creator: keepertest.TestAccount, | ||
ContractAddr: keepertest.TestContract, | ||
CodeId: 1, | ||
RentBalance: 1000000, | ||
}) | ||
require.NoError(t, err) | ||
|
||
request := types.QueryRegisteredContractRequest{ | ||
ContractAddr: keepertest.TestContract, | ||
} | ||
expectedResponse := types.QueryRegisteredContractResponse{ | ||
ContractInfo: &expectedContractInfo, | ||
} | ||
t.Run("Registered Contract query", func(t *testing.T) { | ||
response, err := wrapper.GetRegisteredContract(wctx, &request) | ||
require.NoError(t, err) | ||
require.Equal(t, expectedResponse, *response) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.