Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scottburch committed Nov 7, 2020
1 parent 4110b19 commit 2d74105
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
11 changes: 11 additions & 0 deletions x/crud/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package crud

import (
"encoding/json"
bluzellechain "github.com/bluzelle/curium/types"
"github.com/bluzelle/curium/x/crud/internal/types"
"github.com/bluzelle/curium/x/crud/mocks"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -32,6 +33,11 @@ import (
var DefaultLeaseBlockHeight = int64(math.Ceil(10 * 86400 / 5.5)) // (10 days of blocks * seconds/day) / 5

func initTest(t *testing.T) (*gomock.Controller, *mocks.MockIKeeper, sdk.Context, []byte) {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(bluzellechain.Bech32PrefixAccAddr, bluzellechain.Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(bluzellechain.Bech32PrefixValAddr, bluzellechain.Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(bluzellechain.Bech32PrefixConsAddr, bluzellechain.Bech32PrefixConsPub)

mockCtrl := gomock.NewController(t)
ctx := sdk.Context{}
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
Expand All @@ -51,10 +57,13 @@ func Test_handleMsgCreate(t *testing.T) {
setup := func(t *testing.T) (*gomock.Controller, *mocks.MockIKeeper, sdk.Context, []byte) {
mockCtrl, mockKeeper, ctx, owner := initTest(t)
defer mockCtrl.Finish()

mockKeeper.EXPECT().GetOwnerStore(ctx).AnyTimes().Return(nil)
mockKeeper.EXPECT().GetDefaultLeaseBlocks().AnyTimes().Return(DefaultLeaseBlockHeight)
// always return nil for a store...
mockKeeper.EXPECT().GetKVStore(ctx).AnyTimes().Return(nil)
mockKeeper.EXPECT().GetLeaseStore(gomock.Any()).AnyTimes().Return(nil)
mockKeeper.EXPECT().SetOwner(mockKeeper.GetKVStore(ctx), mockKeeper.GetOwnerStore(ctx), "uuid", "key", gomock.Any()).AnyTimes()

return mockCtrl, mockKeeper, ctx, owner
}
Expand Down Expand Up @@ -395,11 +404,13 @@ func Test_handleMsgDelete(t *testing.T) {
assert.Equal(t, deleteMsg.Type(), "delete")

// always return nil for a store...
mockKeeper.EXPECT().GetOwnerStore(ctx)
mockKeeper.EXPECT().GetKVStore(ctx).AnyTimes().Return(nil)

mockKeeper.EXPECT().GetLeaseStore(gomock.Any()).AnyTimes().Return(nil)

mockKeeper.EXPECT().GetOwner(ctx, nil, deleteMsg.UUID, deleteMsg.Key)
mockKeeper.EXPECT().DeleteOwner(gomock.Any(), gomock.Any(), "uuid", "key")

_, err := NewHandler(mockKeeper)(ctx, deleteMsg)
assert.NotNil(t, err)
Expand Down
6 changes: 4 additions & 2 deletions x/crud/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ func Test_MakeOwnerKey(t *testing.T) {

func TestKeeper_SetOwner(t *testing.T) {
_, testStore, _, cdc := initKeeperTest()
keeper := NewKeeper(nil, nil, nil,nil, cdc, MaxKeeperSizes{MaxDefaultLeaseBlocks: DefaultLeaseBlockHeight})

keeper := NewKeeper(nil, nil, nil, nil, cdc, MaxKeeperSizes{MaxDefaultLeaseBlocks: DefaultLeaseBlockHeight})
owner, _ := sdk.AccAddressFromBech32("bluzelle1rnnpyp9wr6law2u5jwa23t0ywtmrduldhcp079")
keeper.SetOwner(testStore, "uuid", "key", owner)
keeper.SetOwner(testStore, testStore, "uuid", "key", owner)


ownerKey := "bluzelle1rnnpyp9wr6law2u5jwa23t0ywtmrduldhcp079\x00uuid\x00key"

Expand Down
24 changes: 24 additions & 0 deletions x/crud/mocks/mock_keeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2d74105

Please sign in to comment.