prysm-pulse/testing/endtoend/components/eth1/depositor_test.go
kasey d58d3f2c57
E2E deposit testing overhaul (#11667)
* rewrite/refactor deposit testing code

keep track of sent deposits so that they can be compared in detail with
the validator set retreived from the API.

* fix bugs in evaluator and retry

* lint + deepsource appeasement

* typo s/Sprintf/Printf/

* gosec, more like nosec

* fix gosec number - 204->304

* type switch to get signed block from container

* improve comments

* centralizing constants and adding comments

* lock around Depositor to avoid future races

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
2022-11-19 03:40:32 +00:00

96 lines
1.9 KiB
Go

package eth1
import (
"fmt"
"strings"
"testing"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/testing/require"
)
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))
})
}
}