mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-16 14:58:46 +00:00
2f10b1c7b1
* Remove gogoproto compiler * Remove more gogoproto * Improvements * Fix gengo * More scripts * Gazelle, fix deps * Fix version and errors * Fix gocast for arrays * Fix ethapis * Fixes * Fix compile errors * fix go.mod * //proto/... builds * Update for protov2 * temp fix compilation to move on * Change everything to emptypb.empty * Add grpc to proto/slashings * Fix almost all build failures * Oher build problems * FIX THIS FUCKING THING * gaz literally every .bazel * Final touches * Final final touches * Fix proto * Begin moving proto.Marshal to native * Fix site_data * Fixes * Fix duplicate gateway * Fix gateway target * Fix ethapis * Fixes from review * Update * Fix * Fix status test * Fix fuzz * Add isprotoslice to fun * Change DeepEqual to DeepSSZEqual for proto arrays * Fix build * Fix gaz * Update go * Fixes * Fixes * Add case for nil validators after copy * Fix cast * Fix test * Fix imports * Go mod * Only use extension where needed * Fixes * Split gateway from gengo * gaz * go mod * Add back hydrated state * fix hydrate * Fix proto.clone * Fies * Revert "Split gateway from gengo" This reverts commit 7298bb2054d446e427d9af97e13b8fabe8695085. * Revert "gaz" This reverts commit ca952565701a88727e22302d6c8d60ac48d97255. * Merge all gateway into one target * go mod * Gaz * Add generate v1_gateway files * run pb again * goimports * gaz * Fix comments * Fix protos * Fix PR * Fix protos * Update grpc-gateway and ethapis * Update ethapis and gen-go-cast * Go tidy * Reorder * Fix ethapis * fix spec tests * Fix script * Remove unused import * Fix fuzz * Fix gomod * Update version * Error if the cloned result is nil * Handle optional slots * ADd more empty checks to clone * Undo fuzz changes * Fix build.bazel * Gaz * Redo fuzz changes * Undo some eth1data changes * Update go.mod Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Undo clone beacon state * Remove gogo proto more and unused v1_gateway * Add manual fix for nil vals * Fix gaz * tidy * Tidy again * Add detailed error * Revert "Add detailed error" This reverts commit 59bc053dcd59569a54c95b07739d5a379665ec5d. * Undo varint changes * Fix nil validators in deposit test * Commit * Undo Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
162 lines
5.0 KiB
Go
162 lines
5.0 KiB
Go
package depositcache
|
|
|
|
import (
|
|
"context"
|
|
"math/big"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
dbpb "github.com/prysmaticlabs/prysm/proto/beacon/db"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
var _ PendingDepositsFetcher = (*DepositCache)(nil)
|
|
|
|
func TestInsertPendingDeposit_OK(t *testing.T) {
|
|
dc := DepositCache{}
|
|
dc.InsertPendingDeposit(context.Background(), ðpb.Deposit{}, 111, 100, [32]byte{})
|
|
|
|
assert.Equal(t, 1, len(dc.pendingDeposits), "Deposit not inserted")
|
|
}
|
|
|
|
func TestInsertPendingDeposit_ignoresNilDeposit(t *testing.T) {
|
|
dc := DepositCache{}
|
|
dc.InsertPendingDeposit(context.Background(), nil /*deposit*/, 0 /*blockNum*/, 0, [32]byte{})
|
|
|
|
assert.Equal(t, 0, len(dc.pendingDeposits))
|
|
}
|
|
|
|
func TestRemovePendingDeposit_OK(t *testing.T) {
|
|
db := DepositCache{}
|
|
proof1 := makeDepositProof()
|
|
proof1[0] = bytesutil.PadTo([]byte{'A'}, 32)
|
|
proof2 := makeDepositProof()
|
|
proof2[0] = bytesutil.PadTo([]byte{'A'}, 32)
|
|
data := ðpb.Deposit_Data{
|
|
PublicKey: make([]byte, 48),
|
|
WithdrawalCredentials: make([]byte, 32),
|
|
Amount: 0,
|
|
Signature: make([]byte, 96),
|
|
}
|
|
depToRemove := ðpb.Deposit{Proof: proof1, Data: data}
|
|
otherDep := ðpb.Deposit{Proof: proof2, Data: data}
|
|
db.pendingDeposits = []*dbpb.DepositContainer{
|
|
{Deposit: depToRemove, Index: 1},
|
|
{Deposit: otherDep, Index: 5},
|
|
}
|
|
db.RemovePendingDeposit(context.Background(), depToRemove)
|
|
|
|
if len(db.pendingDeposits) != 1 || !proto.Equal(db.pendingDeposits[0].Deposit, otherDep) {
|
|
t.Error("Failed to remove deposit")
|
|
}
|
|
}
|
|
|
|
func TestRemovePendingDeposit_IgnoresNilDeposit(t *testing.T) {
|
|
dc := DepositCache{}
|
|
dc.pendingDeposits = []*dbpb.DepositContainer{{Deposit: ðpb.Deposit{}}}
|
|
dc.RemovePendingDeposit(context.Background(), nil /*deposit*/)
|
|
assert.Equal(t, 1, len(dc.pendingDeposits), "Deposit unexpectedly removed")
|
|
}
|
|
|
|
func TestPendingDeposit_RoundTrip(t *testing.T) {
|
|
dc := DepositCache{}
|
|
proof := makeDepositProof()
|
|
proof[0] = bytesutil.PadTo([]byte{'A'}, 32)
|
|
data := ðpb.Deposit_Data{
|
|
PublicKey: make([]byte, 48),
|
|
WithdrawalCredentials: make([]byte, 32),
|
|
Amount: 0,
|
|
Signature: make([]byte, 96),
|
|
}
|
|
dep := ðpb.Deposit{Proof: proof, Data: data}
|
|
dc.InsertPendingDeposit(context.Background(), dep, 111, 100, [32]byte{})
|
|
dc.RemovePendingDeposit(context.Background(), dep)
|
|
assert.Equal(t, 0, len(dc.pendingDeposits), "Failed to insert & delete a pending deposit")
|
|
}
|
|
|
|
func TestPendingDeposits_OK(t *testing.T) {
|
|
dc := DepositCache{}
|
|
|
|
dc.pendingDeposits = []*dbpb.DepositContainer{
|
|
{Eth1BlockHeight: 2, Deposit: ðpb.Deposit{Proof: [][]byte{[]byte("A")}}},
|
|
{Eth1BlockHeight: 4, Deposit: ðpb.Deposit{Proof: [][]byte{[]byte("B")}}},
|
|
{Eth1BlockHeight: 6, Deposit: ðpb.Deposit{Proof: [][]byte{[]byte("c")}}},
|
|
}
|
|
|
|
deposits := dc.PendingDeposits(context.Background(), big.NewInt(4))
|
|
expected := []*ethpb.Deposit{
|
|
{Proof: [][]byte{[]byte("A")}},
|
|
{Proof: [][]byte{[]byte("B")}},
|
|
}
|
|
assert.DeepSSZEqual(t, expected, deposits)
|
|
|
|
all := dc.PendingDeposits(context.Background(), nil)
|
|
assert.Equal(t, len(dc.pendingDeposits), len(all), "PendingDeposits(ctx, nil) did not return all deposits")
|
|
}
|
|
|
|
func TestPrunePendingDeposits_ZeroMerkleIndex(t *testing.T) {
|
|
dc := DepositCache{}
|
|
|
|
dc.pendingDeposits = []*dbpb.DepositContainer{
|
|
{Eth1BlockHeight: 2, Index: 2},
|
|
{Eth1BlockHeight: 4, Index: 4},
|
|
{Eth1BlockHeight: 6, Index: 6},
|
|
{Eth1BlockHeight: 8, Index: 8},
|
|
{Eth1BlockHeight: 10, Index: 10},
|
|
{Eth1BlockHeight: 12, Index: 12},
|
|
}
|
|
|
|
dc.PrunePendingDeposits(context.Background(), 0)
|
|
expected := []*dbpb.DepositContainer{
|
|
{Eth1BlockHeight: 2, Index: 2},
|
|
{Eth1BlockHeight: 4, Index: 4},
|
|
{Eth1BlockHeight: 6, Index: 6},
|
|
{Eth1BlockHeight: 8, Index: 8},
|
|
{Eth1BlockHeight: 10, Index: 10},
|
|
{Eth1BlockHeight: 12, Index: 12},
|
|
}
|
|
assert.DeepEqual(t, expected, dc.pendingDeposits)
|
|
}
|
|
|
|
func TestPrunePendingDeposits_OK(t *testing.T) {
|
|
dc := DepositCache{}
|
|
|
|
dc.pendingDeposits = []*dbpb.DepositContainer{
|
|
{Eth1BlockHeight: 2, Index: 2},
|
|
{Eth1BlockHeight: 4, Index: 4},
|
|
{Eth1BlockHeight: 6, Index: 6},
|
|
{Eth1BlockHeight: 8, Index: 8},
|
|
{Eth1BlockHeight: 10, Index: 10},
|
|
{Eth1BlockHeight: 12, Index: 12},
|
|
}
|
|
|
|
dc.PrunePendingDeposits(context.Background(), 6)
|
|
expected := []*dbpb.DepositContainer{
|
|
{Eth1BlockHeight: 6, Index: 6},
|
|
{Eth1BlockHeight: 8, Index: 8},
|
|
{Eth1BlockHeight: 10, Index: 10},
|
|
{Eth1BlockHeight: 12, Index: 12},
|
|
}
|
|
|
|
assert.DeepEqual(t, expected, dc.pendingDeposits)
|
|
|
|
dc.pendingDeposits = []*dbpb.DepositContainer{
|
|
{Eth1BlockHeight: 2, Index: 2},
|
|
{Eth1BlockHeight: 4, Index: 4},
|
|
{Eth1BlockHeight: 6, Index: 6},
|
|
{Eth1BlockHeight: 8, Index: 8},
|
|
{Eth1BlockHeight: 10, Index: 10},
|
|
{Eth1BlockHeight: 12, Index: 12},
|
|
}
|
|
|
|
dc.PrunePendingDeposits(context.Background(), 10)
|
|
expected = []*dbpb.DepositContainer{
|
|
{Eth1BlockHeight: 10, Index: 10},
|
|
{Eth1BlockHeight: 12, Index: 12},
|
|
}
|
|
|
|
assert.DeepEqual(t, expected, dc.pendingDeposits)
|
|
}
|