Skip to content

Commit

Permalink
[1789]: Unit tests on the GetNav keeper func.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpicyLemon committed Jan 23, 2024
1 parent 773c026 commit e35ade1
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion x/exchange/keeper/fulfillment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/provenance-io/provenance/x/exchange"
markertypes "github.com/provenance-io/provenance/x/marker/types"
)
Expand Down Expand Up @@ -2507,4 +2508,56 @@ func (s *TestSuite) TestKeeper_SettleOrders() {
}
}

// TODO[1789]: func (s *TestSuite) TestKeeper_GetNav()
func (s *TestSuite) TestKeeper_GetNav() {
tests := []struct {
name string
markerKeeper *MockMarkerKeeper
assetsDenom string
priceDenom string
expNav *exchange.NetAssetPrice
}{
{
name: "error getting nav",
markerKeeper: NewMockMarkerKeeper().WithGetNetAssetValueError("apple", "pear", "injected test error"),
assetsDenom: "apple",
priceDenom: "pear",
expNav: nil,
},
{
name: "no nav found",
assetsDenom: "apple",
priceDenom: "pear",
expNav: nil,
},
{
name: "nav exists",
markerKeeper: NewMockMarkerKeeper().
WithGetNetAssetValueResult(sdk.NewInt64Coin("apple", 500), sdk.NewInt64Coin("pear", 12)),
assetsDenom: "apple",
priceDenom: "pear",
expNav: &exchange.NetAssetPrice{
Assets: sdk.NewInt64Coin("apple", 500),
Price: sdk.NewInt64Coin("pear", 12),
},
},
}

for _, tc := range tests {
s.Run(tc.name, func() {
if tc.markerKeeper == nil {
tc.markerKeeper = NewMockMarkerKeeper()
}

kpr := s.k.WithMarkerKeeper(tc.markerKeeper)
var actNav *exchange.NetAssetPrice
testFunc := func() {
actNav = kpr.GetNav(s.ctx, tc.assetsDenom, tc.priceDenom)
}
s.Require().NotPanics(testFunc, "GetNav(%q, %q)", tc.assetsDenom, tc.priceDenom)
if !s.Assert().Equal(tc.expNav, actNav, "GetNav(%q, %q) result", tc.assetsDenom, tc.priceDenom) && tc.expNav != nil && actNav != nil {
s.Assert().Equal(tc.expNav.Assets.String(), actNav.Assets.String(), "assets (string)")
s.Assert().Equal(tc.expNav.Price.String(), actNav.Price.String(), "price (string)")
}
})
}
}

0 comments on commit e35ade1

Please sign in to comment.