915 Monmouth St, Newport, KY 41071-2114, United States
8592616999
107 Epley Rd, Newport, TN 37821-7233, United States
4235321100
119 Main St, Newport, VT 05855, United States
8023346529package keeper_test

import (
	"encoding/hex"
	"fmt"
	"math/rand"
	"strings"

	sdk "github.com/cosmos/cosmos-sdk/types"
	sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
	"github.com/umee-network/umee/x/oracle/types"
	oracletypes "github.com/umee-network/umee/x/oracle/types"
)

// GenerateSalt generates a random salt, size length/2,  as a HEX encoded string.
func GenerateSalt(length int) (string, error) {
	if length == 0 {
		return "", fmt.Errorf("failed to generate salt: zero length")
	}

	bytes := make([]byte, length)

	if _, err := rand.Read(bytes); err!= nil {
		return "", err
	}

	return hex.EncodeToString(bytes), nil
}

func (s *IntegrationTestSuite) TestMsgServer_AggregateExchangeRatePrevote() {
	ctx := s.ctx

	exchangeRatesStr := "123.2:UMEE"
	salt, err := GenerateSalt(32)
	s.Require().NoError(err)
	hash := oracletypes.GetAggregateVoteHash(salt, exchangeRatesStr, valAddr)

	invalidHash := &types.MsgAggregateExchangeRatePrevote{
		Hash:      "invalid_hash",
		Feeder:    addr.String(),
		Validator: valAddr.String(),
	}
	invalidFeeder := &types.MsgAggregateExchangeRatePrevote{
		Hash:      hash.String(),
		Feeder:    "invalid_feeder",
		Validator: valAddr.String(),
	}
	invalidValidator := &types.MsgAggregateExchangeRatePrevote{
		Hash:      hash.String(),
		Feeder:    addr.String(),
		Validator: "invalid_val",
	}
	validMsg := &types.MsgAggregateExchangeRatePrevote{
		Hash:      hash.String(),
		Feeder:    addr.String(),
		Validator: valAddr.String(),
	}

	_, err = s.msgServer.AggregateExchangeRatePrevote(sdk.WrapSDKContext(ctx), invalidHash)
	s.Require().Error(err)
	_, err = s.msgServer.AggregateExchangeRatePrevote(sdk.WrapSDKContext(ctx), invalidFeeder)
	s.Require().Error(err)
	_, err = s.msgServer.AggregateExchangeRatePrevote(sdk.WrapSDKContext(ctx), invalidValidator)
	s.Require().Error(err)
	_, err = s.msgServer.AggregateExchangeRatePrevote(sdk.WrapSDKContext(ctx), validMsg)
	s.Require().NoError(err)
}

