mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 20:20:05 +00:00
b7175b3482
* Revert "Revert "Update fastssz" (#7100)"
This reverts commit b954db9704
.
* Preston's patch
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Update fssz, add regression test case
* more HTR with fssz
* fix some tests
* only one test left
* Make it so that HTR will work
* gofmt, imports
* gofmt, imports
* fix
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* fix
* Merge branch 'master' into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* gaz
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* fix test
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
88 lines
3.2 KiB
Go
88 lines
3.2 KiB
Go
package slashingprotection
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
mockSlasher "github.com/prysmaticlabs/prysm/validator/testing"
|
|
)
|
|
|
|
func TestService_VerifyAttestation(t *testing.T) {
|
|
s := &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: true}}
|
|
att := ð.IndexedAttestation{
|
|
AttestingIndices: []uint64{1, 2},
|
|
Data: ð.AttestationData{
|
|
Slot: 5,
|
|
CommitteeIndex: 2,
|
|
BeaconBlockRoot: []byte("great block"),
|
|
Source: ð.Checkpoint{
|
|
Epoch: 4,
|
|
Root: []byte("good source"),
|
|
},
|
|
Target: ð.Checkpoint{
|
|
Epoch: 10,
|
|
Root: []byte("good target"),
|
|
},
|
|
},
|
|
}
|
|
assert.Equal(t, false, s.CheckAttestationSafety(context.Background(), att), "Expected verify attestation to fail verification")
|
|
s = &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: false}}
|
|
assert.Equal(t, true, s.CheckAttestationSafety(context.Background(), att), "Expected verify attestation to pass verification")
|
|
}
|
|
|
|
func TestService_CommitAttestation(t *testing.T) {
|
|
s := &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: true}}
|
|
att := ð.IndexedAttestation{
|
|
AttestingIndices: []uint64{1, 2},
|
|
Data: ð.AttestationData{
|
|
Slot: 5,
|
|
CommitteeIndex: 2,
|
|
BeaconBlockRoot: []byte("great block"),
|
|
Source: ð.Checkpoint{
|
|
Epoch: 4,
|
|
Root: []byte("good source"),
|
|
},
|
|
Target: ð.Checkpoint{
|
|
Epoch: 10,
|
|
Root: []byte("good target"),
|
|
},
|
|
},
|
|
}
|
|
assert.Equal(t, false, s.CommitAttestation(context.Background(), att), "Expected commit attestation to fail verification")
|
|
s = &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: false}}
|
|
assert.Equal(t, true, s.CommitAttestation(context.Background(), att), "Expected commit attestation to pass verification")
|
|
}
|
|
|
|
func TestService_CommitBlock(t *testing.T) {
|
|
s := &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: true}}
|
|
blk := ð.SignedBeaconBlockHeader{
|
|
Header: ð.BeaconBlockHeader{
|
|
Slot: 0,
|
|
ProposerIndex: 0,
|
|
ParentRoot: bytesutil.PadTo([]byte("parent"), 32),
|
|
StateRoot: bytesutil.PadTo([]byte("state"), 32),
|
|
BodyRoot: bytesutil.PadTo([]byte("body"), 32),
|
|
},
|
|
}
|
|
assert.Equal(t, false, s.CommitBlock(context.Background(), blk), "Expected commit block to fail verification")
|
|
s = &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: false}}
|
|
assert.Equal(t, true, s.CommitBlock(context.Background(), blk), "Expected commit block to pass verification")
|
|
}
|
|
|
|
func TestService_VerifyBlock(t *testing.T) {
|
|
s := &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: true}}
|
|
blk := ð.BeaconBlockHeader{
|
|
Slot: 0,
|
|
ProposerIndex: 0,
|
|
ParentRoot: bytesutil.PadTo([]byte("parent"), 32),
|
|
StateRoot: bytesutil.PadTo([]byte("state"), 32),
|
|
BodyRoot: bytesutil.PadTo([]byte("body"), 32),
|
|
}
|
|
assert.Equal(t, false, s.CheckBlockSafety(context.Background(), blk), "Expected verify block to fail verification")
|
|
s = &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: false}}
|
|
assert.Equal(t, true, s.CheckBlockSafety(context.Background(), blk), "Expected verify block to pass verification")
|
|
}
|