-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement ext_offchain_index_set_version_1 for wasmer runtime #1739
Changes from 12 commits
c6d38ac
d88d707
99fe2c4
38c0813
cbdb7f2
53d11f5
9d5094b
caea8b0
6284063
9ddda6d
cdd0b08
8c4b89f
38c99ab
1cdf409
fcb1238
f9c9cdf
b1864dc
cc43aa9
defa63f
ee82422
b10fd88
a956531
0fc1adf
b70dc1c
8ae7638
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,21 @@ package core | |
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
"testing" | ||
|
||
coremocks "github.com/ChainSafe/gossamer/dot/core/mocks" | ||
"github.com/ChainSafe/gossamer/dot/network" | ||
"github.com/ChainSafe/gossamer/dot/state" | ||
"github.com/ChainSafe/gossamer/lib/common" | ||
"github.com/ChainSafe/gossamer/lib/crypto/sr25519" | ||
"github.com/ChainSafe/gossamer/lib/genesis" | ||
"github.com/ChainSafe/gossamer/lib/keystore" | ||
"github.com/ChainSafe/gossamer/lib/runtime" | ||
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage" | ||
"github.com/ChainSafe/gossamer/lib/runtime/wasmer" | ||
"github.com/ChainSafe/gossamer/lib/utils" | ||
log "github.com/ChainSafe/log15" | ||
|
||
coremocks "github.com/ChainSafe/gossamer/dot/core/mocks" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
@@ -105,6 +107,13 @@ func NewTestService(t *testing.T, cfg *Config) *Service { | |
rtCfg.CodeHash, err = cfg.StorageState.LoadCodeHash(nil) | ||
require.NoError(t, err) | ||
|
||
nodeStorage := runtime.NodeStorage{} | ||
|
||
nodeStorage.BaseDB, err = utils.SetupDatabase(filepath.Join(testDatadirPath, "offline_storage"), false) | ||
require.NoError(t, err) | ||
|
||
rtCfg.NodeStorage = nodeStorage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lgmt! just this pice of code that repeats in some places, would be nice to create a test function helper that receives a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created this:
however it seems that I could find a place to put this where it wouldn't cause a cycle import error in one of the files that used it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where did you place it? If you could not find a place to put there is no problem to keep the code as it is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried using it in core/test_helpers.go, then sync/test_helpers.go and babe/babe_test.go |
||
|
||
cfg.Runtime, err = wasmer.NewRuntimeFromGenesis(gen, rtCfg) | ||
require.NoError(t, err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,9 +120,15 @@ func createRuntime(cfg *Config, st *state.Service, ks *keystore.GlobalKeystore, | |
return nil, err | ||
} | ||
|
||
baseDB, err := utils.SetupDatabase(filepath.Join(st.DB().Path(), "offline_storage"), false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, replaced with st.Base. |
||
ns := runtime.NodeStorage{ | ||
LocalStorage: localStorage, | ||
PersistentStorage: chaindb.NewTable(st.DB(), "offlinestorage"), | ||
BaseDB: baseDB, | ||
} | ||
|
||
codeHash, err := st.Storage.LoadCodeHash(nil) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,12 @@ package sync | |
import ( | ||
"io/ioutil" | ||
"math/big" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/ChainSafe/gossamer/dot/state" | ||
syncmocks "github.com/ChainSafe/gossamer/dot/sync/mocks" | ||
"github.com/ChainSafe/gossamer/dot/types" | ||
"github.com/ChainSafe/gossamer/lib/babe" | ||
"github.com/ChainSafe/gossamer/lib/common" | ||
|
@@ -34,11 +34,11 @@ import ( | |
"github.com/ChainSafe/gossamer/lib/runtime/wasmer" | ||
"github.com/ChainSafe/gossamer/lib/transaction" | ||
"github.com/ChainSafe/gossamer/lib/trie" | ||
"github.com/ChainSafe/gossamer/lib/utils" | ||
"github.com/ChainSafe/gossamer/pkg/scale" | ||
log "github.com/ChainSafe/log15" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
|
||
syncmocks "github.com/ChainSafe/gossamer/dot/sync/mocks" | ||
) | ||
|
||
// NewMockFinalityGadget create and return sync FinalityGadget interface mock | ||
|
@@ -100,6 +100,11 @@ func NewTestSyncer(t *testing.T, usePolkadotGenesis bool) *Service { | |
rtCfg.CodeHash, err = cfg.StorageState.LoadCodeHash(nil) | ||
require.NoError(t, err) | ||
|
||
nodeStorage := runtime.NodeStorage{} | ||
nodeStorage.BaseDB, err = utils.SetupDatabase(filepath.Join(testDatadirPath, "offline_storage"), false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
require.NoError(t, err) | ||
rtCfg.NodeStorage = nodeStorage | ||
|
||
instance, err := wasmer.NewRuntimeFromGenesis(gen, rtCfg) //nolint | ||
require.NoError(t, err) | ||
cfg.Runtime = instance | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,24 +21,25 @@ import ( | |
"io/ioutil" | ||
"math/big" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ChainSafe/gossamer/dot/core" | ||
"github.com/ChainSafe/gossamer/dot/state" | ||
"github.com/ChainSafe/gossamer/dot/types" | ||
"github.com/ChainSafe/gossamer/lib/babe/mocks" | ||
"github.com/ChainSafe/gossamer/lib/common" | ||
"github.com/ChainSafe/gossamer/lib/crypto/sr25519" | ||
"github.com/ChainSafe/gossamer/lib/genesis" | ||
"github.com/ChainSafe/gossamer/lib/runtime" | ||
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage" | ||
"github.com/ChainSafe/gossamer/lib/runtime/wasmer" | ||
"github.com/ChainSafe/gossamer/lib/trie" | ||
"github.com/ChainSafe/gossamer/lib/utils" | ||
log "github.com/ChainSafe/log15" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ChainSafe/gossamer/lib/babe/mocks" | ||
mock "github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
|
@@ -98,8 +99,9 @@ func createTestService(t *testing.T, cfg *ServiceConfig) *Service { | |
cfg.TransactionState = state.NewTransactionState() | ||
} | ||
|
||
testDatadirPath, err := ioutil.TempDir("/tmp", "test-datadir-*") //nolint | ||
|
||
if cfg.BlockState == nil || cfg.StorageState == nil || cfg.EpochState == nil { | ||
testDatadirPath, err := ioutil.TempDir("/tmp", "test-datadir-*") //nolint | ||
require.NoError(t, err) | ||
|
||
config := state.Config{ | ||
|
@@ -138,6 +140,11 @@ func createTestService(t *testing.T, cfg *ServiceConfig) *Service { | |
rtCfg.CodeHash, err = storageState.LoadCodeHash(nil) | ||
require.NoError(t, err) | ||
|
||
nodeStorage := runtime.NodeStorage{} | ||
nodeStorage.BaseDB, err = utils.SetupDatabase(filepath.Join(testDatadirPath, "offline_storage"), false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update. |
||
require.NoError(t, err) | ||
rtCfg.NodeStorage = nodeStorage | ||
|
||
cfg.Runtime, err = wasmer.NewRuntimeFromGenesis(gen, rtCfg) | ||
require.NoError(t, err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,6 +409,27 @@ func Test_ext_storage_set_version_1(t *testing.T) { | |
require.Equal(t, testvalue, val) | ||
} | ||
|
||
func Test_ext_offline_index_set_version_1(t *testing.T) { | ||
// TODO this currently fails with error could nat find exported function, determine how else to test this | ||
t.Skip() | ||
inst := NewTestInstance(t, runtime.HOST_API_TEST_RUNTIME) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if change from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @EclesioMeloJunior the |
||
|
||
testkey := []byte("noot") | ||
testvalue := []byte("washere") | ||
|
||
encKey, err := scale.Encode(testkey) | ||
require.NoError(t, err) | ||
encValue, err := scale.Encode(testvalue) | ||
require.NoError(t, err) | ||
|
||
_, err = inst.Exec("rtm_ext_offline_index_set_version_1", append(encKey, encValue...)) | ||
require.NoError(t, err) | ||
|
||
val, err := inst.ctx.NodeStorage.PersistentStorage.Get(testkey) | ||
require.NoError(t, err) | ||
require.Equal(t, testvalue, val) | ||
} | ||
|
||
func Test_ext_crypto_ed25519_generate_version_1(t *testing.T) { | ||
inst := NewTestInstance(t, runtime.HOST_API_TEST_RUNTIME) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be preferred to use
stateSrvc.BaseDB
here ifstateSrvc != nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.