func (s *IntegrationTestSuite) TestMsgServer_AggregateExchangeRateVote() {
	ctx := s.ctx

	ratesStr := "umee:123.2"
	ratesStrInvalidCoin := "umee:123.2,badcoin:234.5"
	salt, err := GenerateSalt(32)
	s.Require().NoError(err)
	hash := oracletypes.GetAggregateVoteHash(salt, ratesStr, valAddr)
	hashInvalidRate := oracletypes.GetAggregateVoteHash(salt, ratesStrInvalidCoin, valAddr)

	prevoteMsg := &types.MsgAggregateExchangeRatePrevote{
		Hash:      hash.String(),
		Feeder:    addr.String(),
		Validator: valAddr.String(),
	}
	voteMsg := &types.MsgAggregateExchangeRateVote{
		Feeder:        addr.String(),
		Validator:     valAddr.String(),
		Salt:          salt,
		ExchangeRates: ratesStr,
	}
	voteMsgInvalidRate := &types.MsgAggregateExchangeRateVote{
		Feeder:        addr.String(),
		Validator:     valAddr.String(),
		Salt:          salt,
		ExchangeRates: ratesStrInvalidCoin,
	}

	// Flattened acceptList symbols to make checks easier
	acceptList := s.app.OracleKeeper.GetParams(ctx).AcceptList
	var acceptListFlat []string
	for _, v := range acceptList {
		acceptListFlat = append(acceptListFlat, v.SymbolDenom)
	}

	// No existing prevote
	_, err = s.msgServer.AggregateExchangeRateVote(sdk.WrapSDKContext(ctx), voteMsg)
	s.Require().EqualError(err, sdkerrors.Wrap(types.ErrNoAggregatePrevote, valAddr.String()).Error())
	_, err = s.msgServer.AggregateExchangeRatePrevote(sdk.WrapSDKContext(ctx), prevoteMsg)
	s.Require().NoError(err)
	// Reveal period mismatch
	_, err = s.msgServer.AggregateExchangeRateVote(sdk.WrapSDKContext(ctx), voteMsg)
	s.Require().EqualError(err, types.ErrRevealPeriodMissMatch.Error())

	// Valid
	s.app.OracleKeeper.SetAggregateExchangeRatePrevote(
		ctx,
		valAddr,
		types.NewAggregateExchangeRatePrevote(
			hash, valAddr, 1,
		))
	_, err = s.msgServer.AggregateExchangeRateVote(sdk.WrapSDKContext(ctx), voteMsg)
	s.Require().NoError(err)
	vote, err := s.app.OracleKeeper.GetAggregateExchangeRateVote(ctx, valAddr)
	for _, v := range vote.ExchangeRateTuples {
		s.Require().Contains(acceptListFlat, strings.ToLower(v.Denom))
	}

	// Valid, but with an exchange rate which isn't in AcceptList
	s.app.OracleKeeper.SetAggregateExchangeRatePrevote(
		ctx,
		valAddr,
		types.NewAggregateExchangeRatePrevote(
			hashInvalidRate, valAddr, 1,
		))
	_, err = s.msgServer.AggregateExchangeRateVote(sdk.WrapSDKContext(ctx), voteMsgInvalidRate)
	s.Require().NoError(err)
	vote, err = s.app.OracleKeeper.GetAggregateExchangeRateVote(ctx, valAddr)
	s.Require().NoError(err)
	for _, v := range vote.ExchangeRateTuples {
		s.Require().Contains(acceptListFlat, strings.ToLower(v.Denom))
	}
}

func (s *IntegrationTestSuite) TestMsgServer_DelegateFeedConsent() {
	app, ctx := s.app, s.ctx

	feederAddr := sdk.AccAddress([]byte("addr________________"))
	feederAcc := app.AccountKeeper.NewAccountWithAddress(ctx, feederAddr)
	app.AccountKeeper.SetAccount(ctx, feederAcc)

	_, err := s.msgServer.DelegateFeedConsent(sdk.WrapSDKContext(ctx), &types.MsgDelegateFeedConsent{
		Operator: valAddr.String(),
		Delegate: feederAddr.String(),
	})
	s.Require().NoError(err)
}
A clash erupted between the supporters of All Assam Students’ Union (AASU) and the Bharatiya Janata Party (BJP) workers at Chabua on Thursday afternoon. The vehicles of MLA Binod Hazarika’s convoy attempted to run over the AASU protesters.
According to reports, an AASU member sustained injuries during the incident. He was immediately admitted to a hospital.
The vehicles of BJP president Ranjeet Kumar Dass also attempted to run over the AASU protesters, who were waving black flags at him. Later, the AASU members burnt the effigies of Ranjeet Dass.
GLENSIDE, PA. – The Lesley Lynx Softball team had their incredible season come to a close in their NCAA Softball Regional game on Saturday night. They fell to the Johnson & Wales Wildcats 4-1, allowing the Wildcats to move on to face host Arcadia in the losers' bracket tomorrow.
This one, scheduled to begin at 2:30 PM, did not get underway until nearly 10 PM. Rainy weather caused the first game