Skip to content

Commit

Permalink
chore: add tally test
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Dec 21, 2023
1 parent 0a7f4ac commit 9c3d48b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/types/tally_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package types

import (

Check failure on line 3 in pkg/types/tally_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"cosmossdk.io/math"
"github.com/stretchr/testify/assert"
"testing"
)

func TestTallyGetVoted(t *testing.T) {
t.Parallel()

tally := Tally{
{Option: "Yes", Voted: math.LegacyNewDec(2)},
{Option: "No", Voted: math.LegacyNewDec(3)},
{Option: "Abstain", Voted: math.LegacyNewDec(5)},
}

assert.Equal(t, "20.00%", tally.GetVoted(tally[0]), "Wrong value!")
}

func TestTallyGetQuorum(t *testing.T) {
t.Parallel()

tallyInfo := TallyInfo{
Tally: Tally{
{Option: "idk", Voted: math.LegacyNewDec(3)},
},
TotalVotingPower: math.LegacyNewDec(10),
}

assert.Equal(t, "30.00%", tallyInfo.GetQuorum(), "Wrong value!")
}

func TestTallyGetNotVoted(t *testing.T) {
t.Parallel()

tallyInfo := TallyInfo{
Tally: Tally{
{Option: "idk", Voted: math.LegacyNewDec(3)},
},
TotalVotingPower: math.LegacyNewDec(10),
}

assert.Equal(t, "70.00%", tallyInfo.GetNotVoted(), "Wrong value!")
}

0 comments on commit 9c3d48b

Please sign in to comment.