Skip to content

Commit

Permalink
cr feedback, fixed storageAppend
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Oct 7, 2021
1 parent 7d58e36 commit 484f81d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
1 change: 1 addition & 0 deletions dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func TestHandleChainReorg_WithReorg_Transactions(t *testing.T) {
// create extrinsic
enc, err := scale.Marshal([]byte("nootwashere"))
require.NoError(t, err)
// we prefix with []byte{2} here since that's the enum index for the old IncludeDataExt extrinsic
tx := append([]byte{2}, enc...)

bhash := s.blockState.BestBlockHash()
Expand Down
13 changes: 7 additions & 6 deletions lib/runtime/life/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ func (in *Instance) Version() (runtime.Version, error) {
version := &runtime.VersionData{}
err = version.Decode(res)
// error comes from scale now, so do a string check
if strings.Contains(fmt.Sprintf("%s", err), "EOF") {
// TODO: kusama seems to use the legacy version format
lversion := &runtime.LegacyVersionData{}
err = lversion.Decode(res)
return lversion, err
} else if err != nil {
if err != nil {
if strings.Contains(err.Error(), "EOF") {
// TODO: kusama seems to use the legacy version format
lversion := &runtime.LegacyVersionData{}
err = lversion.Decode(res)
return lversion, err
}
return nil, err
}

Expand Down
8 changes: 0 additions & 8 deletions lib/runtime/life/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ func TestInstance_ExecuteBlock_KusamaRuntime_KusamaBlock1(t *testing.T) {
// block data is received from querying a polkadot node
body := []byte{8, 40, 4, 2, 0, 11, 144, 17, 14, 179, 110, 1, 16, 4, 20, 0, 0}
var exts [][]byte
<<<<<<< HEAD
err = scale2.Unmarshal(body, &exts)
=======
err = scale.Unmarshal(body, &exts)
>>>>>>> d2357261 (lib/runtime/life updates)
require.NoError(t, err)
require.Equal(t, 2, len(exts))

Expand Down Expand Up @@ -291,11 +287,7 @@ func TestInstance_ExecuteBlock_PolkadotRuntime_PolkadotBlock1(t *testing.T) {
// block data is received from querying a polkadot node
body := []byte{8, 40, 4, 3, 0, 11, 80, 149, 160, 81, 114, 1, 16, 4, 20, 0, 0}
var exts [][]byte
<<<<<<< HEAD
err = scale2.Unmarshal(body, &exts)
=======
err = scale.Unmarshal(body, &exts)
>>>>>>> d2357261 (lib/runtime/life updates)
require.NoError(t, err)
require.Equal(t, 2, len(exts))

Expand Down
9 changes: 7 additions & 2 deletions lib/runtime/life/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,13 @@ func storageAppend(storage runtime.Storage, key, valueToAppend []byte) error {
return nil
}

// append new item, pop off first byte now, since we're not using old scale.Decoder
valueRes = append(valueCurr[1:], valueToAppend...)
lengthBytes, err := scale.Marshal(currLength)
if err != nil {
return err
}
// append new item, pop off number of bytes required for length encoding,
// since we're not using old scale.Decoder
valueRes = append(valueCurr[len(lengthBytes):], valueToAppend...)

// increase length by 1
nextLength = big.NewInt(0).Add(currLength, big.NewInt(1))
Expand Down
13 changes: 7 additions & 6 deletions lib/runtime/wasmer/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ func (in *Instance) Version() (runtime.Version, error) {
version := &runtime.VersionData{}
err = version.Decode(res)
// error comes from scale now, so do a string check
if strings.Contains(fmt.Sprintf("%s", err), "EOF") {
// TODO: kusama seems to use the legacy version format
lversion := &runtime.LegacyVersionData{}
err = lversion.Decode(res)
return lversion, err
} else if err != nil {
if err != nil {
if strings.Contains(err.Error(), "EOF") {
// TODO: kusama seems to use the legacy version format
lversion := &runtime.LegacyVersionData{}
err = lversion.Decode(res)
return lversion, err
}
return nil, err
}

Expand Down
9 changes: 7 additions & 2 deletions lib/runtime/wasmer/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,13 @@ func storageAppend(storage runtime.Storage, key, valueToAppend []byte) error {
return nil
}

// append new item, pop off first byte now, since we're not using old scale.Decoder
valueRes = append(valueCurr[1:], valueToAppend...)
lengthBytes, err := scale.Marshal(currLength)
if err != nil {
return err
}
// append new item, pop off number of bytes required for length encoding,
// since we're not using old scale.Decoder
valueRes = append(valueCurr[len(lengthBytes):], valueToAppend...)

// increase length by 1
nextLength = big.NewInt(0).Add(currLength, big.NewInt(1))
Expand Down

0 comments on commit 484f81d

Please sign in to comment.