From c5889a418ae27cd6694e43a555af1c2c1be110ce Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Thu, 3 Oct 2024 03:14:12 -0700 Subject: [PATCH] test(x/auth/vesting/types): test Periods.String() (#22059) --- x/auth/vesting/types/period_test.go | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 x/auth/vesting/types/period_test.go diff --git a/x/auth/vesting/types/period_test.go b/x/auth/vesting/types/period_test.go new file mode 100644 index 000000000000..636e6255a0d0 --- /dev/null +++ b/x/auth/vesting/types/period_test.go @@ -0,0 +1,49 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" +) + +func TestPeriodsString(t *testing.T) { + tests := []struct { + name string + periods types.Periods + want string + }{ + { + "empty slice", + nil, + "Vesting Periods:", + }, + { + "1 period", + types.Periods{ + {Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin("feeatom", 500), sdk.NewInt64Coin("statom", 50)}}, + }, + "Vesting Periods:\n\t\t" + `length:43200 amount: amount:`, + }, + { + "many", + types.Periods{ + {Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + {Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + {Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 100), sdk.NewInt64Coin(stakeDenom, 15)}}, + }, + "Vesting Periods:\n\t\t" + `length:43200 amount: amount: , ` + + `length:21600 amount: amount: , ` + + `length:21600 amount: amount:`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.periods.String() + if got != tt.want { + t.Fatalf("Mismatch in values:\n\tGot: %q\n\tWant: %q", got, tt.want) + } + }) + } +}