Skip to content

Commit 6486321

Browse files
committed
Remove version Encode method
- Update comment for `scale.Marshal` on `Version` - Remove `Test_Version_Encode`
1 parent 39afb65 commit 6486321

File tree

3 files changed

+9
-64
lines changed

3 files changed

+9
-64
lines changed

lib/runtime/version.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ type Version struct {
2828
TransactionVersion uint32
2929
}
3030

31-
// Encode returns the scale encoding of the version.
32-
// Note the encoding contains all the latest Core_version fields as defined in
33-
// https://spec.polkadot.network/#defn-rt-core-version
34-
// In other words, decoding older version data with missing fields
35-
// and then encoding it will result in a longer encoding due to the
36-
// extra version fields. This however remains compatible since the
37-
// version fields are still encoded in the same order and an older
38-
// decoder would succeed with the longer encoding.
39-
func (v *Version) Encode() (encoded []byte, err error) {
40-
return scale.Marshal(*v)
41-
}
42-
4331
var (
4432
ErrDecodingVersionField = errors.New("decoding version field")
4533
)

lib/runtime/version_test.go

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,6 @@ func concatBytes(slices [][]byte) (concatenated []byte) {
2424
return concatenated
2525
}
2626

27-
func Test_Version_Encode(t *testing.T) {
28-
t.Parallel()
29-
30-
testCases := map[string]struct {
31-
version Version
32-
encoding []byte
33-
errWrapped error
34-
errMessage string
35-
}{
36-
"all optional fields set": {
37-
version: Version{
38-
SpecName: []byte{1},
39-
ImplName: []byte{2},
40-
AuthoringVersion: 3,
41-
SpecVersion: 4,
42-
ImplVersion: 5,
43-
APIItems: []APIItem{{
44-
Name: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
45-
Ver: 6,
46-
}},
47-
TransactionVersion: 7,
48-
},
49-
encoding: []byte{
50-
0x4, 0x1, 0x4, 0x2, 0x3, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0,
51-
0x5, 0x0, 0x0, 0x0, 0x4, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
52-
0x8, 0x6, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0},
53-
},
54-
}
55-
56-
for name, testCase := range testCases {
57-
testCase := testCase
58-
t.Run(name, func(t *testing.T) {
59-
t.Parallel()
60-
61-
encoded, err := testCase.version.Encode()
62-
63-
assert.ErrorIs(t, err, testCase.errWrapped)
64-
if testCase.errWrapped != nil {
65-
require.EqualError(t, err, testCase.errMessage)
66-
}
67-
assert.Equal(t, testCase.encoding, encoded)
68-
})
69-
}
70-
}
71-
7227
func Test_DecodeVersion(t *testing.T) {
7328
t.Parallel()
7429

@@ -200,7 +155,7 @@ func Test_Version_Scale(t *testing.T) {
200155
t.Run(name, func(t *testing.T) {
201156
t.Parallel()
202157

203-
encoded, err := testCase.version.Encode()
158+
encoded, err := scale.Marshal(testCase.version)
204159

205160
require.NoError(t, err)
206161
require.Equal(t, testCase.encoding, encoded)

lib/runtime/wasmer/imports.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -951,12 +951,14 @@ func ext_misc_runtime_version_version_1(context unsafe.Pointer, dataSpan C.int64
951951
return C.int64_t(out)
952952
}
953953

954-
// Note: we must call the `Encode` method and NOT
955-
// scale.Marshal or this one would encode the Version
956-
// interface pointer instead of the actual struct implementation.
957-
// Encode also respects the legacy boolean field of the version
958-
// and encodes the version differently if it is set to true.
959-
encodedData, err := version.Encode()
954+
// Note the encoding contains all the latest Core_version fields as defined in
955+
// https://spec.polkadot.network/#defn-rt-core-version
956+
// In other words, decoding older version data with missing fields
957+
// and then encoding it will result in a longer encoding due to the
958+
// extra version fields. This however remains compatible since the
959+
// version fields are still encoded in the same order and an older
960+
// decoder would succeed with the longer encoding.
961+
encodedData, err := scale.Marshal(version)
960962
if err != nil {
961963
logger.Errorf("failed to encode result: %s", err)
962964
return 0

0 commit comments

Comments
 (0)