Skip to content

Commit

Permalink
add tests for beacon-chain/state/state-native/getters_balance_deposit…
Browse files Browse the repository at this point in the history
…s.go
  • Loading branch information
prestonvanloon committed May 2, 2024
1 parent 477c9cb commit 3f4df33
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions beacon-chain/state/state-native/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ go_test(
name = "go_default_test",
srcs = [
"getters_attestation_test.go",
"getters_balance_deposits_test.go",
"getters_block_test.go",
"getters_checkpoint_test.go",
"getters_consolidation_test.go",
Expand Down
48 changes: 48 additions & 0 deletions beacon-chain/state/state-native/getters_balance_deposits_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package state_native_test

import (
"testing"

state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)

func TestDepositBalanceToConsume(t *testing.T) {
s, err := state_native.InitializeFromProtoElectra(&eth.BeaconStateElectra{
DepositBalanceToConsume: 44,
})
require.NoError(t, err)
dbtc, err := s.DepositBalanceToConsume()
require.NoError(t, err)
require.Equal(t, uint64(44), dbtc)

// Fails for older than electra state
s, err = state_native.InitializeFromProtoDeneb(&eth.BeaconStateDeneb{})
require.NoError(t, err)
_, err = s.DepositBalanceToConsume()
require.ErrorContains(t, "not supported", err)
}

func TestPendingBalanceDeposits(t *testing.T) {
s, err := state_native.InitializeFromProtoElectra(&eth.BeaconStateElectra{
PendingBalanceDeposits: []*eth.PendingBalanceDeposit{
{Index: 1, Amount: 2},
{Index: 3, Amount: 4},
},
})
require.NoError(t, err)
pbd, err := s.PendingBalanceDeposits()
require.NoError(t, err)
require.Equal(t, 2, len(pbd))
require.Equal(t, 1, pbd[0].Index)
require.Equal(t, 2, pbd[0].Amount)
require.Equal(t, 3, pbd[1].Index)
require.Equal(t, 4, pbd[1].Amount)

// Fails for older than electra state
s, err = state_native.InitializeFromProtoDeneb(&eth.BeaconStateDeneb{})
require.NoError(t, err)
_, err = s.DepositBalanceToConsume()
require.ErrorContains(t, "not supported", err)
}

0 comments on commit 3f4df33

Please sign in to comment.