2020-06-15 14:56:11 -07:00
|
|
|
package slotutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-02-23 02:20:57 +03:00
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
2020-06-15 14:56:11 -07:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2020-09-22 19:49:58 +08:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
2020-06-15 14:56:11 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSlotsSinceGenesis(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
genesis time.Time
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2021-02-16 10:45:34 +03:00
|
|
|
want types.Slot
|
2020-06-15 14:56:11 -07:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "pre-genesis",
|
|
|
|
args: args{
|
2020-09-22 19:49:58 +08:00
|
|
|
genesis: timeutils.Now().Add(1 * time.Hour), // 1 hour in the future
|
2020-06-15 14:56:11 -07:00
|
|
|
},
|
|
|
|
want: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "post-genesis",
|
|
|
|
args: args{
|
2020-09-22 19:49:58 +08:00
|
|
|
genesis: timeutils.Now().Add(-5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
2020-06-15 14:56:11 -07:00
|
|
|
},
|
|
|
|
want: 5,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := SlotsSinceGenesis(tt.args.genesis); got != tt.want {
|
|
|
|
t.Errorf("SlotsSinceGenesis() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|