Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-dambovaliev committed Mar 26, 2024
1 parent eefe2de commit f0cefcf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 76 deletions.
30 changes: 0 additions & 30 deletions tm2/pkg/bft/consensus/types/round_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"time"

"github.com/gnolang/gno/tm2/ordering"

"github.com/gnolang/gno/tm2/pkg/bft/types"
)

Expand Down Expand Up @@ -97,34 +95,6 @@ type HRS struct {
Step RoundStepType `json:"step"`
}

func (hrs HRS) Compare(other HRS) ordering.Ordering {
if hrs.Height < other.Height {
return ordering.Less
}

if hrs.Height > other.Height {
return ordering.Greater
}

if hrs.Round < other.Round {
return ordering.Less
}

if hrs.Round > other.Round {
return ordering.Greater
}

if hrs.Step < other.Step {
return ordering.Less
}

if hrs.Step > other.Step {
return ordering.Greater
}

return ordering.Equal
}

func (hrs HRS) IsHRSZero() bool {
return hrs == HRS{}
}
Expand Down
46 changes: 0 additions & 46 deletions tm2/pkg/bft/consensus/types/round_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cstypes
import (
"testing"

"github.com/gnolang/gno/tm2/ordering"

amino "github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/bft/types"
tmtime "github.com/gnolang/gno/tm2/pkg/bft/types/time"
Expand Down Expand Up @@ -88,47 +86,3 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) {
amino.DeepCopy(rs)
}
}

func TestCompare(t *testing.T) {
tests := []struct {
name string
hrs1 HRS
hrs2 HRS
result ordering.Ordering
}{
{"Equal HRS", HRS{Height: 1, Round: 2, Step: RoundStepNewHeight}, HRS{Height: 1, Round: 2, Step: RoundStepNewHeight}, ordering.Equal},
{"HRS1 Lesser Height", HRS{Height: 1, Round: 2, Step: RoundStepNewHeight}, HRS{Height: 2, Round: 2, Step: RoundStepNewHeight}, ordering.Less},
{"HRS1 Greater Height", HRS{Height: 2, Round: 2, Step: RoundStepNewHeight}, HRS{Height: 1, Round: 2, Step: RoundStepNewHeight}, ordering.Greater},
{"Equal Height, HRS1 Lesser Round", HRS{Height: 1, Round: 2, Step: RoundStepNewHeight}, HRS{Height: 1, Round: 3, Step: RoundStepNewHeight}, ordering.Less},
{"Equal Height, HRS1 Greater Round", HRS{Height: 1, Round: 3, Step: RoundStepNewHeight}, HRS{Height: 1, Round: 2, Step: RoundStepNewHeight}, ordering.Greater},
{"Equal Height, Equal Round, HRS1 Lesser Step", HRS{Height: 1, Round: 2, Step: RoundStepNewHeight}, HRS{Height: 1, Round: 2, Step: RoundStepPropose}, ordering.Less},
{"Equal Height, Equal Round, HRS1 Greater Step", HRS{Height: 1, Round: 2, Step: RoundStepPropose}, HRS{Height: 1, Round: 2, Step: RoundStepNewHeight}, ordering.Greater},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.hrs1.Compare(tt.hrs2)
if result != tt.result {
t.Errorf("Expected %d, got %d", tt.result, result)
}
})
}

// Test cases for all RoundStepType values
t.Run("All RoundStepType Values", func(t *testing.T) {
for step1 := RoundStepInvalid; step1 <= RoundStepCommit; step1++ {
for step2 := RoundStepInvalid; step2 <= RoundStepCommit; step2++ {
hrs1 := HRS{Height: 1, Round: 2, Step: step1}
hrs2 := HRS{Height: 1, Round: 2, Step: step2}
result := hrs1.Compare(hrs2)
if step1 < step2 && result != ordering.Less {
t.Errorf("Expected -1, got %d for %s < %s", result, step1, step2)
} else if step1 > step2 && result != ordering.Greater {
t.Errorf("Expected 1, got %d for %s > %s", result, step1, step2)
} else if step1 == step2 && result != ordering.Equal {
t.Errorf("Expected 0, got %d for %s == %s", result, step1, step2)
}
}
}
})
}

0 comments on commit f0cefcf

Please sign in to comment.