Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dot/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 21 additions & 9 deletions dot/rpc/modules/author_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -193,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,
},
}
Expand All @@ -212,15 +213,25 @@ 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()
testInvalidKeyringPairAlice := signature.KeyringPair{
URI: "//Alice",
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",
}

integrationTestController := setupStateAndRuntime(t, t.TempDir(), useInstanceFromGenesis)

genesisHash := integrationTestController.genesisHeader.Hash()

// 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,
testInvalidKeyringPairAlice, "System.remark", []byte{0xab, 0xcd})

ctrl := gomock.NewController(t)
net2test := NewMockNetwork(ctrl)
Expand All @@ -233,7 +244,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)
Expand Down Expand Up @@ -269,7 +280,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)
Expand Down Expand Up @@ -630,7 +642,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)
Expand Down Expand Up @@ -690,7 +702,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)
Expand Down
6 changes: 3 additions & 3 deletions dot/rpc/modules/chain_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/childstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/dev_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions dot/rpc/modules/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/babe/babe_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment thread
EclesioMeloJunior marked this conversation as resolved.
Outdated
"github.com/golang/mock/gomock"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions lib/babe/build_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Comment thread
EclesioMeloJunior marked this conversation as resolved.
Outdated
t.Helper()

rawMeta, err := rt.Metadata()
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -343,7 +344,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})

genesisHashBytes := genesisHeader.Hash().ToBytes()

Expand Down Expand Up @@ -561,7 +562,7 @@ func TestInstance_ApplyExtrinsic_WestendRuntime(t *testing.T) {
require.NoError(t, err)

extHex := runtime.NewTestExtrinsic(t, instance, genesisHeader.Hash(), genesisHeader.Hash(),
0, "System.remark", []byte{0xab, 0xcd})
0, signature.TestKeyringPairAlice, "System.remark", []byte{0xab, 0xcd})

res, err := instance.ApplyExtrinsic(common.MustHexToBytes(extHex))
require.NoError(t, err)
Expand Down