Skip to content

Commit

Permalink
fix most tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kpeluso committed Aug 29, 2024
1 parent 93459b5 commit 16967cd
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 254 deletions.
24 changes: 14 additions & 10 deletions test/integration/create_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ func CreateTopic(m testCommon.TestConfig) (topicId uint64) {
require.Positive(m.T, topicIdStart.NextTopicId)
require.NoError(m.T, err)
createTopicRequest := &emissionstypes.MsgCreateNewTopic{
Creator: m.AliceAddr,
Metadata: "ETH 24h Prediction",
LossMethod: "mse",
EpochLength: 5,
GroundTruthLag: 10,
WorkerSubmissionWindow: 4,
PNorm: alloraMath.NewDecFromInt64(3),
AlphaRegret: alloraMath.MustNewDecFromString("0.1"),
AllowNegative: true,
Epsilon: alloraMath.MustNewDecFromString("0.01"),
Creator: m.AliceAddr,
Metadata: "ETH 24h Prediction",
LossMethod: "mse",
EpochLength: 5,
GroundTruthLag: 10,
WorkerSubmissionWindow: 4,
PNorm: alloraMath.NewDecFromInt64(3),
AlphaRegret: alloraMath.MustNewDecFromString("0.1"),
AllowNegative: true,
Epsilon: alloraMath.MustNewDecFromString("0.01"),
MeritSortitionAlpha: alloraMath.MustNewDecFromString("0.1"),
ActiveInfererQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveForecasterQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveReputerQuantile: alloraMath.MustNewDecFromString("0.25"),
}
txResp, err := m.Client.BroadcastTx(ctx, m.AliceAcc, createTopicRequest)
require.NoError(m.T, err)
Expand Down
24 changes: 14 additions & 10 deletions test/invariant/topics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ func createTopic(
wasErr := false
iterLog(m.T, iteration, actor, "creating new topic")
createTopicRequest := &emissionstypes.MsgCreateNewTopic{
Creator: actor.addr,
Metadata: fmt.Sprintf("Created topic iteration %d", iteration),
LossMethod: "mse",
EpochLength: data.epochLength,
GroundTruthLag: data.epochLength,
WorkerSubmissionWindow: 10,
PNorm: alloraMath.NewDecFromInt64(3),
AlphaRegret: alloraMath.MustNewDecFromString("0.1"),
AllowNegative: true,
Epsilon: alloraMath.MustNewDecFromString("0.01"),
Creator: actor.addr,
Metadata: fmt.Sprintf("Created topic iteration %d", iteration),
LossMethod: "mse",
EpochLength: data.epochLength,
GroundTruthLag: data.epochLength,
WorkerSubmissionWindow: 10,
PNorm: alloraMath.NewDecFromInt64(3),
AlphaRegret: alloraMath.MustNewDecFromString("0.1"),
AllowNegative: true,
Epsilon: alloraMath.MustNewDecFromString("0.01"),
MeritSortitionAlpha: alloraMath.MustNewDecFromString("0.1"),
ActiveInfererQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveForecasterQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveReputerQuantile: alloraMath.MustNewDecFromString("0.25"),
}

ctx := context.Background()
Expand Down
24 changes: 14 additions & 10 deletions test/stress/create_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ func createTopic(
) (topicId uint64) {
ctx := context.Background()
createTopicRequest := &emissionstypes.MsgCreateNewTopic{
Creator: creator.aa.addr,
Metadata: "ETH 24h Prediction",
LossMethod: "mse",
EpochLength: epochLength,
GroundTruthLag: epochLength,
WorkerSubmissionWindow: epochLength,
PNorm: alloraMath.NewDecFromInt64(3),
AlphaRegret: alloraMath.NewDecFromInt64(1),
AllowNegative: true,
Epsilon: alloraMath.MustNewDecFromString("0.01"),
Creator: creator.aa.addr,
Metadata: "ETH 24h Prediction",
LossMethod: "mse",
EpochLength: epochLength,
GroundTruthLag: epochLength,
WorkerSubmissionWindow: epochLength,
PNorm: alloraMath.NewDecFromInt64(3),
AlphaRegret: alloraMath.NewDecFromInt64(1),
AllowNegative: true,
Epsilon: alloraMath.MustNewDecFromString("0.01"),
MeritSortitionAlpha: alloraMath.MustNewDecFromString("0.1"),
ActiveInfererQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveForecasterQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveReputerQuantile: alloraMath.MustNewDecFromString("0.25"),
}

txResp, err := m.Client.BroadcastTx(ctx, creator.aa.acc, createTopicRequest)
Expand Down
24 changes: 14 additions & 10 deletions x/emissions/keeper/actor_utils/scores_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ func (s *ActorUtilsTestSuite) TestGetReputersScoresFromCsv() {
block := int64(1003)

newTopicMsg := &types.MsgCreateNewTopic{
Creator: s.addrs[0].String(),
Metadata: "test",
LossMethod: "mse",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10,
PNorm: alloraMath.NewDecFromInt64(3),
AlphaRegret: alloraMath.MustNewDecFromString("0.1"),
AllowNegative: true,
Epsilon: alloraMath.MustNewDecFromString("0.01"),
Creator: s.addrs[0].String(),
Metadata: "test",
LossMethod: "mse",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10,
PNorm: alloraMath.NewDecFromInt64(3),
AlphaRegret: alloraMath.MustNewDecFromString("0.1"),
AllowNegative: true,
Epsilon: alloraMath.MustNewDecFromString("0.01"),
MeritSortitionAlpha: alloraMath.MustNewDecFromString("0.1"),
ActiveInfererQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveForecasterQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveReputerQuantile: alloraMath.MustNewDecFromString("0.25"),
}
res, err := s.msgServer.CreateNewTopic(s.ctx, newTopicMsg)
s.Require().NoError(err)
Expand Down
22 changes: 13 additions & 9 deletions x/emissions/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,19 @@ func (s *KeeperTestSuite) CreateOneTopic() uint64 {
creator := sdk.AccAddress(PKS[0].Address())

newTopicMsg := &types.MsgCreateNewTopic{
Creator: creator.String(),
Metadata: metadata,
LossMethod: "method",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10800,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
Creator: creator.String(),
Metadata: metadata,
LossMethod: "method",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10800,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
MeritSortitionAlpha: alloraMath.MustNewDecFromString("0.1"),
ActiveInfererQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveForecasterQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveReputerQuantile: alloraMath.MustNewDecFromString("0.25"),
}

s.MintTokensToAddress(creator, types.DefaultParams().CreateTopicFee)
Expand Down
22 changes: 13 additions & 9 deletions x/emissions/keeper/msgserver/msg_server_registrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,19 @@ func (s *MsgServerTestSuite) TestBlocklistedAddressUnableToRegister() {
s.MintTokensToAddress(worker, cosmosMath.NewInt(10).Mul(cosmosOneE18))
// Create topic
newTopicMsg := &types.MsgCreateNewTopic{
Creator: worker.String(),
Metadata: "test",
LossMethod: "mse",
EpochLength: epochLength,
GroundTruthLag: epochLength,
WorkerSubmissionWindow: 10,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
Creator: worker.String(),
Metadata: "test",
LossMethod: "mse",
EpochLength: epochLength,
GroundTruthLag: epochLength,
WorkerSubmissionWindow: 10,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
MeritSortitionAlpha: alloraMath.MustNewDecFromString("0.1"),
ActiveInfererQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveForecasterQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveReputerQuantile: alloraMath.MustNewDecFromString("0.25"),
}
res, err := s.msgServer.CreateNewTopic(s.ctx, newTopicMsg)
s.Require().NoError(err)
Expand Down
35 changes: 14 additions & 21 deletions x/emissions/keeper/msgserver/msg_server_reputer_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,14 @@ func (ms msgServer) InsertReputerPayload(ctx context.Context, msg *types.MsgInse
blockHeight := sdkCtx.BlockHeight()

// Call the bundles self validation method
if err := validateReputerValueBundle(msg.Sender, msg.ReputerValueBundle); err != nil {
if err := validateReputerValueBundle(msg.ReputerValueBundle); err != nil {
return nil, errorsmod.Wrapf(err,
"Error validating reputer value bundle for block height %d", blockHeight)
}

nonce := msg.ReputerValueBundle.ValueBundle.ReputerRequestNonce
topicId := msg.ReputerValueBundle.ValueBundle.TopicId
reputer := msg.Sender

// the reputer in the bundle must match the sender of this transaction
if reputer != msg.ReputerValueBundle.ValueBundle.Reputer {
return nil, errorsmod.Wrapf(types.ErrInvalidWorkerData,
"Reputer cannot upload value bundle for another reputer")
}
reputer := msg.ReputerValueBundle.ValueBundle.Reputer

// Check if the topic exists
topicExists, err := ms.k.TopicExists(ctx, topicId)
Expand All @@ -60,8 +54,7 @@ func (ms msgServer) InsertReputerPayload(ctx context.Context, msg *types.MsgInse
return nil, errorsmod.Wrapf(err, "Error checking if reputer is registered in topic")
}
if !isReputerRegistered {
return nil, errorsmod.Wrapf(types.ErrInvalidWorkerData,
"Reputer not registered in topic")
return nil, errorsmod.Wrapf(types.ErrInvalidReputerData, "Reputer not registered in topic")
}

// Check if the worker nonce is fulfilled
Expand Down Expand Up @@ -106,7 +99,7 @@ func (ms msgServer) InsertReputerPayload(ctx context.Context, msg *types.MsgInse
return nil, errorsmod.Wrapf(err, "Error getting reputer stake for sender: %v", &msg.Sender)
}
if reputerStake.LT(moduleParams.RequiredMinimumStake) {
return nil, errorsmod.Wrapf(types.ErrInvalidWorkerData,
return nil, errorsmod.Wrapf(types.ErrInvalidReputerData,
"Reputer must have minimum stake in order to participate in topic")
}

Expand Down Expand Up @@ -214,7 +207,7 @@ func validateWithheldWorkerAttributedValue(withheldWorkerValue *types.WithheldWo
}

// validateReputerValueBundle validates a ReputerValueBundle
func validateReputerValueBundle(msgSender string, bundle *types.ReputerValueBundle) error {
func validateReputerValueBundle(bundle *types.ReputerValueBundle) error {
if bundle.ValueBundle == nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "value bundle cannot be nil")
}
Expand All @@ -224,9 +217,15 @@ func validateReputerValueBundle(msgSender string, bundle *types.ReputerValueBund
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid reputer address (%s)", err)
}

if bundle.ValueBundle.Reputer != msgSender {
return errorsmod.Wrapf(types.ErrUnauthorized,
"Reputer does not match transaction sender")
pk, err := hex.DecodeString(bundle.Pubkey)
if err != nil || len(pk) != secp256k1.PubKeySize {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid pubkey")
}
pubkey := secp256k1.PubKey(pk)
pubKeyConvertedToAddress := sdk.AccAddress(pubkey.Address().Bytes()).String()

if bundle.ValueBundle.Reputer != pubKeyConvertedToAddress {
return errorsmod.Wrapf(types.ErrUnauthorized, "Reputer does not match pubkey")
}

if bundle.ValueBundle.ReputerRequestNonce == nil {
Expand Down Expand Up @@ -283,12 +282,6 @@ func validateReputerValueBundle(msgSender string, bundle *types.ReputerValueBund
}
}

pk, err := hex.DecodeString(bundle.Pubkey)
if err != nil || len(pk) != secp256k1.PubKeySize {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "signature verification failed")
}
pubkey := secp256k1.PubKey(pk)

src := make([]byte, 0)
src, _ = bundle.ValueBundle.XXX_Marshal(src, true)
if !pubkey.VerifySignature(src, bundle.Signature) {
Expand Down
22 changes: 13 additions & 9 deletions x/emissions/keeper/msgserver/msg_server_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ func (s *MsgServerTestSuite) commonStakingSetup(

// Create Topic
newTopicMsg := &types.MsgCreateNewTopic{
Creator: reputerAddr.String(),
Metadata: "Some metadata for the new topic",
LossMethod: "mse",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
Creator: reputerAddr.String(),
Metadata: "Some metadata for the new topic",
LossMethod: "mse",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
MeritSortitionAlpha: alloraMath.MustNewDecFromString("0.1"),
ActiveInfererQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveForecasterQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveReputerQuantile: alloraMath.MustNewDecFromString("0.25"),
}

reputerInitialBalance := types.DefaultParams().CreateTopicFee.Add(reputerInitialBalanceUint)
Expand Down
44 changes: 26 additions & 18 deletions x/emissions/keeper/msgserver/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,19 @@ func (s *MsgServerTestSuite) CreateOneTopic() uint64 {
creator := sdk.AccAddress(PKS[0].Address())

newTopicMsg := &types.MsgCreateNewTopic{
Creator: creator.String(),
Metadata: metadata,
LossMethod: "mse",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
Creator: creator.String(),
Metadata: metadata,
LossMethod: "mse",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
MeritSortitionAlpha: alloraMath.MustNewDecFromString("0.1"),
ActiveInfererQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveForecasterQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveReputerQuantile: alloraMath.MustNewDecFromString("0.25"),
}

s.MintTokensToAddress(creator, types.DefaultParams().CreateTopicFee)
Expand All @@ -220,15 +224,19 @@ func (s *MsgServerTestSuite) TestCreateSeveralTopics() {
creator := sdk.AccAddress(PKS[0].Address())

newTopicMsg := &types.MsgCreateNewTopic{
Creator: creator.String(),
Metadata: metadata,
LossMethod: "mse",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
Creator: creator.String(),
Metadata: metadata,
LossMethod: "mse",
EpochLength: 10800,
GroundTruthLag: 10800,
WorkerSubmissionWindow: 10,
AlphaRegret: alloraMath.NewDecFromInt64(1),
PNorm: alloraMath.NewDecFromInt64(3),
Epsilon: alloraMath.MustNewDecFromString("0.01"),
MeritSortitionAlpha: alloraMath.MustNewDecFromString("0.1"),
ActiveInfererQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveForecasterQuantile: alloraMath.MustNewDecFromString("0.25"),
ActiveReputerQuantile: alloraMath.MustNewDecFromString("0.25"),
}

creatorInitialBalance := types.DefaultParams().CreateTopicFee.Mul(cosmosMath.NewInt(3))
Expand Down
Loading

0 comments on commit 16967cd

Please sign in to comment.