[todo] mv tests depending on removed sdk testutils
This commit is contained in:
parent
fce00cb5a7
commit
9b1e34a089
@ -1,30 +0,0 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
integrationTest "git.vdb.to/cerc-io/laconicd/tests/integration"
|
||||
types "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
)
|
||||
|
||||
type KeeperTestSuite struct {
|
||||
suite.Suite
|
||||
integrationTest.TestFixture
|
||||
|
||||
queryClient types.QueryClient
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) SetupTest() {
|
||||
err := kts.TestFixture.Setup(kts.T())
|
||||
assert.Nil(kts.T(), err)
|
||||
|
||||
qr := kts.App.QueryHelper()
|
||||
kts.queryClient = types.NewQueryClient(qr)
|
||||
}
|
||||
|
||||
func TestAuctionKeeperTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(KeeperTestSuite))
|
||||
}
|
@ -1,356 +0,0 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
types "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
)
|
||||
|
||||
const testCommitHash = "71D8CF34026E32A3A34C2C2D4ADF25ABC8D7943A4619761BE27F196603D91B9D"
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcQueryParams() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryParamsRequest
|
||||
}{
|
||||
{
|
||||
"fetch params",
|
||||
&types.QueryParamsRequest{},
|
||||
},
|
||||
}
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
resp, err := kts.queryClient.Params(context.Background(), test.req)
|
||||
kts.Require().Nil(err)
|
||||
kts.Require().Equal(*(resp.Params), types.DefaultParams())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcGetAuction() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryGetAuctionRequest
|
||||
createAuction bool
|
||||
}{
|
||||
{
|
||||
"fetch auction with empty auction ID",
|
||||
&types.QueryGetAuctionRequest{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"fetch auction with valid auction ID",
|
||||
&types.QueryGetAuctionRequest{},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
var expectedAuction types.Auction
|
||||
if test.createAuction {
|
||||
auction, _, err := kts.createAuctionAndCommitBid(false)
|
||||
kts.Require().Nil(err)
|
||||
test.req.Id = auction.Id
|
||||
expectedAuction = *auction
|
||||
}
|
||||
|
||||
resp, err := kts.queryClient.GetAuction(context.Background(), test.req)
|
||||
if test.createAuction {
|
||||
kts.Require().Nil(err)
|
||||
kts.Require().NotNil(resp.GetAuction())
|
||||
kts.Require().EqualExportedValues(expectedAuction, *(resp.GetAuction()))
|
||||
} else {
|
||||
kts.Require().NotNil(err)
|
||||
kts.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcGetAllAuctions() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryAuctionsRequest
|
||||
createAuctions bool
|
||||
auctionCount int
|
||||
}{
|
||||
{
|
||||
"fetch auctions when no auctions exist",
|
||||
&types.QueryAuctionsRequest{},
|
||||
false,
|
||||
0,
|
||||
},
|
||||
|
||||
{
|
||||
"fetch auctions with one auction created",
|
||||
&types.QueryAuctionsRequest{},
|
||||
true,
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
if test.createAuctions {
|
||||
_, _, err := kts.createAuctionAndCommitBid(false)
|
||||
kts.Require().Nil(err)
|
||||
}
|
||||
|
||||
resp, _ := kts.queryClient.Auctions(context.Background(), test.req)
|
||||
kts.Require().Equal(test.auctionCount, len(resp.GetAuctions().Auctions))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcGetBids() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryGetBidsRequest
|
||||
createAuction bool
|
||||
commitBid bool
|
||||
bidCount int
|
||||
}{
|
||||
{
|
||||
"fetch all bids when no auction exists",
|
||||
&types.QueryGetBidsRequest{},
|
||||
false,
|
||||
false,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"fetch all bids for valid auction but no added bids",
|
||||
&types.QueryGetBidsRequest{},
|
||||
true,
|
||||
false,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"fetch all bids for valid auction and valid bid",
|
||||
&types.QueryGetBidsRequest{},
|
||||
true,
|
||||
true,
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
if test.createAuction {
|
||||
auction, _, err := kts.createAuctionAndCommitBid(test.commitBid)
|
||||
kts.Require().NoError(err)
|
||||
test.req.AuctionId = auction.Id
|
||||
}
|
||||
|
||||
resp, err := kts.queryClient.GetBids(context.Background(), test.req)
|
||||
if test.createAuction {
|
||||
kts.Require().Nil(err)
|
||||
kts.Require().Equal(test.bidCount, len(resp.GetBids()))
|
||||
} else {
|
||||
kts.Require().NotNil(err)
|
||||
kts.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcGetBid() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryGetBidRequest
|
||||
createAuctionAndBid bool
|
||||
}{
|
||||
{
|
||||
"fetch bid when bid does not exist",
|
||||
&types.QueryGetBidRequest{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"fetch bid when valid bid exists",
|
||||
&types.QueryGetBidRequest{},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
if test.createAuctionAndBid {
|
||||
auction, bid, err := kts.createAuctionAndCommitBid(test.createAuctionAndBid)
|
||||
kts.Require().NoError(err)
|
||||
test.req.AuctionId = auction.Id
|
||||
test.req.Bidder = bid.BidderAddress
|
||||
}
|
||||
|
||||
resp, err := kts.queryClient.GetBid(context.Background(), test.req)
|
||||
if test.createAuctionAndBid {
|
||||
kts.Require().NoError(err)
|
||||
kts.Require().NotNil(resp.Bid)
|
||||
kts.Require().Equal(test.req.Bidder, resp.Bid.BidderAddress)
|
||||
} else {
|
||||
kts.Require().NotNil(err)
|
||||
kts.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcGetAuctionsByBidder() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryAuctionsByBidderRequest
|
||||
createAuctionAndCommitBid bool
|
||||
auctionCount int
|
||||
}{
|
||||
{
|
||||
"get auctions by bidder with invalid bidder address",
|
||||
&types.QueryAuctionsByBidderRequest{},
|
||||
false,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"get auctions by bidder with valid auction and bid",
|
||||
&types.QueryAuctionsByBidderRequest{},
|
||||
true,
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
if test.createAuctionAndCommitBid {
|
||||
_, bid, err := kts.createAuctionAndCommitBid(test.createAuctionAndCommitBid)
|
||||
kts.Require().NoError(err)
|
||||
test.req.BidderAddress = bid.BidderAddress
|
||||
}
|
||||
|
||||
resp, err := kts.queryClient.AuctionsByBidder(context.Background(), test.req)
|
||||
if test.createAuctionAndCommitBid {
|
||||
kts.Require().NoError(err)
|
||||
kts.Require().NotNil(resp.Auctions)
|
||||
kts.Require().Equal(test.auctionCount, len(resp.Auctions.Auctions))
|
||||
} else {
|
||||
kts.Require().NotNil(err)
|
||||
kts.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcGetAuctionsByOwner() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryAuctionsByOwnerRequest
|
||||
createAuction bool
|
||||
auctionCount int
|
||||
}{
|
||||
{
|
||||
"get auctions by owner with invalid owner address",
|
||||
&types.QueryAuctionsByOwnerRequest{},
|
||||
false,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"get auctions by owner with valid auction",
|
||||
&types.QueryAuctionsByOwnerRequest{},
|
||||
true,
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
if test.createAuction {
|
||||
auction, _, err := kts.createAuctionAndCommitBid(false)
|
||||
kts.Require().NoError(err)
|
||||
test.req.OwnerAddress = auction.OwnerAddress
|
||||
}
|
||||
|
||||
resp, err := kts.queryClient.AuctionsByOwner(context.Background(), test.req)
|
||||
if test.createAuction {
|
||||
kts.Require().NoError(err)
|
||||
kts.Require().NotNil(resp.Auctions)
|
||||
kts.Require().Equal(test.auctionCount, len(resp.Auctions.Auctions))
|
||||
} else {
|
||||
kts.Require().NotNil(err)
|
||||
kts.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcQueryBalance() {
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryGetAuctionModuleBalanceRequest
|
||||
createAuction bool
|
||||
auctionCount int
|
||||
}{
|
||||
{
|
||||
"get balance with no auctions created",
|
||||
&types.QueryGetAuctionModuleBalanceRequest{},
|
||||
false,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"get balance with single auction created",
|
||||
&types.QueryGetAuctionModuleBalanceRequest{},
|
||||
true,
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
if test.createAuction {
|
||||
_, _, err := kts.createAuctionAndCommitBid(true)
|
||||
kts.Require().NoError(err)
|
||||
}
|
||||
|
||||
resp, err := kts.queryClient.GetAuctionModuleBalance(context.Background(), test.req)
|
||||
kts.Require().NoError(err)
|
||||
kts.Require().Equal(test.auctionCount, len(resp.GetBalance()))
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) createAuctionAndCommitBid(commitBid bool) (*types.Auction, *types.Bid, error) {
|
||||
ctx, k := kts.SdkCtx, kts.AuctionKeeper
|
||||
numAccounts := 1
|
||||
if commitBid {
|
||||
numAccounts++
|
||||
}
|
||||
|
||||
// Create funded account(s)
|
||||
accounts := kts.MakeTestAccounts(numAccounts, sdkmath.NewInt(1000000))
|
||||
|
||||
auction, err := k.CreateAuction(
|
||||
ctx,
|
||||
types.MsgCreateAuction{
|
||||
Kind: types.AuctionKindVickrey,
|
||||
Signer: accounts[0].String(),
|
||||
CommitsDuration: 5 * time.Minute,
|
||||
RevealsDuration: 5 * time.Minute,
|
||||
CommitFee: sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1000)),
|
||||
RevealFee: sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1000)),
|
||||
MinimumBid: sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1000000)),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if commitBid {
|
||||
bid, err := k.CommitBid(ctx, types.NewMsgCommitBid(auction.Id, testCommitHash, accounts[1]))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return auction, bid, nil
|
||||
}
|
||||
|
||||
return auction, nil, nil
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
integrationTest "git.vdb.to/cerc-io/laconicd/tests/integration"
|
||||
types "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
)
|
||||
|
||||
type KeeperTestSuite struct {
|
||||
suite.Suite
|
||||
integrationTest.TestFixture
|
||||
|
||||
queryClient types.QueryClient
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) SetupTest() {
|
||||
err := kts.TestFixture.Setup(kts.T())
|
||||
assert.Nil(kts.T(), err)
|
||||
|
||||
qr := kts.App.QueryHelper()
|
||||
kts.queryClient = types.NewQueryClient(qr)
|
||||
}
|
||||
|
||||
func TestBondKeeperTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(KeeperTestSuite))
|
||||
}
|
@ -1,207 +0,0 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
types "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
)
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcQueryParams() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryParamsRequest
|
||||
}{
|
||||
{
|
||||
"fetch params",
|
||||
&types.QueryParamsRequest{},
|
||||
},
|
||||
}
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
resp, err := kts.queryClient.Params(context.Background(), test.req)
|
||||
kts.Require().Nil(err)
|
||||
kts.Require().Equal(*(resp.Params), types.DefaultParams())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcQueryBondsList() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryBondsRequest
|
||||
resp *types.QueryBondsResponse
|
||||
noOfBonds int
|
||||
createBonds bool
|
||||
}{
|
||||
{
|
||||
"empty request",
|
||||
&types.QueryBondsRequest{},
|
||||
&types.QueryBondsResponse{},
|
||||
0,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"Get Bonds",
|
||||
&types.QueryBondsRequest{},
|
||||
&types.QueryBondsResponse{},
|
||||
1,
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
if test.createBonds {
|
||||
_, err := kts.createBond()
|
||||
kts.Require().NoError(err)
|
||||
}
|
||||
resp, _ := kts.queryClient.Bonds(context.Background(), test.req)
|
||||
kts.Require().Equal(test.noOfBonds, len(resp.GetBonds()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcQueryBondByBondId() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryGetBondByIdRequest
|
||||
createBonds bool
|
||||
errResponse bool
|
||||
bondId string
|
||||
}{
|
||||
{
|
||||
"empty request",
|
||||
&types.QueryGetBondByIdRequest{},
|
||||
false,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"Get Bond By ID",
|
||||
&types.QueryGetBondByIdRequest{},
|
||||
true,
|
||||
false,
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
if test.createBonds {
|
||||
bond, err := kts.createBond()
|
||||
kts.Require().NoError(err)
|
||||
test.req.Id = bond.Id
|
||||
}
|
||||
resp, err := kts.queryClient.GetBondById(context.Background(), test.req)
|
||||
if !test.errResponse {
|
||||
kts.Require().Nil(err)
|
||||
kts.Require().NotNil(resp.GetBond())
|
||||
kts.Require().Equal(test.req.Id, resp.GetBond().GetId())
|
||||
} else {
|
||||
kts.Require().NotNil(err)
|
||||
kts.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcGetBondsByOwner() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryGetBondsByOwnerRequest
|
||||
noOfBonds int
|
||||
createBonds bool
|
||||
errResponse bool
|
||||
bondId string
|
||||
}{
|
||||
{
|
||||
"empty request",
|
||||
&types.QueryGetBondsByOwnerRequest{},
|
||||
0,
|
||||
false,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"Get Bond By Owner",
|
||||
&types.QueryGetBondsByOwnerRequest{},
|
||||
1,
|
||||
true,
|
||||
false,
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
if test.createBonds {
|
||||
bond, err := kts.createBond()
|
||||
kts.Require().NoError(err)
|
||||
test.req.Owner = bond.Owner
|
||||
}
|
||||
resp, err := kts.queryClient.GetBondsByOwner(context.Background(), test.req)
|
||||
if !test.errResponse {
|
||||
kts.Require().Nil(err)
|
||||
kts.Require().NotNil(resp.GetBonds())
|
||||
kts.Require().Equal(test.noOfBonds, len(resp.GetBonds()))
|
||||
} else {
|
||||
kts.Require().NotNil(err)
|
||||
kts.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcGetModuleBalance() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryGetBondModuleBalanceRequest
|
||||
noOfBonds int
|
||||
createBonds bool
|
||||
errResponse bool
|
||||
}{
|
||||
{
|
||||
"empty request",
|
||||
&types.QueryGetBondModuleBalanceRequest{},
|
||||
0,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
if test.createBonds {
|
||||
_, err := kts.createBond()
|
||||
kts.Require().NoError(err)
|
||||
}
|
||||
resp, err := kts.queryClient.GetBondModuleBalance(context.Background(), test.req)
|
||||
if !test.errResponse {
|
||||
kts.Require().Nil(err)
|
||||
kts.Require().NotNil(resp.GetBalance())
|
||||
kts.Require().Equal(resp.GetBalance(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(10))))
|
||||
} else {
|
||||
kts.Require().NotNil(err)
|
||||
kts.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) createBond() (*types.Bond, error) {
|
||||
ctx, k := kts.SdkCtx, kts.BondKeeper
|
||||
|
||||
// Create funded account(s)
|
||||
accounts := kts.MakeTestAccounts(1, math.NewInt(1000))
|
||||
|
||||
bond, err := k.CreateBond(ctx, accounts[0], sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(10))))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bond, nil
|
||||
}
|
@ -1,222 +0,0 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/math"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"cosmossdk.io/x/bank"
|
||||
bankkeeper "cosmossdk.io/x/bank/keeper"
|
||||
banktypes "cosmossdk.io/x/bank/types"
|
||||
minttypes "cosmossdk.io/x/mint/types"
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/integration"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
|
||||
authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/app/params"
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
auctiontypes "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
auctionkeeper "git.vdb.to/cerc-io/laconicd/x/auction/keeper"
|
||||
auctionmodule "git.vdb.to/cerc-io/laconicd/x/auction/module"
|
||||
bondtypes "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
bondkeeper "git.vdb.to/cerc-io/laconicd/x/bond/keeper"
|
||||
bondmodule "git.vdb.to/cerc-io/laconicd/x/bond/module"
|
||||
registrytypes "git.vdb.to/cerc-io/laconicd/x/registry"
|
||||
registrykeeper "git.vdb.to/cerc-io/laconicd/x/registry/keeper"
|
||||
registrymodule "git.vdb.to/cerc-io/laconicd/x/registry/module"
|
||||
)
|
||||
|
||||
type TestFixture struct {
|
||||
App *integration.App
|
||||
|
||||
SdkCtx sdk.Context
|
||||
cdc codec.Codec
|
||||
keys map[string]*storetypes.KVStoreKey
|
||||
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
BankKeeper bankkeeper.Keeper
|
||||
|
||||
AuctionKeeper *auctionkeeper.Keeper
|
||||
BondKeeper *bondkeeper.Keeper
|
||||
RegistryKeeper registrykeeper.Keeper
|
||||
}
|
||||
|
||||
func (tf *TestFixture) Setup(t *testing.T) error {
|
||||
keys := storetypes.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, auctiontypes.StoreKey, bondtypes.StoreKey, registrytypes.StoreKey,
|
||||
)
|
||||
cdc := moduletestutil.MakeTestEncodingConfig(
|
||||
codectestutil.CodecOptions{},
|
||||
auth.AppModule{},
|
||||
auctionmodule.AppModule{},
|
||||
bondmodule.AppModule{},
|
||||
registrymodule.AppModule{},
|
||||
).Codec
|
||||
|
||||
logger := log.NewNopLogger() // Use log.NewTestLogger(kts.T()) for help with debugging
|
||||
cms := integration.CreateMultiStore(keys, logger)
|
||||
|
||||
newCtx := sdk.NewContext(cms, true, logger)
|
||||
|
||||
authority := authtypes.NewModuleAddress("gov")
|
||||
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(t)
|
||||
accountsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
acctNum := uint64(0)
|
||||
accountsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currNum := acctNum
|
||||
acctNum++
|
||||
return currNum, nil
|
||||
})
|
||||
|
||||
maccPerms := map[string][]string{
|
||||
minttypes.ModuleName: {authtypes.Minter},
|
||||
auctiontypes.ModuleName: {},
|
||||
auctiontypes.AuctionBurnModuleAccountName: {},
|
||||
bondtypes.ModuleName: {},
|
||||
registrytypes.ModuleName: {},
|
||||
registrytypes.RecordRentModuleAccountName: {},
|
||||
registrytypes.AuthorityRentModuleAccountName: {},
|
||||
}
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger),
|
||||
cdc,
|
||||
authtypes.ProtoBaseAccount,
|
||||
accountsModKeeper,
|
||||
maccPerms,
|
||||
utils.NewAddressCodec(),
|
||||
params.Bech32PrefixAccAddr,
|
||||
authority.String(),
|
||||
)
|
||||
|
||||
blockedAddresses := map[string]bool{
|
||||
accountKeeper.GetAuthority(): false,
|
||||
}
|
||||
bankKeeper := bankkeeper.NewBaseKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), logger),
|
||||
cdc,
|
||||
accountKeeper,
|
||||
blockedAddresses,
|
||||
authority.String(),
|
||||
)
|
||||
|
||||
auctionKeeper := auctionkeeper.NewKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[auctiontypes.StoreKey]), logger),
|
||||
cdc,
|
||||
accountKeeper,
|
||||
bankKeeper,
|
||||
authority.String(),
|
||||
logger,
|
||||
)
|
||||
|
||||
bondKeeper := bondkeeper.NewKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[bondtypes.StoreKey]), logger),
|
||||
cdc,
|
||||
runtime.NewKVStoreService(keys[bondtypes.StoreKey]),
|
||||
accountKeeper,
|
||||
bankKeeper,
|
||||
authority.String(),
|
||||
logger,
|
||||
)
|
||||
|
||||
registryKeeper := registrykeeper.NewKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[registrytypes.StoreKey]), logger),
|
||||
cdc,
|
||||
accountKeeper,
|
||||
bankKeeper,
|
||||
bondKeeper,
|
||||
auctionKeeper,
|
||||
authority.String(),
|
||||
logger,
|
||||
)
|
||||
|
||||
authModule := auth.NewAppModule(cdc, accountKeeper, accountsModKeeper, authsims.RandomGenesisAccounts, nil)
|
||||
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)
|
||||
auctionModule := auctionmodule.NewAppModule(cdc, auctionKeeper)
|
||||
bondModule := bondmodule.NewAppModule(cdc, bondKeeper)
|
||||
registryModule := registrymodule.NewAppModule(cdc, registryKeeper)
|
||||
|
||||
router := baseapp.NewMsgServiceRouter()
|
||||
queryRouter := baseapp.NewGRPCQueryRouter()
|
||||
|
||||
integrationApp := integration.NewIntegrationApp(
|
||||
newCtx, logger, keys, cdc,
|
||||
utils.NewAddressCodec(),
|
||||
utils.NewValAddressCodec(),
|
||||
map[string]appmodule.AppModule{
|
||||
authtypes.ModuleName: authModule,
|
||||
banktypes.ModuleName: bankModule,
|
||||
auctiontypes.ModuleName: auctionModule,
|
||||
bondtypes.ModuleName: bondModule,
|
||||
registrytypes.ModuleName: registryModule,
|
||||
},
|
||||
router, queryRouter)
|
||||
|
||||
ctx := integrationApp.Context()
|
||||
|
||||
// Register MsgServer and QueryServer
|
||||
auctiontypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), auctionkeeper.NewMsgServerImpl(auctionKeeper))
|
||||
auctiontypes.RegisterQueryServer(integrationApp.QueryHelper(), auctionkeeper.NewQueryServerImpl(auctionKeeper))
|
||||
|
||||
bondtypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), bondkeeper.NewMsgServerImpl(bondKeeper))
|
||||
bondtypes.RegisterQueryServer(integrationApp.QueryHelper(), bondkeeper.NewQueryServerImpl(bondKeeper))
|
||||
|
||||
registrytypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), registrykeeper.NewMsgServerImpl(registryKeeper))
|
||||
registrytypes.RegisterQueryServer(integrationApp.QueryHelper(), registrykeeper.NewQueryServerImpl(registryKeeper))
|
||||
|
||||
// set default params
|
||||
if err := auctionKeeper.Params.Set(ctx, auctiontypes.DefaultParams()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := bondKeeper.Params.Set(ctx, bondtypes.DefaultParams()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := registryKeeper.Params.Set(ctx, registrytypes.DefaultParams()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tf.App = integrationApp
|
||||
tf.SdkCtx, tf.cdc, tf.keys = sdk.UnwrapSDKContext(ctx), cdc, keys
|
||||
tf.AccountKeeper, tf.BankKeeper = accountKeeper, bankKeeper
|
||||
tf.AuctionKeeper, tf.BondKeeper, tf.RegistryKeeper = auctionKeeper, bondKeeper, registryKeeper
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (kts *TestFixture) MakeTestAccounts(numAccounts int, funds math.Int) []sdk.AccAddress {
|
||||
accounts := simtestutil.CreateRandomAccounts(numAccounts)
|
||||
coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))
|
||||
const mintModuleName = "mint"
|
||||
for _, addr := range accounts {
|
||||
println("funding test account:", addr.String())
|
||||
if err := kts.BankKeeper.MintCoins(kts.SdkCtx, mintModuleName, coins); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := kts.BankKeeper.SendCoinsFromModuleToAccount(kts.SdkCtx, mintModuleName, addr, coins); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for _, acct := range accounts {
|
||||
kts.AccountKeeper.SetAccount(kts.SdkCtx, kts.AccountKeeper.NewAccountWithAddress(kts.SdkCtx, acct))
|
||||
}
|
||||
return accounts
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
integrationTest "git.vdb.to/cerc-io/laconicd/tests/integration"
|
||||
bondTypes "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
types "git.vdb.to/cerc-io/laconicd/x/registry"
|
||||
)
|
||||
|
||||
type KeeperTestSuite struct {
|
||||
suite.Suite
|
||||
integrationTest.TestFixture
|
||||
|
||||
queryClient types.QueryClient
|
||||
|
||||
accounts []sdk.AccAddress
|
||||
bond bondTypes.Bond
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) SetupTest() {
|
||||
err := kts.TestFixture.Setup(kts.T())
|
||||
assert.Nil(kts.T(), err)
|
||||
|
||||
// set default params
|
||||
err = kts.RegistryKeeper.Params.Set(kts.SdkCtx, types.DefaultParams())
|
||||
assert.Nil(kts.T(), err)
|
||||
|
||||
qr := kts.App.QueryHelper()
|
||||
kts.queryClient = types.NewQueryClient(qr)
|
||||
|
||||
// Create a bond
|
||||
bond, err := kts.createBond()
|
||||
assert.Nil(kts.T(), err)
|
||||
kts.bond = *bond
|
||||
}
|
||||
|
||||
func TestRegistryKeeperTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(KeeperTestSuite))
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) createBond() (*bondTypes.Bond, error) {
|
||||
ctx := kts.SdkCtx
|
||||
|
||||
// Create a funded account
|
||||
kts.accounts = kts.MakeTestAccounts(1, math.NewInt(1000000000000))
|
||||
|
||||
bond, err := kts.BondKeeper.CreateBond(ctx, kts.accounts[0], sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(1000000000))))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bond, nil
|
||||
}
|
@ -1,421 +0,0 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
||||
types "git.vdb.to/cerc-io/laconicd/x/registry"
|
||||
"git.vdb.to/cerc-io/laconicd/x/registry/client/cli"
|
||||
"git.vdb.to/cerc-io/laconicd/x/registry/helpers"
|
||||
registryKeeper "git.vdb.to/cerc-io/laconicd/x/registry/keeper"
|
||||
)
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcQueryParams() {
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryParamsRequest
|
||||
}{
|
||||
{
|
||||
"Get Params",
|
||||
&types.QueryParamsRequest{},
|
||||
},
|
||||
}
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
resp, _ := kts.queryClient.Params(context.Background(), test.req)
|
||||
defaultParams := types.DefaultParams()
|
||||
kts.Require().Equal(defaultParams.String(), resp.GetParams().String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcGetRecordLists() {
|
||||
ctx, queryClient := kts.SdkCtx, kts.queryClient
|
||||
sr := kts.Require()
|
||||
|
||||
var recordId string
|
||||
examples := []string{
|
||||
"../../../data/examples/service_provider_example.yml",
|
||||
"../../../data/examples/website_registration_example.yml",
|
||||
"../../../data/examples/general_record_example.yml",
|
||||
}
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryRecordsRequest
|
||||
createRecords bool
|
||||
expErr bool
|
||||
noOfRecords int
|
||||
}{
|
||||
{
|
||||
"Empty Records",
|
||||
&types.QueryRecordsRequest{},
|
||||
false,
|
||||
false,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"List Records",
|
||||
&types.QueryRecordsRequest{},
|
||||
true,
|
||||
false,
|
||||
3,
|
||||
},
|
||||
{
|
||||
"Filter with type",
|
||||
&types.QueryRecordsRequest{
|
||||
Attributes: []*types.QueryRecordsRequest_KeyValueInput{
|
||||
{
|
||||
Key: "type",
|
||||
Value: &types.QueryRecordsRequest_ValueInput{
|
||||
Value: &types.QueryRecordsRequest_ValueInput_String_{String_: "WebsiteRegistrationRecord"},
|
||||
},
|
||||
},
|
||||
},
|
||||
All: true,
|
||||
},
|
||||
true,
|
||||
false,
|
||||
1,
|
||||
},
|
||||
// Skip the following test as querying with recursive values not supported (PR https://git.vdb.to/cerc-io/laconicd/pulls/112)
|
||||
// See function RecordsFromAttributes (QueryValueToJSON call) in the registry keeper implementation (x/registry/keeper/keeper.go)
|
||||
// {
|
||||
// "Filter with tag (extant) (https://git.vdb.to/cerc-io/laconicd/issues/129)",
|
||||
// &types.QueryRecordsRequest{
|
||||
// Attributes: []*types.QueryRecordsRequest_KeyValueInput{
|
||||
// {
|
||||
// Key: "tags",
|
||||
// // Value: &types.QueryRecordsRequest_ValueInput{
|
||||
// // Value: &types.QueryRecordsRequest_ValueInput_String_{"tagA"},
|
||||
// // },
|
||||
// Value: &types.QueryRecordsRequest_ValueInput{
|
||||
// Value: &types.QueryRecordsRequest_ValueInput_Array{Array: &types.QueryRecordsRequest_ArrayInput{
|
||||
// Values: []*types.QueryRecordsRequest_ValueInput{
|
||||
// {
|
||||
// Value: &types.QueryRecordsRequest_ValueInput_String_{"tagA"},
|
||||
// },
|
||||
// },
|
||||
// }},
|
||||
// },
|
||||
// // Throws: "Recursive query values are not supported"
|
||||
// },
|
||||
// },
|
||||
// All: true,
|
||||
// },
|
||||
// true,
|
||||
// false,
|
||||
// 1,
|
||||
// },
|
||||
{
|
||||
"Filter with tag (non-existent) (https://git.vdb.to/cerc-io/laconicd/issues/129)",
|
||||
&types.QueryRecordsRequest{
|
||||
Attributes: []*types.QueryRecordsRequest_KeyValueInput{
|
||||
{
|
||||
Key: "tags",
|
||||
Value: &types.QueryRecordsRequest_ValueInput{
|
||||
Value: &types.QueryRecordsRequest_ValueInput_String_{String_: "NOEXIST"},
|
||||
},
|
||||
},
|
||||
},
|
||||
All: true,
|
||||
},
|
||||
true,
|
||||
false,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"Filter test for key collision (https://git.vdb.to/cerc-io/laconicd/issues/122)",
|
||||
&types.QueryRecordsRequest{
|
||||
Attributes: []*types.QueryRecordsRequest_KeyValueInput{
|
||||
{
|
||||
Key: "typ",
|
||||
Value: &types.QueryRecordsRequest_ValueInput{
|
||||
Value: &types.QueryRecordsRequest_ValueInput_String_{String_: "eWebsiteRegistrationRecord"},
|
||||
},
|
||||
},
|
||||
},
|
||||
All: true,
|
||||
},
|
||||
true,
|
||||
false,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"Filter with attributes ServiceProviderRegistration",
|
||||
&types.QueryRecordsRequest{
|
||||
Attributes: []*types.QueryRecordsRequest_KeyValueInput{
|
||||
{
|
||||
Key: "x500state_name",
|
||||
Value: &types.QueryRecordsRequest_ValueInput{
|
||||
Value: &types.QueryRecordsRequest_ValueInput_String_{String_: "california"},
|
||||
},
|
||||
},
|
||||
},
|
||||
All: true,
|
||||
},
|
||||
true,
|
||||
false,
|
||||
1,
|
||||
},
|
||||
}
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
if test.createRecords {
|
||||
for _, example := range examples {
|
||||
filePath, err := filepath.Abs(example)
|
||||
sr.NoError(err)
|
||||
payloadType, err := cli.GetPayloadFromFile(filePath)
|
||||
sr.NoError(err)
|
||||
payload := payloadType.ToPayload()
|
||||
record, err := kts.RegistryKeeper.SetRecord(ctx, types.MsgSetRecord{
|
||||
BondId: kts.bond.GetId(),
|
||||
Signer: kts.accounts[0].String(),
|
||||
Payload: payload,
|
||||
})
|
||||
sr.NoError(err)
|
||||
sr.NotNil(record.Id)
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := queryClient.Records(context.Background(), test.req)
|
||||
|
||||
if test.expErr {
|
||||
kts.Error(err)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
sr.Equal(test.noOfRecords, len(resp.GetRecords()))
|
||||
if test.createRecords && test.noOfRecords > 0 {
|
||||
recordId = resp.GetRecords()[0].GetId()
|
||||
sr.NotZero(resp.GetRecords())
|
||||
sr.Equal(resp.GetRecords()[0].GetBondId(), kts.bond.GetId())
|
||||
|
||||
for _, record := range resp.GetRecords() {
|
||||
recAttr := helpers.MustUnmarshalJSON[types.AttributeMap](record.Attributes)
|
||||
|
||||
for _, attr := range test.req.GetAttributes() {
|
||||
enc, err := registryKeeper.QueryValueToJSON(attr.Value)
|
||||
sr.NoError(err)
|
||||
av := helpers.MustUnmarshalJSON[any](enc)
|
||||
|
||||
if nil != av && nil != recAttr[attr.Key] &&
|
||||
reflect.Slice == reflect.TypeOf(recAttr[attr.Key]).Kind() &&
|
||||
reflect.Slice != reflect.TypeOf(av).Kind() {
|
||||
found := false
|
||||
allValues := recAttr[attr.Key].([]interface{})
|
||||
for i := range allValues {
|
||||
if av == allValues[i] {
|
||||
fmt.Printf("Found %s in %s", allValues[i], recAttr[attr.Key])
|
||||
found = true
|
||||
}
|
||||
}
|
||||
sr.Equal(true, found, fmt.Sprintf("Unable to find %s in %s", av, recAttr[attr.Key]))
|
||||
} else {
|
||||
if attr.Key[:4] == "x500" {
|
||||
sr.Equal(av, recAttr["x500"].(map[string]interface{})[attr.Key[4:]])
|
||||
} else {
|
||||
sr.Equal(av, recAttr[attr.Key])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Get the records by record id
|
||||
testCases1 := []struct {
|
||||
msg string
|
||||
req *types.QueryGetRecordRequest
|
||||
createRecord bool
|
||||
expErr bool
|
||||
noOfRecords int
|
||||
}{
|
||||
{
|
||||
"Invalid Request without record id",
|
||||
&types.QueryGetRecordRequest{},
|
||||
false,
|
||||
true,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"With Record ID",
|
||||
&types.QueryGetRecordRequest{
|
||||
Id: recordId,
|
||||
},
|
||||
true,
|
||||
false,
|
||||
1,
|
||||
},
|
||||
}
|
||||
for _, test := range testCases1 {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
resp, err := queryClient.GetRecord(context.Background(), test.req)
|
||||
|
||||
if test.expErr {
|
||||
kts.Error(err)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
sr.NotNil(resp.GetRecord())
|
||||
if test.createRecord {
|
||||
sr.Equal(resp.GetRecord().BondId, kts.bond.GetId())
|
||||
sr.Equal(resp.GetRecord().Id, recordId)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Get the records by record id
|
||||
testCasesByBondId := []struct {
|
||||
msg string
|
||||
req *types.QueryGetRecordsByBondIdRequest
|
||||
createRecord bool
|
||||
expErr bool
|
||||
noOfRecords int
|
||||
}{
|
||||
{
|
||||
"Invalid Request without bond id",
|
||||
&types.QueryGetRecordsByBondIdRequest{},
|
||||
false,
|
||||
true,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"With Bond ID",
|
||||
&types.QueryGetRecordsByBondIdRequest{
|
||||
Id: kts.bond.GetId(),
|
||||
},
|
||||
true,
|
||||
false,
|
||||
1,
|
||||
},
|
||||
}
|
||||
for _, test := range testCasesByBondId {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
resp, err := queryClient.GetRecordsByBondId(context.Background(), test.req)
|
||||
|
||||
if test.expErr {
|
||||
sr.Zero(resp.GetRecords())
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
sr.NotNil(resp.GetRecords())
|
||||
if test.createRecord {
|
||||
sr.NotZero(resp.GetRecords())
|
||||
sr.Equal(resp.GetRecords()[0].GetBondId(), kts.bond.GetId())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcQueryRegistryModuleBalance() {
|
||||
queryClient, ctx := kts.queryClient, kts.SdkCtx
|
||||
sr := kts.Require()
|
||||
examples := []string{
|
||||
"../../../data/examples/service_provider_example.yml",
|
||||
"../../../data/examples/website_registration_example.yml",
|
||||
}
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryGetRegistryModuleBalanceRequest
|
||||
createRecords bool
|
||||
expErr bool
|
||||
noOfRecords int
|
||||
}{
|
||||
{
|
||||
"Get Module Balance",
|
||||
&types.QueryGetRegistryModuleBalanceRequest{},
|
||||
true,
|
||||
false,
|
||||
1,
|
||||
},
|
||||
}
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
if test.createRecords {
|
||||
for _, example := range examples {
|
||||
filePath, err := filepath.Abs(example)
|
||||
sr.NoError(err)
|
||||
payloadType, err := cli.GetPayloadFromFile(filePath)
|
||||
sr.NoError(err)
|
||||
payload := payloadType.ToPayload()
|
||||
record, err := kts.RegistryKeeper.SetRecord(ctx, types.MsgSetRecord{
|
||||
BondId: kts.bond.GetId(),
|
||||
Signer: kts.accounts[0].String(),
|
||||
Payload: payload,
|
||||
})
|
||||
sr.NoError(err)
|
||||
sr.NotNil(record.Id)
|
||||
}
|
||||
}
|
||||
resp, err := queryClient.GetRegistryModuleBalance(context.Background(), test.req)
|
||||
if test.expErr {
|
||||
kts.Error(err)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
sr.Equal(test.noOfRecords, len(resp.GetBalances()))
|
||||
if test.createRecords {
|
||||
balance := resp.GetBalances()[0]
|
||||
sr.Equal(balance.AccountName, types.RecordRentModuleAccountName)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (kts *KeeperTestSuite) TestGrpcQueryWhoIs() {
|
||||
queryClient, ctx := kts.queryClient, kts.SdkCtx
|
||||
sr := kts.Require()
|
||||
authorityName := "TestGrpcQueryWhoIs"
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
req *types.QueryWhoisRequest
|
||||
createName bool
|
||||
expErr bool
|
||||
noOfRecords int
|
||||
}{
|
||||
{
|
||||
"Invalid Request without name",
|
||||
&types.QueryWhoisRequest{},
|
||||
false,
|
||||
true,
|
||||
1,
|
||||
},
|
||||
{
|
||||
"Success",
|
||||
&types.QueryWhoisRequest{},
|
||||
true,
|
||||
false,
|
||||
1,
|
||||
},
|
||||
}
|
||||
for _, test := range testCases {
|
||||
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
||||
if test.createName {
|
||||
err := kts.RegistryKeeper.ReserveAuthority(ctx, types.MsgReserveAuthority{
|
||||
Name: authorityName,
|
||||
Signer: kts.accounts[0].String(),
|
||||
Owner: kts.accounts[0].String(),
|
||||
})
|
||||
sr.NoError(err)
|
||||
test.req = &types.QueryWhoisRequest{Name: authorityName}
|
||||
}
|
||||
resp, err := queryClient.Whois(context.Background(), test.req)
|
||||
if test.expErr {
|
||||
kts.Error(err)
|
||||
sr.Nil(resp)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
if test.createName {
|
||||
nameAuth := resp.NameAuthority
|
||||
sr.NotNil(nameAuth)
|
||||
sr.Equal(nameAuth.OwnerAddress, kts.accounts[0].String())
|
||||
sr.Equal(types.AuthorityActive, nameAuth.Status)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
)
|
||||
|
||||
// Reference: https://github.com/cosmos/cosmos-sdk/blob/v0.50.3/testutil/cli/tx.go#L15
|
||||
|
||||
// CheckTxCode verifies that the transaction result returns a specific code
|
||||
// Takes a network, wait for two blocks and fetch the transaction from its hash
|
||||
func CheckTxCode(network network.NetworkI, clientCtx client.Context, txHash string, expectedCode uint32) error {
|
||||
// wait for 2 blocks
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := network.WaitForNextBlock(); err != nil {
|
||||
return fmt.Errorf("failed to wait for next block: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
cmd := authcli.QueryTxCmd()
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var response sdk.TxResponse
|
||||
if err := clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if response.Code != expectedCode {
|
||||
return fmt.Errorf("expected code %d, got %d", expectedCode, response.Code)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/core/transaction"
|
||||
"cosmossdk.io/server/v2/cometbft/mempool"
|
||||
)
|
||||
|
||||
var _ mempool.Mempool[transaction.Tx] = (*MockMempool[transaction.Tx])(nil)
|
||||
|
||||
// MockMempool implements Mempool
|
||||
// Used for testing instead of NoOpMempool
|
||||
type MockMempool[T transaction.Tx] struct{}
|
||||
|
||||
func (MockMempool[T]) Insert(context.Context, T) error { return nil }
|
||||
func (MockMempool[T]) Select(context.Context, []T) mempool.Iterator[T] { return nil }
|
||||
func (MockMempool[T]) SelectBy(context.Context, []T, func(T) bool) {}
|
||||
func (MockMempool[T]) CountTx() int { return 0 }
|
||||
func (MockMempool[T]) Remove(T) error { return nil }
|
@ -1,65 +0,0 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
corestore "cosmossdk.io/core/store"
|
||||
)
|
||||
|
||||
// ReaderMap defines an adapter around a RootStore that only exposes read-only
|
||||
// operations. This is useful for exposing a read-only view of the RootStore at
|
||||
// a specific version in history, which could also be the latest state.
|
||||
type ReaderMap struct {
|
||||
store *MockStore
|
||||
version uint64
|
||||
}
|
||||
|
||||
func NewMockReaderMap(v uint64, rs *MockStore) *ReaderMap {
|
||||
return &ReaderMap{
|
||||
store: rs,
|
||||
version: v,
|
||||
}
|
||||
}
|
||||
|
||||
func (roa *ReaderMap) GetReader(actor []byte) (corestore.Reader, error) {
|
||||
return NewMockReader(roa.version, roa.store, actor), nil
|
||||
}
|
||||
|
||||
// MockReader represents a read-only adapter for accessing data from the root store.
|
||||
type MockReader struct {
|
||||
version uint64 // The version of the data.
|
||||
store *MockStore // The root store to read data from.
|
||||
actor []byte // The actor associated with the data.
|
||||
}
|
||||
|
||||
func NewMockReader(v uint64, rs *MockStore, actor []byte) *MockReader {
|
||||
return &MockReader{
|
||||
version: v,
|
||||
store: rs,
|
||||
actor: actor,
|
||||
}
|
||||
}
|
||||
|
||||
func (roa *MockReader) Has(key []byte) (bool, error) {
|
||||
val, err := roa.store.GetStateStorage().Has(roa.actor, roa.version, key)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func (roa *MockReader) Get(key []byte) ([]byte, error) {
|
||||
result, err := roa.store.GetStateStorage().Get(roa.actor, roa.version, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (roa *MockReader) Iterator(start, end []byte) (corestore.Iterator, error) {
|
||||
return roa.store.GetStateStorage().Iterator(roa.actor, roa.version, start, end)
|
||||
}
|
||||
|
||||
func (roa *MockReader) ReverseIterator(start, end []byte) (corestore.Iterator, error) {
|
||||
return roa.store.GetStateStorage().ReverseIterator(roa.actor, roa.version, start, end)
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/core/log"
|
||||
corestore "cosmossdk.io/core/store"
|
||||
storev2 "cosmossdk.io/store/v2"
|
||||
"cosmossdk.io/store/v2/commitment"
|
||||
"cosmossdk.io/store/v2/commitment/iavl"
|
||||
dbm "cosmossdk.io/store/v2/db"
|
||||
"cosmossdk.io/store/v2/proof"
|
||||
"cosmossdk.io/store/v2/storage"
|
||||
"cosmossdk.io/store/v2/storage/sqlite"
|
||||
)
|
||||
|
||||
type MockStore struct {
|
||||
Storage storev2.VersionedWriter
|
||||
Committer storev2.Committer
|
||||
}
|
||||
|
||||
func NewMockStorage(logger log.Logger, dir string) storev2.VersionedWriter {
|
||||
storageDB, _ := sqlite.New(dir)
|
||||
ss := storage.NewStorageStore(storageDB, logger)
|
||||
return ss
|
||||
}
|
||||
|
||||
func NewMockCommiter(logger log.Logger, actors ...string) storev2.Committer {
|
||||
treeMap := make(map[string]commitment.Tree)
|
||||
for _, actor := range actors {
|
||||
tree := iavl.NewIavlTree(dbm.NewMemDB(), logger, iavl.DefaultConfig())
|
||||
treeMap[actor] = tree
|
||||
}
|
||||
sc, _ := commitment.NewCommitStore(treeMap, treeMap, dbm.NewMemDB(), logger)
|
||||
return sc
|
||||
}
|
||||
|
||||
func NewMockStore(ss storev2.VersionedWriter, sc storev2.Committer) *MockStore {
|
||||
return &MockStore{Storage: ss, Committer: sc}
|
||||
}
|
||||
|
||||
func (s *MockStore) GetLatestVersion() (uint64, error) {
|
||||
lastCommitID, err := s.LastCommitID()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return lastCommitID.Version, nil
|
||||
}
|
||||
|
||||
func (s *MockStore) StateLatest() (uint64, corestore.ReaderMap, error) {
|
||||
v, err := s.GetLatestVersion()
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
return v, NewMockReaderMap(v, s), nil
|
||||
}
|
||||
|
||||
func (s *MockStore) Commit(changeset *corestore.Changeset) (corestore.Hash, error) {
|
||||
v, _, _ := s.StateLatest()
|
||||
err := s.Storage.ApplyChangeset(v, changeset)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
err = s.Committer.WriteChangeset(changeset)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
commitInfo, err := s.Committer.Commit(v + 1)
|
||||
fmt.Println("commitInfo", commitInfo, err)
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
func (s *MockStore) StateAt(version uint64) (corestore.ReaderMap, error) {
|
||||
info, err := s.Committer.GetCommitInfo(version)
|
||||
if err != nil || info == nil {
|
||||
return nil, fmt.Errorf("failed to get commit info for version %d: %w", version, err)
|
||||
}
|
||||
return NewMockReaderMap(version, s), nil
|
||||
}
|
||||
|
||||
func (s *MockStore) GetStateStorage() storev2.VersionedWriter {
|
||||
return s.Storage
|
||||
}
|
||||
|
||||
func (s *MockStore) GetStateCommitment() storev2.Committer {
|
||||
return s.Committer
|
||||
}
|
||||
|
||||
func (s *MockStore) Query(storeKey []byte, version uint64, key []byte, prove bool) (storev2.QueryResult, error) {
|
||||
state, err := s.StateAt(version)
|
||||
if err != nil {
|
||||
return storev2.QueryResult{}, err
|
||||
}
|
||||
|
||||
reader, err := state.GetReader(storeKey)
|
||||
if err != nil {
|
||||
return storev2.QueryResult{}, err
|
||||
}
|
||||
|
||||
value, err := reader.Get(key)
|
||||
if err != nil {
|
||||
return storev2.QueryResult{}, err
|
||||
}
|
||||
|
||||
res := storev2.QueryResult{
|
||||
Key: key,
|
||||
Value: value,
|
||||
Version: version,
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (s *MockStore) LastCommitID() (proof.CommitID, error) {
|
||||
v, err := s.GetStateCommitment().GetLatestVersion()
|
||||
bz := sha256.Sum256([]byte{})
|
||||
return proof.CommitID{
|
||||
Version: v,
|
||||
Hash: bz[:],
|
||||
}, err
|
||||
}
|
||||
|
||||
func (s *MockStore) SetInitialVersion(v uint64) error {
|
||||
return s.Committer.SetInitialVersion(v)
|
||||
}
|
||||
|
||||
func (s *MockStore) WorkingHash(changeset *corestore.Changeset) (corestore.Hash, error) {
|
||||
v, _, _ := s.StateLatest()
|
||||
err := s.Storage.ApplyChangeset(v, changeset)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
err = s.Committer.WriteChangeset(changeset)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
return []byte{}, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user