2022-11-19 03:40:32 +00:00
|
|
|
package eth1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
2022-11-19 03:40:32 +00:00
|
|
|
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
2022-11-19 03:40:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestComputeDeposits(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
nvals int
|
|
|
|
offset int
|
|
|
|
partial bool
|
|
|
|
err error
|
|
|
|
len int
|
|
|
|
name string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
nvals: 100,
|
|
|
|
offset: 0,
|
|
|
|
partial: false,
|
|
|
|
len: 100,
|
|
|
|
name: "offset 0",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nvals: 100,
|
|
|
|
offset: 50,
|
|
|
|
partial: false,
|
|
|
|
len: 100,
|
|
|
|
name: "offset 50",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nvals: 100,
|
|
|
|
offset: 0,
|
|
|
|
partial: true,
|
|
|
|
len: 150,
|
|
|
|
name: "offset 50, partial",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nvals: 100,
|
|
|
|
offset: 50,
|
|
|
|
partial: true,
|
|
|
|
len: 150,
|
|
|
|
name: "offset 50, partial",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nvals: 100,
|
|
|
|
offset: 23,
|
|
|
|
partial: true,
|
|
|
|
len: 150,
|
|
|
|
name: "offset 23, partial",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nvals: 23,
|
|
|
|
offset: 0,
|
|
|
|
partial: true,
|
|
|
|
len: 35, // half of 23 (rounding down) is 11
|
|
|
|
name: "offset 23, partial",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
t.Run(c.name, func(t *testing.T) {
|
|
|
|
totals := make(map[string]uint64, c.nvals)
|
|
|
|
d, err := computeDeposits(c.offset, c.nvals, c.partial)
|
|
|
|
for _, dd := range d {
|
|
|
|
require.Equal(t, 48, len(dd.Data.PublicKey))
|
|
|
|
k := fmt.Sprintf("%#x", dd.Data.PublicKey)
|
|
|
|
if _, ok := totals[k]; !ok {
|
|
|
|
totals[k] = dd.Data.Amount
|
|
|
|
} else {
|
|
|
|
totals[k] += dd.Data.Amount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
complete := make([]string, 0)
|
|
|
|
incomplete := make([]string, 0)
|
|
|
|
for k, v := range totals {
|
|
|
|
if params.BeaconConfig().MaxEffectiveBalance != v {
|
|
|
|
incomplete = append(incomplete, fmt.Sprintf("%s=%d", k, v))
|
|
|
|
} else {
|
|
|
|
complete = append(complete, k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.Equal(t, 0, len(incomplete), strings.Join(incomplete, ", "))
|
|
|
|
require.Equal(t, c.nvals, len(complete), strings.Join(complete, ", "))
|
|
|
|
if err != nil {
|
|
|
|
require.ErrorIs(t, err, c.err)
|
|
|
|
}
|
|
|
|
require.Equal(t, c.len, len(d))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|