-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc4ea40
commit 53aaf2b
Showing
3 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package payloadattestation | ||
|
||
import ( | ||
"testing" | ||
|
||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" | ||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" | ||
"github.com/prysmaticlabs/prysm/v5/testing/assert" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
) | ||
|
||
|
||
func TestValidatePayload(t *testing.T){ | ||
tests := []struct { | ||
name string | ||
bfunc func(t *testing.T) *ethpb.PayloadAttestationMessage | ||
wanterr error | ||
}{ | ||
{ | ||
name: "nil PayloadAttestationMessage", | ||
bfunc: func(t *testing.T) *ethpb.PayloadAttestationMessage { | ||
return nil | ||
}, | ||
wanterr: errNilPayloadMessage, | ||
}, | ||
{ | ||
name: "nil data", | ||
bfunc: func(t *testing.T) *ethpb.PayloadAttestationMessage { | ||
return ðpb.PayloadAttestationMessage{ | ||
Data: nil, | ||
} | ||
}, | ||
wanterr: errNilPayloadData, | ||
}, | ||
{ | ||
name: "nil signature", | ||
bfunc: func(t *testing.T) *ethpb.PayloadAttestationMessage { | ||
return ðpb.PayloadAttestationMessage{ | ||
Signature: nil, | ||
} | ||
}, | ||
wanterr: errMissingPayloadSignature, | ||
}, | ||
{ | ||
name: "Correct PayloadAttestationMessage", | ||
bfunc: func(t *testing.T) *ethpb.PayloadAttestationMessage { | ||
return ðpb.PayloadAttestationMessage{ | ||
Signature: make([]byte, fieldparams.BLSSignatureLength), | ||
Data: ðpb.PayloadAttestationData{ | ||
BeaconBlockRoot: make([]byte, fieldparams.RootLength), | ||
}, | ||
} | ||
}, | ||
wanterr: nil, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name+" ReadOnlyPayloadAtt", func(t *testing.T) { | ||
m := tt.bfunc(t) | ||
err := validatePayload(m) | ||
if tt.wanterr != nil { | ||
require.ErrorIs(t, err, tt.wanterr) | ||
}else { | ||
roMess,err:=NewReadOnly(m) | ||
require.NoError(t, err) | ||
assert.Equal(t,roMess.message.Data,m.Data) | ||
assert.Equal(t,roMess.message.Signature,m.Signature) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestValidatorIndex(t *testing.T){ | ||
valIdx := primitives.ValidatorIndex(1) | ||
m := &ReadOnlyPayloadAtt{ | ||
message: ðpb.PayloadAttestationMessage{ | ||
ValidatorIndex: valIdx, | ||
}, | ||
} | ||
assert.Equal(t,valIdx,m.ValidatorIndex()) | ||
} | ||
|
||
func TestSignature(t *testing.T){ | ||
sig := make([]byte,fieldparams.BLSSignatureLength) | ||
m := &ReadOnlyPayloadAtt{ | ||
message: ðpb.PayloadAttestationMessage{ | ||
Signature: sig[:], | ||
}, | ||
} | ||
assert.Equal(t,sig,m.Signature()) | ||
} | ||
|
||
func TestBeaconBlockRoot(t *testing.T){ | ||
root := make([]byte,fieldparams.RootLength) | ||
m := &ReadOnlyPayloadAtt{ | ||
message: ðpb.PayloadAttestationMessage{ | ||
Data: ðpb.PayloadAttestationData{ | ||
BeaconBlockRoot: root[:], | ||
}, | ||
}, | ||
} | ||
assert.Equal(t,root,m.BeaconBlockRoot()) | ||
} | ||
|
||
func TestSlot(t *testing.T){ | ||
slot := primitives.Slot(1) | ||
m := &ReadOnlyPayloadAtt{ | ||
message: ðpb.PayloadAttestationMessage{ | ||
Data: ðpb.PayloadAttestationData{ | ||
Slot: slot, | ||
}, | ||
}, | ||
} | ||
assert.Equal(t,slot,m.Slot()) | ||
} | ||
|
||
func TestPayloadStatus(t *testing.T){ | ||
for i:=0;i<4;i++ { | ||
status:=primitives.PTCStatus(i) | ||
m := &ReadOnlyPayloadAtt{ | ||
message: ðpb.PayloadAttestationMessage{ | ||
Data: ðpb.PayloadAttestationData{ | ||
PayloadStatus:status, | ||
}, | ||
}, | ||
} | ||
require.NoError(t,validatePayload(m.message)) | ||
assert.Equal(t,status,m.PayloadStatus()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package payloadattestation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/startup" | ||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" | ||
"github.com/prysmaticlabs/prysm/v5/testing/assert" | ||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
) | ||
|
||
func TestVerifyCurrentSlot(t *testing.T){ | ||
clock := &startup.Clock{} | ||
verifier := &PayloadVerifier{ | ||
Resources: Resources{ | ||
clock: clock, | ||
}, | ||
} | ||
assert.Equal(t, verifier.VerifyCurrentSlot(), ErrMismatchCurrentSlot) | ||
} | ||
|
||
func TestVerifyKnownPayloadStatus(t *testing.T){ | ||
ptcstatus := primitives.PTCStatus(4) | ||
verifier := &PayloadVerifier{ | ||
payloadAtt: ReadOnlyPayloadAtt{ | ||
message: ðpb.PayloadAttestationMessage{ | ||
Data: ðpb.PayloadAttestationData{ | ||
PayloadStatus:ptcstatus, | ||
}, | ||
}, | ||
}, | ||
} | ||
assert.Equal(t, verifier.VerifyKnownPayloadStatus(), ErrUnknownPayloadStatus) | ||
} |