From de84089ad5e7d4336776cc096f4c3c19028774ab Mon Sep 17 00:00:00 2001 From: "daniel.vladco" Date: Wed, 14 Aug 2024 18:30:17 +0300 Subject: [PATCH] fix: use common serializer with scale codec --- internal/block/header_test.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/internal/block/header_test.go b/internal/block/header_test.go index 3a79c66..59b0866 100644 --- a/internal/block/header_test.go +++ b/internal/block/header_test.go @@ -1,17 +1,19 @@ package block import ( + "crypto/ed25519" "crypto/rand" "testing" - "github.com/ChainSafe/gossamer/pkg/scale" - "github.com/eigerco/strawberry/internal/time" "github.com/stretchr/testify/assert" "github.com/eigerco/strawberry/internal/crypto" + "github.com/eigerco/strawberry/internal/jamtime" + "github.com/eigerco/strawberry/pkg/serialization" + "github.com/eigerco/strawberry/pkg/serialization/codec" ) -func Test_HeaderMarshalUnmarshal(t *testing.T) { +func Test_HeaderEncodeDecode(t *testing.T) { h := Header{ ParentHash: randomHash(), PriorStateRoot: randomHash(), @@ -24,28 +26,32 @@ func Test_HeaderMarshalUnmarshal(t *testing.T) { }, Entropy: randomHash(), }, - WinningTicketsMarker: [time.TimeslotsPerEpoch]*Ticket{{ + WinningTicketsMarker: [jamtime.TimeslotsPerEpoch]*Ticket{{ Identifier: randomHash(), EntryIndex: 111, }, { Identifier: randomHash(), EntryIndex: 222, }}, - JudgementsMarkers: []crypto.Hash{ + Verdicts: []crypto.Hash{ randomHash(), randomHash(), }, - PublicKeyIndex: 1, + OffendersMarkers: []crypto.Ed25519PublicKey{ + randomED25519PublicKey(), + }, + BlockAuthorIndex: 1, VRFSignature: randomSignature(), BlockSealSignature: randomSignature(), } - bb, err := scale.Marshal(h) + serializer := serialization.NewSerializer(&codec.SCALECodec{}) + bb, err := serializer.Encode(h) if err != nil { t.Fatal(err) } h2 := Header{} - err = scale.Unmarshal(bb, &h2) + err = serializer.Decode(bb, &h2) if err != nil { t.Fatal(err) } @@ -61,6 +67,14 @@ func randomHash() crypto.Hash { } return crypto.Hash(hash) } +func randomED25519PublicKey() crypto.Ed25519PublicKey { + hash := make([]byte, ed25519.PublicKeySize) + _, err := rand.Read(hash) + if err != nil { + panic(err) + } + return hash +} func randomPublicKey() crypto.BandersnatchPublicKey { hash := make([]byte, crypto.BandersnatchSize) _, err := rand.Read(hash)