-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
24 changed files
with
1,087 additions
and
17 deletions.
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,62 @@ | ||
package parachain | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/ChainSafe/gossamer/lib/common" | ||
sc "github.com/LimeChain/goscale" | ||
primitives "github.com/LimeChain/gosemble/primitives/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
expectedBytesAncestor, _ = hex.DecodeString("0500000006000000040a0000000500000006000000013aa96b0149b6ca3688878bdbd19464448624136398e3ce45b9e755d3ab61355c0105") | ||
) | ||
|
||
var ( | ||
paraHeadHash = common.MustHexToHash("0x3aa96b0149b6ca3688878bdbd19464448624136398e3ce45b9e755d3ab61355c").ToBytes() | ||
targetAncestor = Ancestor{ | ||
UsedBandwidth: UsedBandwidth{ | ||
UmpMsgCount: 5, | ||
UmpTotalBytes: 6, | ||
HrmpOutgoing: sc.Dictionary[sc.U32, HrmpChannelUpdate]{ | ||
10: { | ||
MsgCount: 5, | ||
TotalBytes: 6, | ||
}, | ||
}, | ||
}, | ||
ParaHeadHash: sc.Option[primitives.H256]{ | ||
HasValue: true, | ||
Value: primitives.H256{FixedSequence: sc.BytesToFixedSequenceU8(paraHeadHash)}, | ||
}, | ||
ConsumedGoAheadSignal: sc.Option[sc.U8]{ | ||
HasValue: true, | ||
Value: 5, | ||
}, | ||
} | ||
) | ||
|
||
func Test_Ancestor_Encode(t *testing.T) { | ||
buffer := &bytes.Buffer{} | ||
|
||
err := targetAncestor.Encode(buffer) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expectedBytesAncestor, buffer.Bytes()) | ||
} | ||
|
||
func Test_Ancestor_Decode(t *testing.T) { | ||
buf := bytes.NewBuffer(expectedBytesAncestor) | ||
|
||
result, err := DecodeAncestor(buf) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, targetAncestor, result) | ||
} | ||
|
||
func Test_Ancestor_Bytes(t *testing.T) { | ||
assert.Equal(t, expectedBytesAncestor, targetAncestor.Bytes()) | ||
} |
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,40 @@ | ||
package parachain | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
expectedBytesAsyncBackingParams, _ = hex.DecodeString("0400000005000000") | ||
) | ||
|
||
var ( | ||
targetAsyncBackingParams = AsyncBackingParams{ | ||
MaxCandidateDepth: 4, | ||
AllowedAncestryLen: 5, | ||
} | ||
) | ||
|
||
func Test_AsyncBackingParams_Encode(t *testing.T) { | ||
buffer := &bytes.Buffer{} | ||
|
||
err := targetAsyncBackingParams.Encode(buffer) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedBytesAsyncBackingParams, buffer.Bytes()) | ||
} | ||
|
||
func Test_AsyncBackingParams_Decode(t *testing.T) { | ||
buf := bytes.NewBuffer(expectedBytesAsyncBackingParams) | ||
|
||
result, err := DecodeAsyncBackingParams(buf) | ||
assert.NoError(t, err) | ||
assert.Equal(t, targetAsyncBackingParams, result) | ||
} | ||
|
||
func Test_AsyncBackingParams_Bytes(t *testing.T) { | ||
assert.Equal(t, expectedBytesAsyncBackingParams, targetAsyncBackingParams.Bytes()) | ||
} |
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,51 @@ | ||
package parachain | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
sc "github.com/LimeChain/goscale" | ||
primitives "github.com/LimeChain/gosemble/primitives/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
expectedBytesChannel, _ = hex.DecodeString("03000000010000000200000003000000040000000500000000") | ||
) | ||
|
||
var ( | ||
targetChannel = Channel{ | ||
ParachainId: 3, | ||
AbridgedHRMPChannel: AbridgedHRMPChannel{ | ||
MaxCapacity: 1, | ||
MaxTotalSize: 2, | ||
MaxMessageSize: 3, | ||
MsgCount: 4, | ||
TotalSize: 5, | ||
MqcHead: sc.Option[primitives.H256]{ | ||
HasValue: false, | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
func Test_Channel_Encode(t *testing.T) { | ||
buffer := &bytes.Buffer{} | ||
|
||
err := targetChannel.Encode(buffer) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedBytesChannel, buffer.Bytes()) | ||
} | ||
|
||
func Test_Channel_Decode(t *testing.T) { | ||
buf := bytes.NewBuffer(expectedBytesChannel) | ||
|
||
result, err := DecodeChannel(buf) | ||
assert.NoError(t, err) | ||
assert.Equal(t, targetChannel, result) | ||
} | ||
|
||
func Test_Channel_Bytes(t *testing.T) { | ||
assert.Equal(t, expectedBytesChannel, targetChannel.Bytes()) | ||
} |
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,55 @@ | ||
package parachain | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
sc "github.com/LimeChain/goscale" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
expectedBytesCollationInfo, _ = hex.DecodeString("040c01020304030000000c030405010c060708010000000200000008090a") | ||
) | ||
|
||
var ( | ||
targetCollationInfo = CollationInfo{ | ||
UpwardMessages: sc.Sequence[UpwardMessage]{ | ||
sc.Sequence[sc.U8]{1, 2, 3}, | ||
}, | ||
HorizontalMessages: sc.Sequence[OutboundHrmpMessage]{ | ||
{ | ||
Id: 3, | ||
Data: sc.Sequence[sc.U8]{3, 4, 5}, | ||
}, | ||
}, | ||
ValidationCode: sc.Option[sc.Sequence[sc.U8]]{ | ||
HasValue: true, | ||
Value: sc.Sequence[sc.U8]{6, 7, 8}, | ||
}, | ||
ProcessedDownwardMessages: 1, | ||
HrmpWatermark: 2, | ||
HeadData: sc.Sequence[sc.U8]{9, 10}, | ||
} | ||
) | ||
|
||
func Test_CollationInfo_Encode(t *testing.T) { | ||
buffer := &bytes.Buffer{} | ||
|
||
err := targetCollationInfo.Encode(buffer) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedBytesCollationInfo, buffer.Bytes()) | ||
} | ||
|
||
func Test_CollationInfo_Decode(t *testing.T) { | ||
buf := bytes.NewBuffer(expectedBytesCollationInfo) | ||
|
||
result, err := DecodeCollationInfo(buf) | ||
assert.NoError(t, err) | ||
assert.Equal(t, targetCollationInfo, result) | ||
} | ||
|
||
func Test_CollationInfo_Bytes(t *testing.T) { | ||
assert.Equal(t, expectedBytesCollationInfo, targetCollationInfo.Bytes()) | ||
} |
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,23 @@ | ||
package parachain | ||
|
||
import ( | ||
"testing" | ||
|
||
sc "github.com/LimeChain/goscale" | ||
"github.com/LimeChain/gosemble/constants" | ||
primitives "github.com/LimeChain/gosemble/primitives/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_NewDigestRelayParentStorageRoot(t *testing.T) { | ||
storageRoot := primitives.H256{FixedSequence: constants.ZeroAccountId.FixedSequence} | ||
number := sc.NewU32(5) | ||
|
||
expect := primitives.NewDigestItemConsensusMessage( | ||
sc.BytesToFixedSequenceU8(ConsensusTypeId[:]), | ||
sc.BytesToSequenceU8(sc.NewVaryingData(storageRoot, number).Bytes()), | ||
) | ||
|
||
result := NewDigestRelayParentStorageRoot(storageRoot, number) | ||
assert.Equal(t, expect, result) | ||
} |
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,65 @@ | ||
package parachain | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
sc "github.com/LimeChain/goscale" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
expectedBytesHorizontalMessages, _ = hex.DecodeString("040500000004040000000c010203") | ||
) | ||
|
||
var ( | ||
targetHorizontalMessages = HorizontalMessages{ | ||
messages: sc.Dictionary[sc.U32, sc.Sequence[InboundDownwardMessage]]{ | ||
5: sc.Sequence[InboundDownwardMessage]{ | ||
{ | ||
SentAt: 4, | ||
Msg: sc.Sequence[sc.U8]{1, 2, 3}, | ||
}, | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
func Test_HorizontalMessages_Encode(t *testing.T) { | ||
buffer := &bytes.Buffer{} | ||
|
||
err := targetHorizontalMessages.Encode(buffer) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedBytesHorizontalMessages, buffer.Bytes()) | ||
} | ||
|
||
func Test_HorizontalMessages_Decode(t *testing.T) { | ||
buf := bytes.NewBuffer(expectedBytesHorizontalMessages) | ||
|
||
result, err := DecodeHorizontalMessages(buf) | ||
assert.NoError(t, err) | ||
assert.Equal(t, targetHorizontalMessages, result) | ||
} | ||
|
||
func Test_HorizontalMessages_Bytes(t *testing.T) { | ||
assert.Equal(t, expectedBytesHorizontalMessages, targetHorizontalMessages.Bytes()) | ||
} | ||
|
||
func Test_HorizontalMessages_UnprocessedMessages(t *testing.T) { | ||
expect := targetHorizontalMessages | ||
|
||
result := targetHorizontalMessages.UnprocessedMessages(1) | ||
|
||
assert.Equal(t, expect, result) | ||
} | ||
|
||
func Test_HorizontalMessages_UnprocessedMessages_Empty(t *testing.T) { | ||
expect := HorizontalMessages{sc.Dictionary[sc.U32, sc.Sequence[InboundDownwardMessage]]{ | ||
5: sc.Sequence[InboundDownwardMessage]{}, | ||
}} | ||
|
||
result := targetHorizontalMessages.UnprocessedMessages(10) | ||
|
||
assert.Equal(t, expect, result) | ||
} |
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,64 @@ | ||
package parachain | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
expectedHrmpChannelUpdate, _ = hex.DecodeString("0500000006000000") | ||
) | ||
|
||
var ( | ||
targetHrmpChannelUpdate = HrmpChannelUpdate{ | ||
MsgCount: 5, | ||
TotalBytes: 6, | ||
} | ||
) | ||
|
||
func Test_HrmpChannelUpdate_Encode(t *testing.T) { | ||
buffer := &bytes.Buffer{} | ||
|
||
err := targetHrmpChannelUpdate.Encode(buffer) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedHrmpChannelUpdate, buffer.Bytes()) | ||
} | ||
|
||
func Test_HrmpChannelUpdate_Decode(t *testing.T) { | ||
buf := bytes.NewBuffer(expectedHrmpChannelUpdate) | ||
|
||
result, err := DecodeHrmpChannelUpdate(buf) | ||
assert.NoError(t, err) | ||
assert.Equal(t, targetHrmpChannelUpdate, result) | ||
} | ||
|
||
func Test_HrmpChannelUpdate_Bytes(t *testing.T) { | ||
assert.Equal(t, expectedHrmpChannelUpdate, targetHrmpChannelUpdate.Bytes()) | ||
} | ||
|
||
func Test_HrmpChannelUpdate_IsEmpty(t *testing.T) { | ||
assert.False(t, targetHrmpChannelUpdate.IsEmpty()) | ||
} | ||
|
||
func Test_HrmpChannelUpdate_Subtract(t *testing.T) { | ||
target := HrmpChannelUpdate{ | ||
MsgCount: 2, | ||
TotalBytes: 3, | ||
} | ||
other := HrmpChannelUpdate{ | ||
MsgCount: 1, | ||
TotalBytes: 2, | ||
} | ||
expect := HrmpChannelUpdate{ | ||
MsgCount: 1, | ||
TotalBytes: 1, | ||
} | ||
|
||
target.Subtract(other) | ||
|
||
assert.Equal(t, expect, target) | ||
|
||
} |
Oops, something went wrong.