From 7e42ed0323431345ea009d89d585d922944abbb6 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Tue, 17 Jan 2023 10:29:58 -0400 Subject: [PATCH 1/7] fix: use `westend-local` in all integration tests in `dot/rpc/modules` --- dot/core/helpers_test.go | 3 ++- dot/rpc/modules/author_integration_test.go | 17 ++++++++++------- dot/rpc/modules/chain_integration_test.go | 6 +++--- dot/rpc/modules/childstate_test.go | 2 +- dot/rpc/modules/dev_integration_test.go | 2 +- dot/rpc/modules/helpers_test.go | 4 ++-- lib/runtime/test_helpers.go | 4 ++-- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/dot/core/helpers_test.go b/dot/core/helpers_test.go index 6005d3a57d..e3f5a90aed 100644 --- a/dot/core/helpers_test.go +++ b/dot/core/helpers_test.go @@ -22,6 +22,7 @@ import ( "github.com/ChainSafe/gossamer/lib/trie" "github.com/ChainSafe/gossamer/lib/utils" "github.com/ChainSafe/gossamer/pkg/scale" + "github.com/centrifuge/go-substrate-rpc-client/v4/signature" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" ) @@ -116,7 +117,7 @@ func createTestService(t *testing.T, genesisFilePath string, // Hash of encrypted centrifuge extrinsic testCallArguments := []byte{0xab, 0xcd} extHex := runtime.NewTestExtrinsic(t, cfgRuntime, genesisHeader.Hash(), cfgBlockState.BestBlockHash(), - 0, "System.remark", testCallArguments) + 0, signature.TestKeyringPairAlice, "System.remark", testCallArguments) encodedExtrinsic = common.MustHexToBytes(extHex) cfgCodeSubstitutes := make(map[common.Hash]string) diff --git a/dot/rpc/modules/author_integration_test.go b/dot/rpc/modules/author_integration_test.go index 1f8798ea11..963c85b5b3 100644 --- a/dot/rpc/modules/author_integration_test.go +++ b/dot/rpc/modules/author_integration_test.go @@ -174,7 +174,8 @@ func TestAuthorModule_SubmitExtrinsic_Integration(t *testing.T) { // creating an extrisinc to the System.remark call using a sample argument extHex := runtime.NewTestExtrinsic(t, - integrationTestController.runtime, genesisHash, genesisHash, 0, "System.remark", []byte{0xab, 0xcd}) + integrationTestController.runtime, genesisHash, genesisHash, 0, + signature.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) extBytes := common.MustHexToBytes(extHex) @@ -212,7 +213,7 @@ func TestAuthorModule_SubmitExtrinsic_Integration(t *testing.T) { require.Equal(t, expectedHash, *res) } -func TestAuthorModule_SubmitExtrinsic_invalid(t *testing.T) { +func TestAuthorModule_SubmitExtrinsic_bad_proof(t *testing.T) { t.Parallel() integrationTestController := setupStateAndRuntime(t, t.TempDir(), useInstanceFromGenesis) @@ -220,7 +221,8 @@ func TestAuthorModule_SubmitExtrinsic_invalid(t *testing.T) { // creating an extrisinc to the System.remark call using a sample argument extHex := runtime.NewTestExtrinsic(t, - integrationTestController.runtime, genesisHash, genesisHash, 0, "System.remark", []byte{}) + integrationTestController.runtime, genesisHash, genesisHash, 0, + signature.TestInvalidKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) ctrl := gomock.NewController(t) net2test := NewMockNetwork(ctrl) @@ -233,7 +235,7 @@ func TestAuthorModule_SubmitExtrinsic_invalid(t *testing.T) { res := new(ExtrinsicHashResponse) err := auth.SubmitExtrinsic(nil, &Extrinsic{extHex}, res) - require.EqualError(t, err, "ancient birth block") + require.EqualError(t, err, "bad proof") txOnPool := integrationTestController.stateSrv.Transaction.PendingInPool() require.Len(t, txOnPool, 0) @@ -269,7 +271,8 @@ func TestAuthorModule_SubmitExtrinsic_AlreadyInPool(t *testing.T) { // creating an extrisinc to the System.remark call using a sample argument extHex := runtime.NewTestExtrinsic(t, - integrationTestController.runtime, genesisHash, genesisHash, 0, "System.remark", []byte{}) + integrationTestController.runtime, genesisHash, genesisHash, 0, + signature.TestKeyringPairAlice, "System.remark", []byte{}) extBytes := common.MustHexToBytes(extHex) integrationTestController.network = NewMockNetwork(nil) @@ -630,7 +633,7 @@ type integrationTestController struct { func setupStateAndRuntime(t *testing.T, basepath string, useInstance useRuntimeInstance) *integrationTestController { t.Helper() - gen, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) + gen, genesisTrie, genesisHeader := newWestendLocalGenesisWithTrieAndHeader(t) ctrl := gomock.NewController(t) telemetryMock := NewMockTelemetry(ctrl) @@ -690,7 +693,7 @@ func setupStateAndPopulateTrieState(t *testing.T, basepath string, useInstance useRuntimeInstance) *integrationTestController { t.Helper() - gen, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) + gen, genesisTrie, genesisHeader := newWestendLocalGenesisWithTrieAndHeader(t) ctrl := gomock.NewController(t) telemetryMock := NewMockTelemetry(ctrl) diff --git a/dot/rpc/modules/chain_integration_test.go b/dot/rpc/modules/chain_integration_test.go index e3ba6f2031..cf162fa120 100644 --- a/dot/rpc/modules/chain_integration_test.go +++ b/dot/rpc/modules/chain_integration_test.go @@ -288,7 +288,7 @@ func TestChainGetBlockHash_Array(t *testing.T) { func TestChainGetFinalizedHead(t *testing.T) { state := newTestStateService(t) svc := NewChainModule(state.Block) - _, _, genesisHeader := newTestGenesisWithTrieAndHeader(t) + _, _, genesisHeader := newWestendLocalGenesisWithTrieAndHeader(t) var res ChainHashResponse err := svc.GetFinalizedHead(nil, &EmptyRequest{}, &res) require.NoError(t, err) @@ -306,7 +306,7 @@ func TestChainGetFinalizedHeadByRound(t *testing.T) { err := svc.GetFinalizedHeadByRound(nil, &req, &res) require.NoError(t, err) - _, _, genesisHeader := newTestGenesisWithTrieAndHeader(t) + _, _, genesisHeader := newWestendLocalGenesisWithTrieAndHeader(t) expected := genesisHeader.Hash() require.Equal(t, common.BytesToHex(expected[:]), res) @@ -351,7 +351,7 @@ func newTestStateService(t *testing.T) *state.Service { stateSrvc := state.NewService(config) stateSrvc.UseMemDB() - gen, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) + gen, genesisTrie, genesisHeader := newWestendLocalGenesisWithTrieAndHeader(t) err := stateSrvc.Initialise(&gen, &genesisHeader, &genesisTrie) require.NoError(t, err) diff --git a/dot/rpc/modules/childstate_test.go b/dot/rpc/modules/childstate_test.go index 8bcb7aba45..f3aecad492 100644 --- a/dot/rpc/modules/childstate_test.go +++ b/dot/rpc/modules/childstate_test.go @@ -21,7 +21,7 @@ import ( func createTestTrieState(t *testing.T) (*trie.Trie, common.Hash) { t.Helper() - _, genesisTrie, _ := newTestGenesisWithTrieAndHeader(t) + _, genesisTrie, _ := newWestendLocalGenesisWithTrieAndHeader(t) tr := rtstorage.NewTrieState(&genesisTrie) tr.Put([]byte(":first_key"), []byte(":value1")) diff --git a/dot/rpc/modules/dev_integration_test.go b/dot/rpc/modules/dev_integration_test.go index eeebd1ef63..42083e1a07 100644 --- a/dot/rpc/modules/dev_integration_test.go +++ b/dot/rpc/modules/dev_integration_test.go @@ -39,7 +39,7 @@ func newState(t *testing.T) (*state.BlockState, *state.EpochState) { db := state.NewInMemoryDB(t) - _, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) + _, genesisTrie, genesisHeader := newWestendLocalGenesisWithTrieAndHeader(t) tries := state.NewTries() tries.SetTrie(&genesisTrie) bs, err := state.NewBlockStateFromGenesis(db, tries, &genesisHeader, telemetryMock) diff --git a/dot/rpc/modules/helpers_test.go b/dot/rpc/modules/helpers_test.go index 61bc9260a6..41e9708253 100644 --- a/dot/rpc/modules/helpers_test.go +++ b/dot/rpc/modules/helpers_test.go @@ -22,11 +22,11 @@ func makeChange(keyHex, valueHex string) [2]*string { return [2]*string{&keyHex, &valueHex} } -func newTestGenesisWithTrieAndHeader(t *testing.T) ( +func newWestendLocalGenesisWithTrieAndHeader(t *testing.T) ( gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { t.Helper() - genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) + genesisPath := utils.GetWestendLocalRawGenesisPath(t) genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) gen = *genesisPtr diff --git a/lib/runtime/test_helpers.go b/lib/runtime/test_helpers.go index 7a98fd4022..0d0900d307 100644 --- a/lib/runtime/test_helpers.go +++ b/lib/runtime/test_helpers.go @@ -222,7 +222,7 @@ type MetadataVersioner interface { // NewTestExtrinsic builds a new extrinsic using centrifuge pkg func NewTestExtrinsic(t *testing.T, rt MetadataVersioner, genHash, blockHash common.Hash, - nonce uint64, call string, args ...interface{}) string { + nonce uint64, keypair signature.KeyringPair, call string, args ...interface{}) string { t.Helper() rawMeta, err := rt.Metadata() @@ -254,7 +254,7 @@ func NewTestExtrinsic(t *testing.T, rt MetadataVersioner, genHash, blockHash com } // Sign the transaction using Alice's key - err = ext.Sign(signature.TestKeyringPairAlice, o) + err = ext.Sign(keypair, o) require.NoError(t, err) extEnc, err := codec.EncodeToHex(ext) From 4a6e7c4045e8113cccb3ad937b906de8438b65fd Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Tue, 17 Jan 2023 12:40:53 -0400 Subject: [PATCH 2/7] chore: fix imports --- dot/rpc/modules/author_integration_test.go | 11 ++++++++++- lib/babe/babe_integration_test.go | 4 +++- lib/babe/build_integration_test.go | 6 ++++-- lib/runtime/wasmer/exports_test.go | 5 +++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/dot/rpc/modules/author_integration_test.go b/dot/rpc/modules/author_integration_test.go index 963c85b5b3..643b031868 100644 --- a/dot/rpc/modules/author_integration_test.go +++ b/dot/rpc/modules/author_integration_test.go @@ -215,6 +215,15 @@ func TestAuthorModule_SubmitExtrinsic_Integration(t *testing.T) { func TestAuthorModule_SubmitExtrinsic_bad_proof(t *testing.T) { t.Parallel() + testInvalidKeyringPairAlice := signature.KeyringPair{ + URI: "//Alice", + PublicKey: []byte{0xd4, 0x35, 0x93, 0xc7, 0x15, 0xfd, 0xd3, + 0x1c, 0x61, 0x14, 0x1a, 0xbd, 0x4, 0xa9, 0x9f, 0xd6, 0x82, + 0x2c, 0x85, 0x58, 0x85, 0x4c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, + 0xe7, 0xa5, 0x6d, 0xa2, 0x7d}, + Address: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + } + integrationTestController := setupStateAndRuntime(t, t.TempDir(), useInstanceFromGenesis) genesisHash := integrationTestController.genesisHeader.Hash() @@ -222,7 +231,7 @@ func TestAuthorModule_SubmitExtrinsic_bad_proof(t *testing.T) { // creating an extrisinc to the System.remark call using a sample argument extHex := runtime.NewTestExtrinsic(t, integrationTestController.runtime, genesisHash, genesisHash, 0, - signature.TestInvalidKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) + testInvalidKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) ctrl := gomock.NewController(t) net2test := NewMockNetwork(ctrl) diff --git a/lib/babe/babe_integration_test.go b/lib/babe/babe_integration_test.go index 8ebd8e381e..9e8d0fd589 100644 --- a/lib/babe/babe_integration_test.go +++ b/lib/babe/babe_integration_test.go @@ -21,6 +21,7 @@ import ( "github.com/ChainSafe/gossamer/lib/runtime/wasmer" "github.com/ChainSafe/gossamer/lib/trie" "github.com/ChainSafe/gossamer/pkg/scale" + signaturev4 "github.com/centrifuge/go-substrate-rpc-client/v4/signature" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" @@ -313,7 +314,8 @@ func TestService_HandleSlotWithLaggingSlot(t *testing.T) { epochData, err := babeService.initiateEpoch(testEpochIndex) require.NoError(t, err) - ext := runtime.NewTestExtrinsic(t, rt, parentHash, parentHash, 0, "System.remark", []byte{0xab, 0xcd}) + ext := runtime.NewTestExtrinsic(t, rt, parentHash, parentHash, 0, + signaturev4.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) block := createTestBlock(t, babeService, emptyHeader, [][]byte{common.MustHexToBytes(ext)}, 1, testEpochIndex, epochData) diff --git a/lib/babe/build_integration_test.go b/lib/babe/build_integration_test.go index 77a56c76ae..060a669b4f 100644 --- a/lib/babe/build_integration_test.go +++ b/lib/babe/build_integration_test.go @@ -98,7 +98,8 @@ func TestBuildBlock_ok(t *testing.T) { epochData, err := babeService.initiateEpoch(testEpochIndex) require.NoError(t, err) - ext := runtime.NewTestExtrinsic(t, rt, parentHash, parentHash, 0, "System.remark", []byte{0xab, 0xcd}) + ext := runtime.NewTestExtrinsic(t, rt, parentHash, parentHash, 0, + signaturev4.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) block := createTestBlock(t, babeService, emptyHeader, [][]byte{common.MustHexToBytes(ext)}, 1, testEpochIndex, epochData) @@ -183,7 +184,8 @@ func TestApplyExtrinsic(t *testing.T) { header1, err := rt.FinalizeBlock() require.NoError(t, err) - extHex := runtime.NewTestExtrinsic(t, rt, parentHash, parentHash, 0, "System.remark", []byte{0xab, 0xcd}) + extHex := runtime.NewTestExtrinsic(t, rt, parentHash, parentHash, 0, + signaturev4.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) extBytes := common.MustHexToBytes(extHex) _, err = rt.ValidateTransaction(append([]byte{byte(types.TxnExternal)}, extBytes...)) require.NoError(t, err) diff --git a/lib/runtime/wasmer/exports_test.go b/lib/runtime/wasmer/exports_test.go index 189f35f868..c0f0dddc5a 100644 --- a/lib/runtime/wasmer/exports_test.go +++ b/lib/runtime/wasmer/exports_test.go @@ -21,6 +21,7 @@ import ( "github.com/ChainSafe/gossamer/lib/trie" "github.com/ChainSafe/gossamer/lib/utils" "github.com/ChainSafe/gossamer/pkg/scale" + "github.com/centrifuge/go-substrate-rpc-client/v4/signature" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -342,7 +343,7 @@ func TestNodeRuntime_ValidateTransaction(t *testing.T) { } extHex := runtime.NewTestExtrinsic(t, rt, genesisHeader.Hash(), genesisHeader.Hash(), - 0, "System.remark", []byte{0xab, 0xcd}) + 0, signature.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) extBytes := common.MustHexToBytes(extHex) extBytes = append([]byte{byte(types.TxnExternal)}, extBytes...) @@ -582,7 +583,7 @@ func TestInstance_ApplyExtrinsic_GossamerRuntime(t *testing.T) { require.NoError(t, err) extHex := runtime.NewTestExtrinsic(t, instance, parentHash, parentHash, - 0, "System.remark", []byte{0xab, 0xcd}) + 0, signature.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) extBytes := common.MustHexToBytes(extHex) enc, err := scale.Marshal(extBytes) From e45551fe64ddef9e842552aa3a1d09bd2d19a960 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Tue, 17 Jan 2023 15:05:04 -0400 Subject: [PATCH 3/7] chore: add a real invalid alice key --- dot/rpc/modules/author_integration_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dot/rpc/modules/author_integration_test.go b/dot/rpc/modules/author_integration_test.go index 643b031868..bd20b3405b 100644 --- a/dot/rpc/modules/author_integration_test.go +++ b/dot/rpc/modules/author_integration_test.go @@ -217,10 +217,10 @@ func TestAuthorModule_SubmitExtrinsic_bad_proof(t *testing.T) { t.Parallel() testInvalidKeyringPairAlice := signature.KeyringPair{ URI: "//Alice", - PublicKey: []byte{0xd4, 0x35, 0x93, 0xc7, 0x15, 0xfd, 0xd3, - 0x1c, 0x61, 0x14, 0x1a, 0xbd, 0x4, 0xa9, 0x9f, 0xd6, 0x82, - 0x2c, 0x85, 0x58, 0x85, 0x4c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, - 0xe7, 0xa5, 0x6d, 0xa2, 0x7d}, + PublicKey: []byte{0xd5, 0x36, 0x13, 0xc7, 0x15, 0xfd, 0xd3, + 0x1c, 0x61, 0x14, 0x1a, 0xb4, 0x4, 0xa9, 0x9f, 0xd6, 0x82, + 0x2c, 0x85, 0x58, 0x85, 0x2c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, + 0xe7, 0xa5, 0x6d, 0x12, 0x7d}, Address: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", } From 9cae1624efdd12705675b72e65e448d452917f22 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Tue, 17 Jan 2023 15:59:49 -0400 Subject: [PATCH 4/7] chore: blocked by #3047 --- dot/rpc/modules/author_integration_test.go | 2 +- lib/runtime/test_helpers.go | 30 ++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/dot/rpc/modules/author_integration_test.go b/dot/rpc/modules/author_integration_test.go index bd20b3405b..1ecd31312c 100644 --- a/dot/rpc/modules/author_integration_test.go +++ b/dot/rpc/modules/author_integration_test.go @@ -756,7 +756,7 @@ func setupStateAndPopulateTrieState(t *testing.T, basepath string, genesisHash := genesisHeader.Hash() state2test.Block.StoreRuntime(genesisHash, rt) - b := runtime.InitializeRuntimeToTest(t, rt, genesisHash) + b := runtime.InitializeRuntimeToTest(t, rt, &genesisHeader) err = state2test.Block.AddBlock(b) require.NoError(t, err) diff --git a/lib/runtime/test_helpers.go b/lib/runtime/test_helpers.go index 0d0900d307..90fabb3a42 100644 --- a/lib/runtime/test_helpers.go +++ b/lib/runtime/test_helpers.go @@ -304,11 +304,11 @@ type Metadataer interface { } // InitializeRuntimeToTest sets a new block using the runtime functions to set initial data into the host -func InitializeRuntimeToTest(t *testing.T, instance Instance, parentHash common.Hash) *types.Block { +func InitializeRuntimeToTest(t *testing.T, instance Instance, parentHeader *types.Header) *types.Block { t.Helper() header := &types.Header{ - ParentHash: parentHash, + ParentHash: parentHeader.Hash(), Number: 1, Digest: types.NewDigest(), } @@ -316,18 +316,28 @@ func InitializeRuntimeToTest(t *testing.T, instance Instance, parentHash common. err := instance.InitializeBlock(header) require.NoError(t, err) - idata := types.NewInherentData() - err = idata.SetInherent(types.Timstap0, uint64(1)) + inherentData := types.NewInherentData() + err = inherentData.SetInherent(types.Timstap0, uint64(1)) require.NoError(t, err) - err = idata.SetInherent(types.Babeslot, uint64(1)) + err = inherentData.SetInherent(types.Babeslot, uint64(1)) require.NoError(t, err) - ienc, err := idata.Encode() + parachainInherent := struct{ ParentHeader types.Header }{ + ParentHeader: *parentHeader, + } + + err = inherentData.SetInherent(types.Parachn0, parachainInherent) + require.NoError(t, err) + + err = inherentData.SetInherent(types.Newheads, []byte{0}) + require.NoError(t, err) + + ecodedInherent, err := inherentData.Encode() require.NoError(t, err) // Call BlockBuilder_inherent_extrinsics which returns the inherents as extrinsics - inherentExts, err := instance.InherentExtrinsics(ienc) + inherentExts, err := instance.InherentExtrinsics(ecodedInherent) require.NoError(t, err) // decode inherent extrinsics @@ -337,11 +347,11 @@ func InitializeRuntimeToTest(t *testing.T, instance Instance, parentHash common. // apply each inherent extrinsic for _, ext := range exts { - in, err := scale.Marshal(ext) + encodedInherent, err := scale.Marshal(ext) require.NoError(t, err) - ret, err := instance.ApplyExtrinsic(append([]byte{1}, in...)) - require.NoError(t, err, in) + ret, err := instance.ApplyExtrinsic(encodedInherent) + require.NoError(t, err, encodedInherent) require.Equal(t, ret, []byte{0, 0}) } From 747a9fb629b57f4e04ab37b99e748d97c7ecc1f8 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Tue, 17 Jan 2023 16:14:03 -0400 Subject: [PATCH 5/7] chore: fix types arguments --- lib/runtime/wasmer/exports_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/runtime/wasmer/exports_test.go b/lib/runtime/wasmer/exports_test.go index c0f0dddc5a..d2ec969715 100644 --- a/lib/runtime/wasmer/exports_test.go +++ b/lib/runtime/wasmer/exports_test.go @@ -348,7 +348,7 @@ func TestNodeRuntime_ValidateTransaction(t *testing.T) { extBytes := common.MustHexToBytes(extHex) extBytes = append([]byte{byte(types.TxnExternal)}, extBytes...) - runtime.InitializeRuntimeToTest(t, rt, genesisHeader.Hash()) + runtime.InitializeRuntimeToTest(t, rt, genesisHeader) _, err = rt.ValidateTransaction(extBytes) require.NoError(t, err) } @@ -511,12 +511,12 @@ func TestInstance_InitializeBlock_PolkadotRuntime(t *testing.T) { func TestInstance_FinalizeBlock_NodeRuntime(t *testing.T) { instance := NewTestInstance(t, runtime.NODE_RUNTIME) - runtime.InitializeRuntimeToTest(t, instance, common.Hash{}) + runtime.InitializeRuntimeToTest(t, instance, &types.Header{}) } func TestInstance_ExecuteBlock_NodeRuntime(t *testing.T) { instance := NewTestInstance(t, runtime.NODE_RUNTIME) - block := runtime.InitializeRuntimeToTest(t, instance, common.Hash{}) + block := runtime.InitializeRuntimeToTest(t, instance, &types.Header{}) // reset state back to parent state before executing parentState := storage.NewTrieState(nil) @@ -545,7 +545,7 @@ func TestInstance_ExecuteBlock_GossamerRuntime(t *testing.T) { instance, err := NewRuntimeFromGenesis(cfg) require.NoError(t, err) - block := runtime.InitializeRuntimeToTest(t, instance, common.Hash{}) + block := runtime.InitializeRuntimeToTest(t, instance, &types.Header{}) // reset state back to parent state before executing parentState := storage.NewTrieState(&genTrie) @@ -599,7 +599,7 @@ func TestInstance_ExecuteBlock_PolkadotRuntime(t *testing.T) { instance := NewTestInstance(t, runtime.POLKADOT_RUNTIME) - block := runtime.InitializeRuntimeToTest(t, instance, common.Hash{}) + block := runtime.InitializeRuntimeToTest(t, instance, &types.Header{}) // reset state back to parent state before executing parentState := storage.NewTrieState(nil) From 464fb5ef758f1ee1b5aa144cb78c69d06b36b0a0 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Wed, 18 Jan 2023 18:30:50 -0400 Subject: [PATCH 6/7] chore: resolve assertion at `TestAuthorModule_SubmitExtrinsic_Integration` --- dot/rpc/modules/author_integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dot/rpc/modules/author_integration_test.go b/dot/rpc/modules/author_integration_test.go index 1ecd31312c..9567dc520a 100644 --- a/dot/rpc/modules/author_integration_test.go +++ b/dot/rpc/modules/author_integration_test.go @@ -194,12 +194,12 @@ func TestAuthorModule_SubmitExtrinsic_Integration(t *testing.T) { expected := &transaction.ValidTransaction{ Extrinsic: expectedExtrinsic, Validity: &transaction.Validity{ - Priority: 39325240425794630, + Priority: 36074, Requires: nil, Provides: [][]byte{ common.MustHexToBytes("0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d00000000"), }, - Longevity: 18446744073709551614, + Longevity: 18446744073709551613, Propagate: true, }, } From dd8d12ae537825dc191316b552ddb08f9f278137 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Fri, 20 Jan 2023 14:11:59 -0400 Subject: [PATCH 7/7] chore: fix `author_decode_session_keys` rpc calls and add more key types --- dot/core/service.go | 4 ++-- dot/rpc/modules/author.go | 5 ++--- dot/rpc/modules/author_integration_test.go | 20 +++++++++++++------- lib/babe/babe_integration_test.go | 4 ++-- lib/babe/build_integration_test.go | 8 ++++---- lib/keystore/helpers.go | 13 ++----------- lib/keystore/keystore.go | 10 ++++++++++ lib/runtime/test_helpers.go | 4 ++-- 8 files changed, 37 insertions(+), 31 deletions(-) diff --git a/dot/core/service.go b/dot/core/service.go index 4e198995ff..660ee482b0 100644 --- a/dot/core/service.go +++ b/dot/core/service.go @@ -472,14 +472,14 @@ func (s *Service) HasKey(pubKeyStr, keystoreType string) (bool, error) { } // DecodeSessionKeys executes the runtime DecodeSessionKeys and return the scale encoded keys -func (s *Service) DecodeSessionKeys(enc []byte) ([]byte, error) { +func (s *Service) DecodeSessionKeys(encodedSessionKeys []byte) ([]byte, error) { bestBlockHash := s.blockState.BestBlockHash() rt, err := s.blockState.GetRuntime(bestBlockHash) if err != nil { return nil, err } - return rt.DecodeSessionKeys(enc) + return rt.DecodeSessionKeys(encodedSessionKeys) } // GetRuntimeVersion gets the current RuntimeVersion diff --git a/dot/rpc/modules/author.go b/dot/rpc/modules/author.go index 5655e9ae45..63adbafc75 100644 --- a/dot/rpc/modules/author.go +++ b/dot/rpc/modules/author.go @@ -108,12 +108,12 @@ func (am *AuthorModule) HasSessionKeys(r *http.Request, req *HasSessionKeyReques return err } - pkeys, err := scale.Marshal(pubKeysBytes) + encodedKeys, err := scale.Marshal(pubKeysBytes) if err != nil { return err } - data, err := am.coreAPI.DecodeSessionKeys(pkeys) + data, err := am.coreAPI.DecodeSessionKeys(encodedKeys) if err != nil { *res = false return err @@ -133,7 +133,6 @@ func (am *AuthorModule) HasSessionKeys(r *http.Request, req *HasSessionKeyReques for _, key := range *decodedKeys { encType := keystore.Name(key.Type[:]) ok, err := am.coreAPI.HasKey(common.BytesToHex(key.Data), string(encType)) - if err != nil || !ok { *res = false return err diff --git a/dot/rpc/modules/author_integration_test.go b/dot/rpc/modules/author_integration_test.go index 9567dc520a..a5e9ab5163 100644 --- a/dot/rpc/modules/author_integration_test.go +++ b/dot/rpc/modules/author_integration_test.go @@ -468,8 +468,8 @@ func TestAuthorModule_HasKey_Integration(t *testing.T) { func TestAuthorModule_HasSessionKeys_Integration(t *testing.T) { t.Parallel() - const granSeed = "0xf25586ceb64a043d887631fa08c2ed790ef7ae3c7f28de5172005f8b9469e529" - const granPubK = "0x6b802349d948444d41397da09ec597fbd8ae8fdd3dfa153b2bb2bddcf020457c" + const granSeed = "0xabf8e5bdbe30c65656c0a3cbd181ff8a56294a69dfedd27982aace4a76909115" + const granPubK = "0x88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee" const sr25519Seed = "0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a" const sr25519Pubk = "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" @@ -484,7 +484,7 @@ func TestAuthorModule_HasSessionKeys_Integration(t *testing.T) { pubk: granPubK, }, { - ktype: []string{"babe", "imon", "audi"}, + ktype: []string{"babe", "imon", "para", "asgn", "audi"}, seed: sr25519Seed, pubk: sr25519Pubk, }, @@ -496,9 +496,11 @@ func TestAuthorModule_HasSessionKeys_Integration(t *testing.T) { waitErr error }{ "public keys are in the right order, should return true": { - pubSessionKeys: "0x6b802349d948444d41397da09ec597fbd8ae8fdd3dfa153b2bb2bddcf020457c" + // gran + pubSessionKeys: "0x88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee" + // gran "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // babe "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // imon + "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // para + "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // asgn "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d", // audi expect: true, }, @@ -506,14 +508,18 @@ func TestAuthorModule_HasSessionKeys_Integration(t *testing.T) { pubSessionKeys: "0x740550da19ef14023ea3e903545a6700160a55be2e4b733b577c91b053e38b8d" + // gran "de6fa0da51c52cc117d77aeb329595b15070db444e7ed4c4adec714b291c1845" + // babe "de6fa0da51c52cc117d77aeb329595b15070db444e7ed4c4adec714b291c1845" + // imon + "de6fa0da51c52cc117d77aeb329595b15070db444e7ed4c4adec714b291c1845" + // para + "de6fa0da51c52cc117d77aeb329595b15070db444e7ed4c4adec714b291c1845" + // asgn "de6fa0da51c52cc117d77aeb329595b15070db444e7ed4c4adec714b291c1845", // audi expect: false, }, "public keys are not in the right order, should return false": { - pubSessionKeys: "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // gran - "6b802349d948444d41397da09ec597fbd8ae8fdd3dfa153b2bb2bddcf020457c" + // babe + pubSessionKeys: "0x6b802349d948444d41397da09ec597fbd8ae8fdd3dfa153b2bb2bddcf020457c" + // babe + "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // gran "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // imon - "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d", // audi + "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // audi + "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // para + "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d", // asgn expect: false, }, "incomplete keys": { diff --git a/lib/babe/babe_integration_test.go b/lib/babe/babe_integration_test.go index 9e8d0fd589..ca7d80977f 100644 --- a/lib/babe/babe_integration_test.go +++ b/lib/babe/babe_integration_test.go @@ -21,7 +21,7 @@ import ( "github.com/ChainSafe/gossamer/lib/runtime/wasmer" "github.com/ChainSafe/gossamer/lib/trie" "github.com/ChainSafe/gossamer/pkg/scale" - signaturev4 "github.com/centrifuge/go-substrate-rpc-client/v4/signature" + "github.com/centrifuge/go-substrate-rpc-client/v4/signature" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" @@ -315,7 +315,7 @@ func TestService_HandleSlotWithLaggingSlot(t *testing.T) { require.NoError(t, err) ext := runtime.NewTestExtrinsic(t, rt, parentHash, parentHash, 0, - signaturev4.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) + signature.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) block := createTestBlock(t, babeService, emptyHeader, [][]byte{common.MustHexToBytes(ext)}, 1, testEpochIndex, epochData) diff --git a/lib/babe/build_integration_test.go b/lib/babe/build_integration_test.go index 060a669b4f..0af4aebcf3 100644 --- a/lib/babe/build_integration_test.go +++ b/lib/babe/build_integration_test.go @@ -19,7 +19,7 @@ import ( "github.com/ChainSafe/gossamer/pkg/scale" cscale "github.com/centrifuge/go-substrate-rpc-client/v4/scale" - signaturev4 "github.com/centrifuge/go-substrate-rpc-client/v4/signature" + "github.com/centrifuge/go-substrate-rpc-client/v4/signature" ctypes "github.com/centrifuge/go-substrate-rpc-client/v4/types" "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec" "github.com/ethereum/go-ethereum/metrics" @@ -99,7 +99,7 @@ func TestBuildBlock_ok(t *testing.T) { require.NoError(t, err) ext := runtime.NewTestExtrinsic(t, rt, parentHash, parentHash, 0, - signaturev4.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) + signature.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) block := createTestBlock(t, babeService, emptyHeader, [][]byte{common.MustHexToBytes(ext)}, 1, testEpochIndex, epochData) @@ -185,7 +185,7 @@ func TestApplyExtrinsic(t *testing.T) { require.NoError(t, err) extHex := runtime.NewTestExtrinsic(t, rt, parentHash, parentHash, 0, - signaturev4.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) + signature.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd}) extBytes := common.MustHexToBytes(extHex) _, err = rt.ValidateTransaction(append([]byte{byte(types.TxnExternal)}, extBytes...)) require.NoError(t, err) @@ -260,7 +260,7 @@ func TestBuildAndApplyExtrinsic(t *testing.T) { } // Sign the transaction using Alice's default account - err = ext.Sign(signaturev4.TestKeyringPairAlice, o) + err = ext.Sign(signature.TestKeyringPairAlice, o) require.NoError(t, err) extEnc := bytes.Buffer{} diff --git a/lib/keystore/helpers.go b/lib/keystore/helpers.go index a2f1dc7909..ad6e76b5d9 100644 --- a/lib/keystore/helpers.go +++ b/lib/keystore/helpers.go @@ -299,19 +299,10 @@ func UnlockKeys(ks Inserter, dir, unlock, password string) error { // and returns the crypto.KeyType func DetermineKeyType(t string) crypto.KeyType { switch t { - case "babe": - return crypto.Sr25519Type case "gran": return crypto.Ed25519Type - case "acco": - return crypto.Sr25519Type - case "aura": - return crypto.Sr25519Type - case "imon": - return crypto.Sr25519Type - case "audi": - return crypto.Sr25519Type - case "dumy": + case "acco", "babe", "para", "asgn", + "aura", "imon", "audi", "dumy": return crypto.Sr25519Type } return crypto.UnknownType diff --git a/lib/keystore/keystore.go b/lib/keystore/keystore.go index d9c70a904b..f436dbfd43 100644 --- a/lib/keystore/keystore.go +++ b/lib/keystore/keystore.go @@ -24,6 +24,8 @@ var ( AccoName Name = "acco" AuraName Name = "aura" ImonName Name = "imon" + ParaName Name = "para" + AsgnName Name = "asgn" AudiName Name = "audi" DumyName Name = "dumy" ) @@ -62,6 +64,8 @@ type GlobalKeystore struct { Gran Keystore Acco Keystore Aura Keystore + Para Keystore + Asgn Keystore Imon Keystore Audi Keystore Dumy Keystore @@ -74,6 +78,8 @@ func NewGlobalKeystore() *GlobalKeystore { Gran: NewBasicKeystore(GranName, crypto.Ed25519Type), Acco: NewGenericKeystore(AccoName), // TODO: which type is used? can an account be either type? (#1872) Aura: NewBasicKeystore(AuraName, crypto.Sr25519Type), + Para: NewBasicKeystore(ParaName, crypto.Sr25519Type), + Asgn: NewBasicKeystore(AsgnName, crypto.Sr25519Type), Imon: NewBasicKeystore(ImonName, crypto.Sr25519Type), Audi: NewBasicKeystore(AudiName, crypto.Sr25519Type), Dumy: NewGenericKeystore(DumyName), @@ -94,6 +100,10 @@ func (k *GlobalKeystore) GetKeystore(name []byte) (Keystore, error) { return k.Aura, nil case ImonName: return k.Imon, nil + case ParaName: + return k.Para, nil + case AsgnName: + return k.Asgn, nil case AudiName: return k.Audi, nil case DumyName: diff --git a/lib/runtime/test_helpers.go b/lib/runtime/test_helpers.go index e84ef8faa3..c3b81d9b8d 100644 --- a/lib/runtime/test_helpers.go +++ b/lib/runtime/test_helpers.go @@ -222,7 +222,7 @@ type MetadataVersioner interface { // NewTestExtrinsic builds a new extrinsic using centrifuge pkg func NewTestExtrinsic(t *testing.T, rt MetadataVersioner, genHash, blockHash common.Hash, - nonce uint64, keypair signature.KeyringPair, call string, args ...interface{}) string { + nonce uint64, keyRingPair signature.KeyringPair, call string, args ...interface{}) string { t.Helper() rawMeta, err := rt.Metadata() @@ -254,7 +254,7 @@ func NewTestExtrinsic(t *testing.T, rt MetadataVersioner, genHash, blockHash com } // Sign the transaction using Alice's key - err = ext.Sign(keypair, o) + err = ext.Sign(keyRingPair, o) require.NoError(t, err) extEnc, err := codec.EncodeToHex(ext)