Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pinebit committed Aug 20, 2024
1 parent 1f15157 commit df495fb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/parsigex/parsigex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/libp2p/go-libp2p/core/peerstore"
"github.com/stretchr/testify/require"

"github.com/obolnetwork/charon/app/featureset"
"github.com/obolnetwork/charon/core"
"github.com/obolnetwork/charon/core/parsigex"
"github.com/obolnetwork/charon/eth2util"
Expand Down Expand Up @@ -324,6 +325,13 @@ func TestParSigExVerifier(t *testing.T) {

require.NoError(t, verifyFunc(ctx, core.NewPrepareSyncContributionDuty(slot), pubkey, parSigData))
})

t.Run("with disable_parsig_checks", func(t *testing.T) {
featureset.EnableForT(t, featureset.DisableParSigChecks)

err := verifyFunc(ctx, core.NewProposerDuty(1), pubkey, core.ParSignedData{})
require.NoError(t, err)
})
}

func versionedSignedProposalRoot(t *testing.T, p *eth2api.VersionedSignedProposal) (eth2p0.Root, error) {
Expand Down
15 changes: 15 additions & 0 deletions core/sigagg/sigagg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"

"github.com/obolnetwork/charon/app/featureset"
"github.com/obolnetwork/charon/core"
"github.com/obolnetwork/charon/core/sigagg"
"github.com/obolnetwork/charon/eth2util/signing"
Expand All @@ -27,6 +28,20 @@ import (
"github.com/obolnetwork/charon/testutil/beaconmock"
)

func TestNewVerifier(t *testing.T) {
ctx := context.Background()
bmock, err := beaconmock.New()
require.NoError(t, err)

t.Run("with disable_parsig_checks", func(t *testing.T) {
featureset.EnableForT(t, featureset.DisableParSigChecks)

vf := sigagg.NewVerifier(bmock)
err := vf(ctx, "", nil)
require.NoError(t, err)
})
}

func TestSigAgg(t *testing.T) {
ctx := context.Background()

Expand Down
12 changes: 11 additions & 1 deletion core/validatorapi/validatorapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/eth2wrap"
"github.com/obolnetwork/charon/app/featureset"
"github.com/obolnetwork/charon/core"
"github.com/obolnetwork/charon/core/validatorapi"
"github.com/obolnetwork/charon/eth2util"
Expand Down Expand Up @@ -550,7 +551,7 @@ func TestComponent_SubmitProposalInvalidSignature(t *testing.T) {
vapi.Subscribe(func(ctx context.Context, duty core.Duty, set core.ParSignedDataSet) error {
block, ok := set[corePubKey].SignedData.(core.VersionedSignedProposal)
require.True(t, ok)
require.Equal(t, signedBlock, block)
require.Equal(t, *signedBlock, block.VersionedSignedProposal)

return nil
})
Expand All @@ -559,6 +560,15 @@ func TestComponent_SubmitProposalInvalidSignature(t *testing.T) {
Proposal: signedBlock,
})
require.ErrorContains(t, err, "signature not verified")

t.Run("with disable_parsig_checks", func(t *testing.T) {
featureset.EnableForT(t, featureset.DisableParSigChecks)

err = vapi.SubmitProposal(ctx, &eth2api.SubmitProposalOpts{
Proposal: signedBlock,
})
require.NoError(t, err)
})
}

func TestComponent_SubmitProposalInvalidBlock(t *testing.T) {
Expand Down

0 comments on commit df495fb

Please sign in to comment.