Skip to content

Commit

Permalink
added Runtime Environment Updated digest (#3083)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego <diego2737@gmail.com>
  • Loading branch information
kishansagathiya and dimartiro committed Sep 19, 2023
1 parent 70e2d2b commit ff2eb11
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dot/types/block_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
)

var (
digestItem = scale.MustNewVaryingDataType(PreRuntimeDigest{}, ConsensusDigest{}, SealDigest{})
digestItem = scale.MustNewVaryingDataType(PreRuntimeDigest{}, ConsensusDigest{},
SealDigest{}, RuntimeEnvironmentUpdated{})
digest = scale.NewVaryingDataTypeSlice(digestItem)
testDigest = digest
)
Expand Down
13 changes: 12 additions & 1 deletion dot/types/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type DigestItem struct {

// NewDigestItem returns a new VaryingDataType to represent a DigestItem
func NewDigestItem() scale.VaryingDataType {
return scale.MustNewVaryingDataType(PreRuntimeDigest{}, ConsensusDigest{}, SealDigest{})
return scale.MustNewVaryingDataType(PreRuntimeDigest{}, ConsensusDigest{}, SealDigest{}, RuntimeEnvironmentUpdated{})
}

// NewDigest returns a new Digest as a varying data type slice.
Expand Down Expand Up @@ -84,3 +84,14 @@ func (SealDigest) Index() uint { return 5 }
func (d SealDigest) String() string {
return fmt.Sprintf("SealDigest ConsensusEngineID=%s Data=0x%x", d.ConsensusEngineID.ToBytes(), d.Data)
}

// RuntimeEnvironmentUpdated contains is an indicator for the light clients that the runtime environment is updated
type RuntimeEnvironmentUpdated struct{}

// Index returns VDT index
func (RuntimeEnvironmentUpdated) Index() uint { return 8 }

// String returns the digest as a string
func (RuntimeEnvironmentUpdated) String() string {
return "RuntimeEnvironmentUpdated"
}
28 changes: 27 additions & 1 deletion dot/types/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ func Test_Digest_String(t *testing.T) {
ConsensusEngineID: ConsensusEngineID{'x', 'y', 'w', 'z'},
Data: []byte{7, 8},
})
digest.Add(RuntimeEnvironmentUpdated{})
return digest
},
s: "[" +
"PreRuntimeDigest ConsensusEngineID=abcd Data=0x01020304, " +
"ConsensusDigest ConsensusEngineID=ffgg Data=0x0506, " +
"SealDigest ConsensusEngineID=xywz Data=0x0708" +
"SealDigest ConsensusEngineID=xywz Data=0x0708, " +
"RuntimeEnvironmentUpdated" +
"]",
},
}
Expand Down Expand Up @@ -191,6 +193,30 @@ func TestConsensusDigest(t *testing.T) {
require.Equal(t, diValue, vValue)
}

func TestRuntimeEnvironmentUpdatedDigest(t *testing.T) {
exp := common.MustHexToBytes("0x08")
d := RuntimeEnvironmentUpdated{}

di := NewDigestItem()
err := di.Set(d)
require.NoError(t, err)

enc, err := scale.Marshal(di)
require.NoError(t, err)

require.Equal(t, exp, enc)

v := NewDigestItem()
err = scale.Unmarshal(enc, &v)
require.NoError(t, err)

diValue, err := di.Value()
require.NoError(t, err)
vValue, err := v.Value()
require.NoError(t, err)
require.Equal(t, diValue, vValue)
}

func TestSealDigest(t *testing.T) {
exp := common.MustHexToBytes("0x05424142451001030507")
d := SealDigest{
Expand Down

0 comments on commit ff2eb11

Please sign in to comment.