|
| 1 | +package types_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 7 | + "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" |
| 8 | +) |
| 9 | + |
| 10 | +func TestPeriodsString(t *testing.T) { |
| 11 | + tests := []struct { |
| 12 | + name string |
| 13 | + periods types.Periods |
| 14 | + want string |
| 15 | + }{ |
| 16 | + { |
| 17 | + "empty slice", |
| 18 | + nil, |
| 19 | + "Vesting Periods:", |
| 20 | + }, |
| 21 | + { |
| 22 | + "1 period", |
| 23 | + types.Periods{ |
| 24 | + {Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin("feeatom", 500), sdk.NewInt64Coin("statom", 50)}}, |
| 25 | + }, |
| 26 | + "Vesting Periods:\n\t\t" + `length:43200 amount:<denom:"feeatom" amount:"500" > amount:<denom:"statom" amount:"50" >`, |
| 27 | + }, |
| 28 | + { |
| 29 | + "many", |
| 30 | + types.Periods{ |
| 31 | + {Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, |
| 32 | + {Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, |
| 33 | + {Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 100), sdk.NewInt64Coin(stakeDenom, 15)}}, |
| 34 | + }, |
| 35 | + "Vesting Periods:\n\t\t" + `length:43200 amount:<denom:"fee" amount:"500" > amount:<denom:"stake" amount:"50" > , ` + |
| 36 | + `length:21600 amount:<denom:"fee" amount:"250" > amount:<denom:"stake" amount:"25" > , ` + |
| 37 | + `length:21600 amount:<denom:"fee" amount:"100" > amount:<denom:"stake" amount:"15" >`, |
| 38 | + }, |
| 39 | + } |
| 40 | + |
| 41 | + for _, tt := range tests { |
| 42 | + t.Run(tt.name, func(t *testing.T) { |
| 43 | + got := tt.periods.String() |
| 44 | + if got != tt.want { |
| 45 | + t.Fatalf("Mismatch in values:\n\tGot: %q\n\tWant: %q", got, tt.want) |
| 46 | + } |
| 47 | + }) |
| 48 | + } |
| 49 | +} |
0 commit comments