Skip to content

Commit

Permalink
Merge branch 'development' into eclesio/fix-TestStartGossamerAndPolka…
Browse files Browse the repository at this point in the history
…dotAPI
  • Loading branch information
EclesioMeloJunior authored Jan 23, 2023
2 parents 154f785 + 650371e commit 94b147e
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
68 changes: 68 additions & 0 deletions dot/network/block_announce_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2023 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package network

import (
"testing"

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/stretchr/testify/require"
)

func Test_BlockAnnounceMessage_String(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
messageBuilder func() BlockAnnounceMessage
s string
}{
"empty": {
messageBuilder: func() BlockAnnounceMessage {
return BlockAnnounceMessage{}
},
s: "BlockAnnounceMessage " +
"ParentHash=0x0000000000000000000000000000000000000000000000000000000000000000 " +
"Number=0 " +
"StateRoot=0x0000000000000000000000000000000000000000000000000000000000000000 " +
"ExtrinsicsRoot=0x0000000000000000000000000000000000000000000000000000000000000000 " +
"Digest=[]",
},
"filled": {
messageBuilder: func() BlockAnnounceMessage {
digest := types.NewDigest()
digest.Add(types.PreRuntimeDigest{
ConsensusEngineID: types.ConsensusEngineID{'a', 'b', 'c', 'd'},
Data: []byte{1, 2, 3, 4},
})
return BlockAnnounceMessage{
ParentHash: common.Hash{1},
Number: 2,
StateRoot: common.Hash{3},
ExtrinsicsRoot: common.Hash{4},
Digest: digest,
BestBlock: true,
}
},

s: "BlockAnnounceMessage " +
"ParentHash=0x0100000000000000000000000000000000000000000000000000000000000000 " +
"Number=2 " +
"StateRoot=0x0300000000000000000000000000000000000000000000000000000000000000 " +
"ExtrinsicsRoot=0x0400000000000000000000000000000000000000000000000000000000000000 " +
"Digest=[PreRuntimeDigest ConsensusEngineID=abcd Data=0x01020304]",
},
}

for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

message := testCase.messageBuilder()
s := message.String()
require.Equal(t, testCase.s, s)
})
}
}
2 changes: 1 addition & 1 deletion dot/types/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewDigestItem() scale.VaryingDataType {
return scale.MustNewVaryingDataType(ChangesTrieRootDigest{}, PreRuntimeDigest{}, ConsensusDigest{}, SealDigest{})
}

// NewDigest returns a new Digest from the given DigestItems
// NewDigest returns a new Digest as a varying data type slice.
func NewDigest() scale.VaryingDataTypeSlice {
return scale.NewVaryingDataTypeSlice(NewDigestItem())
}
Expand Down
54 changes: 54 additions & 0 deletions dot/types/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,60 @@ import (
"github.com/stretchr/testify/require"
)

func Test_Digest_String(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
digestBuilder func() scale.VaryingDataTypeSlice
s string
}{
"empty": {
digestBuilder: func() scale.VaryingDataTypeSlice {
return scale.VaryingDataTypeSlice{}
},
s: "[]",
},
"all digests": {
digestBuilder: func() scale.VaryingDataTypeSlice {
digest := NewDigest()
digest.Add(ChangesTrieRootDigest{
Hash: common.Hash{1},
})
digest.Add(PreRuntimeDigest{
ConsensusEngineID: ConsensusEngineID{'a', 'b', 'c', 'd'},
Data: []byte{1, 2, 3, 4},
})
digest.Add(ConsensusDigest{
ConsensusEngineID: ConsensusEngineID{'f', 'f', 'g', 'g'},
Data: []byte{5, 6},
})
digest.Add(SealDigest{
ConsensusEngineID: ConsensusEngineID{'x', 'y', 'w', 'z'},
Data: []byte{7, 8},
})
return digest
},
s: "[" +
"ChangesTrieRootDigest Hash=0x0100000000000000000000000000000000000000000000000000000000000000, " +
"PreRuntimeDigest ConsensusEngineID=abcd Data=0x01020304, " +
"ConsensusDigest ConsensusEngineID=ffgg Data=0x0506, " +
"SealDigest ConsensusEngineID=xywz Data=0x0708" +
"]",
},
}

for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

digest := testCase.digestBuilder()
s := digest.String()
require.Equal(t, testCase.s, s)
})
}
}

func TestEncode(t *testing.T) {
d := common.MustHexToBytes("0x0c0642414245340201000000ef55a50f00000000044241424549040118ca239392960473fe1bc65f94ee27d890a49c1b200c006ff5dcc525330ecc16770100000000000000b46f01874ce7abbb5220e8fd89bede0adad14c73039d91e28e881823433e723f0100000000000000d684d9176d6eb69887540c9a89fa6097adea82fc4b0ff26d1062b488f352e179010000000000000068195a71bdde49117a616424bdc60a1733e96acb1da5aeab5d268cf2a572e94101000000000000001a0575ef4ae24bdfd31f4cb5bd61239ae67c12d4e64ae51ac756044aa6ad8200010000000000000018168f2aad0081a25728961ee00627cfe35e39833c805016632bf7c14da5800901000000000000000000000000000000000000000000000000000000000000000000000000000000054241424501014625284883e564bc1e4063f5ea2b49846cdddaa3761d04f543b698c1c3ee935c40d25b869247c36c6b8a8cbbd7bb2768f560ab7c276df3c62df357a7e3b1ec8d") //nolint:lll
r := &bytes.Buffer{}
Expand Down

0 comments on commit 94b147e

Please sign in to comment.