0g-chain/x/pricefeed/keeper/msg_server_test.go
Ruaridh ffef832d45
Upgrade to sdk v0.44.5 and add IBC (#1106)
- Upgrade cosmos-sdk to v0.44.5 from v0.39.2
- Add Legacy Tx Endpoint for backwards compatibility
- Add IBC v1.2.3 Support

Co-authored-by: DracoLi <draco@dracoli.com>
Co-authored-by: drklee3 <derrick@dlee.dev>
Co-authored-by: denalimarsh <denalimarsh@gmail.com>
Co-authored-by: Draco Li <draco@kava.io>
Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
Co-authored-by: Denali Marsh <denali@kava.io>
2022-01-07 17:39:27 -07:00

64 lines
1.9 KiB
Go

package keeper_test
import (
"testing"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/pricefeed/keeper"
"github.com/kava-labs/kava/x/pricefeed/types"
"github.com/stretchr/testify/require"
tmprototypes "github.com/tendermint/tendermint/proto/tendermint/types"
)
func TestKeeper_PostPrice(t *testing.T) {
_, addrs := app.GeneratePrivKeyAddressPairs(4)
tApp := app.NewTestApp()
ctx := tApp.NewContext(true, tmprototypes.Header{}).
WithBlockTime(time.Now().UTC())
k := tApp.GetPriceFeedKeeper()
msgSrv := keeper.NewMsgServerImpl(k)
authorizedOracles := addrs[:2]
unauthorizedAddrs := addrs[2:]
mp := types.Params{
Markets: []types.Market{
{MarketID: "tstusd", BaseAsset: "tst", QuoteAsset: "usd", Oracles: authorizedOracles, Active: true},
},
}
k.SetParams(ctx, mp)
now := time.Now().UTC()
tests := []struct {
giveMsg string
giveOracle sdk.AccAddress
giveMarketId string
giveExpiry time.Time
wantAccepted bool
errorKind error
}{
{"authorized", authorizedOracles[0], "tstusd", now.Add(time.Hour * 1), true, nil},
{"expired", authorizedOracles[0], "tstusd", now.Add(-time.Hour * 1), false, types.ErrExpired},
{"invalid", authorizedOracles[0], "invalid", now.Add(time.Hour * 1), false, types.ErrInvalidMarket},
{"unauthorized", unauthorizedAddrs[0], "tstusd", now.Add(time.Hour * 1), false, types.ErrInvalidOracle},
}
for _, tt := range tests {
t.Run(tt.giveMsg, func(t *testing.T) {
// Use MsgServer over keeper methods directly to tests against valid oracles
msg := types.NewMsgPostPrice(tt.giveOracle.String(), tt.giveMarketId, sdk.MustNewDecFromStr("0.5"), tt.giveExpiry)
_, err := msgSrv.PostPrice(sdk.WrapSDKContext(ctx), msg)
if tt.wantAccepted {
require.NoError(t, err)
} else {
require.Error(t, err)
require.ErrorIs(t, tt.errorKind, err)
}
})
}
}