Skip to content
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

testing(dot/core): rewrite dot/core service tests (part 2) #2308

Merged
merged 75 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
635a950
add wasm file generation to core service tests
jimjbrettj Jan 25, 2022
cad1117
WIP/codeSubstituteTest
jimjbrettj Jan 25, 2022
f1b4543
code substitution test
jimjbrettj Jan 25, 2022
b556f79
test handle block
jimjbrettj Jan 25, 2022
5709451
handle BlockProduced test
jimjbrettj Jan 26, 2022
996e4ce
clean up and test maintainTxnPool
jimjbrettj Jan 26, 2022
88ac199
test handleBlockAsync
jimjbrettj Jan 26, 2022
b82d0a5
part1 of service tests
jimjbrettj Jan 26, 2022
43d7ba2
clean up
jimjbrettj Jan 26, 2022
ccbba02
fix test naming
jimjbrettj Feb 10, 2022
86c9152
wip/cr feedback
jimjbrettj Feb 10, 2022
772147b
define storage root tests in subtests
jimjbrettj Feb 10, 2022
b478bf5
parallel storage root tests
jimjbrettj Feb 10, 2022
ba87d17
remove gomack.Any() for getRuntime calls
jimjbrettj Feb 10, 2022
1469c1f
restructure handleCodeSub unit tests
jimjbrettj Feb 10, 2022
1419f73
restructure handle block tests
jimjbrettj Feb 10, 2022
8f0e431
restructure tests and make subtests parallel
jimjbrettj Feb 10, 2022
c25e8dd
reduce integration test diff
jimjbrettj Feb 10, 2022
910984a
CR feedback TODO rewrite code sub
jimjbrettj Feb 16, 2022
b376056
remove wasm files from core service tests
jimjbrettj Feb 16, 2022
a84a7ae
reduce code duplication in tests
jimjbrettj Feb 17, 2022
028ab93
CR feedback
jimjbrettj Feb 17, 2022
c2191bd
wip/reorg test
jimjbrettj Jan 31, 2022
88758d0
maybe finished chainreorg test
jimjbrettj Jan 31, 2022
505f55a
temp comment out reorg test to work on others. TODO/fix extrinsic sig
jimjbrettj Jan 31, 2022
f1386cc
test insert and has key
jimjbrettj Jan 31, 2022
03f287d
test decode session keys
jimjbrettj Jan 31, 2022
7ed1e87
fix core reorg logic and remove wrapper for centrifuge extrinsics
jimjbrettj Feb 1, 2022
902d7ab
test getRuntimeVersion
jimjbrettj Feb 1, 2022
ff2cab4
wip/fix core integration tests
jimjbrettj Feb 1, 2022
77cb3fe
wip/fix core integration tests
jimjbrettj Feb 1, 2022
ef67b6e
wip/fix core integration tests
jimjbrettj Feb 2, 2022
23fb2a6
test hadnle submitted extrinsic
jimjbrettj Feb 2, 2022
72bf8f0
test get metadata
jimjbrettj Feb 3, 2022
c8581d8
test try query storage
jimjbrettj Feb 3, 2022
de52abd
test query storage
jimjbrettj Feb 3, 2022
a6599cf
finish dot core unit tests
jimjbrettj Feb 3, 2022
968fd1b
wip
jimjbrettj Feb 8, 2022
b9fa310
wip temp
jimjbrettj Feb 8, 2022
63b824b
wip/fix unit tests post rebase
jimjbrettj Feb 10, 2022
4ee6cf7
fix first broken core integration test
jimjbrettj Feb 15, 2022
63e67cf
clean up code before fix other tests
jimjbrettj Feb 15, 2022
28cba7c
wip/fix tests
jimjbrettj Feb 15, 2022
7cc72b9
fix core unit tests TODO fix final integration test
jimjbrettj Feb 15, 2022
b61dd70
fix core service integration and unit tests
jimjbrettj Feb 15, 2022
289709b
wip/restructure tests
jimjbrettj Feb 16, 2022
666e407
rebase
jimjbrettj Feb 17, 2022
7fbf8d8
wip/refactor tests
jimjbrettj Feb 17, 2022
439cb3f
wip/test refactor
jimjbrettj Feb 17, 2022
b454d70
finish tests
jimjbrettj Feb 17, 2022
00575be
merge dev
jimjbrettj Feb 28, 2022
5d9021e
update github workflows to test core integration tests
jimjbrettj Feb 28, 2022
f48bae4
fix integration tests
jimjbrettj Mar 1, 2022
efd729c
wip/remove hardcoded test vals
jimjbrettj Mar 1, 2022
7a0f337
wip/CE feedback
jimjbrettj Mar 1, 2022
7fa3495
wip
jimjbrettj Mar 1, 2022
b97ea9d
remove mocks from helper func
jimjbrettj Mar 1, 2022
c4bf88e
remove comment
jimjbrettj Mar 1, 2022
a8e48bc
remove hardcoded babeDigests
jimjbrettj Mar 1, 2022
f161f18
PR feedback wip
jimjbrettj Mar 1, 2022
57f3718
CR feedback
jimjbrettj Mar 2, 2022
43b465a
use helper to get root path
jimjbrettj Mar 7, 2022
61496f3
wip/CR feedback
jimjbrettj Mar 7, 2022
9b899ea
wip
jimjbrettj Mar 7, 2022
4013485
respond to feedback
jimjbrettj Mar 7, 2022
ca65fb6
linting
jimjbrettj Mar 8, 2022
96f7448
fix linting
jimjbrettj Mar 8, 2022
daa077b
CR feedback resolved
jimjbrettj Mar 14, 2022
625bb39
clean up
jimjbrettj Mar 14, 2022
619975f
wip/CR feedback
jimjbrettj Mar 21, 2022
17978df
wip/feedback
jimjbrettj Mar 21, 2022
d2d0c4e
resolve feedback
jimjbrettj Mar 21, 2022
bebac17
merge dev
jimjbrettj Mar 21, 2022
b04b414
remove anon struct from accountInfo
jimjbrettj Mar 22, 2022
efcef54
Merge branch 'development' into jimmy/coreServiceTestsP2
jimjbrettj Mar 22, 2022
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
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
matrix:
packages:
[
github.com/ChainSafe/gossamer/dot/core,
github.com/ChainSafe/gossamer/dot/rpc/modules,
github.com/ChainSafe/gossamer/lib/babe,
]
Expand Down
17 changes: 2 additions & 15 deletions dot/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import (
"path/filepath"
"testing"

"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/peerset"
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
Expand All @@ -21,7 +18,6 @@ import (
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/golang/mock/gomock"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/stretchr/testify/require"
)

Expand All @@ -35,9 +31,7 @@ func NewTestService(t *testing.T, cfg *Config) *Service {
}

if cfg.DigestHandler == nil {
digestHandler := NewMockDigestHandler(ctrl)
digestHandler.EXPECT().HandleDigests(gomock.AssignableToTypeOf(new(types.Header)))
cfg.DigestHandler = digestHandler
cfg.DigestHandler = NewMockDigestHandler(ctrl)
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
}

if cfg.Keystore == nil {
Expand Down Expand Up @@ -126,14 +120,7 @@ func NewTestService(t *testing.T, cfg *Config) *Service {
cfg.BlockState.StoreRuntime(cfg.BlockState.BestBlockHash(), cfg.Runtime)

if cfg.Network == nil {
net := NewMockNetwork(ctrl)
net.EXPECT().GossipMessage(gomock.AssignableToTypeOf(new(network.TransactionMessage)))
net.EXPECT().IsSynced().Return(true)
net.EXPECT().ReportPeer(
gomock.AssignableToTypeOf(peerset.ReputationChange{}),
gomock.AssignableToTypeOf(peer.ID("")),
)
cfg.Network = net
cfg.Network = NewMockNetwork(ctrl)
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
}

if cfg.CodeSubstitutes == nil {
Expand Down
24 changes: 22 additions & 2 deletions dot/core/messages_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (

"github.com/centrifuge/go-substrate-rpc-client/v3/signature"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/peerset"
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/sync"
"github.com/ChainSafe/gossamer/dot/types"
Expand All @@ -25,6 +24,10 @@ import (
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/pkg/scale"

"github.com/golang/mock/gomock"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/stretchr/testify/require"
)

func createExtrinsic(t *testing.T, rt runtime.Instance, genHash common.Hash, nonce uint64) types.Extrinsic {
Expand Down Expand Up @@ -77,6 +80,10 @@ func TestService_HandleBlockProduced(t *testing.T) {
Keystore: keystore.NewGlobalKeystore(),
}

digestHandler := NewMockDigestHandler(ctrl)
digestHandler.EXPECT().HandleDigests(gomock.AssignableToTypeOf(new(types.Header)))
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
cfg.DigestHandler = digestHandler

s := NewTestService(t, cfg)
err := s.Start()
require.NoError(t, err)
Expand Down Expand Up @@ -132,9 +139,22 @@ func TestService_HandleTransactionMessage(t *testing.T) {
telemetryMock := NewMockClient(ctrl)
telemetryMock.EXPECT().SendMessage(gomock.Any()).AnyTimes()

digestHandler := NewMockDigestHandler(ctrl)
digestHandler.EXPECT().HandleDigests(gomock.AssignableToTypeOf(new(types.Header)))

net := NewMockNetwork(ctrl)
net.EXPECT().GossipMessage(gomock.AssignableToTypeOf(new(network.TransactionMessage))).AnyTimes()
net.EXPECT().IsSynced().Return(true).AnyTimes()
net.EXPECT().ReportPeer(
gomock.AssignableToTypeOf(peerset.ReputationChange{}),
gomock.AssignableToTypeOf(peer.ID("")),
).AnyTimes()

cfg := &Config{
Keystore: ks,
TransactionState: state.NewTransactionState(telemetryMock),
DigestHandler: digestHandler,
Network: net,
}

s := NewTestService(t, cfg)
Expand Down
20 changes: 8 additions & 12 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package core

import (
"bytes"
"context"
"math/big"
"sync"
Expand All @@ -20,7 +21,8 @@ import (
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/services"
"github.com/ChainSafe/gossamer/lib/transaction"
"github.com/ChainSafe/gossamer/pkg/scale"
cscale "github.com/centrifuge/go-substrate-rpc-client/v3/scale"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v3/types"
)

var (
Expand Down Expand Up @@ -372,14 +374,9 @@ func (s *Service) handleChainReorg(prev, curr common.Hash) error {

for _, ext := range *body {
logger.Tracef("validating transaction on re-org chain for extrinsic %s", ext)
encExt, err := scale.Marshal(ext)
if err != nil {
return err
}

// decode extrinsic and make sure it's not an inherent.
decExt := &types.ExtrinsicData{}
if err = decExt.DecodeVersion(encExt); err != nil {
decExt := &ctypes.Extrinsic{}
decoder := cscale.NewDecoder(bytes.NewReader(ext))
if err = decoder.Decode(&decExt); err != nil {
continue
}

Expand All @@ -388,14 +385,13 @@ func (s *Service) handleChainReorg(prev, curr common.Hash) error {
continue
}

externalExt := types.Extrinsic(append([]byte{byte(types.TxnExternal)}, encExt...))
externalExt := types.Extrinsic(append([]byte{byte(types.TxnExternal)}, ext...))
jimjbrettj marked this conversation as resolved.
Show resolved Hide resolved
txv, err := rt.ValidateTransaction(externalExt)
if err != nil {
logger.Debugf("failed to validate transaction for extrinsic %s: %s", ext, err)
continue
}

vtx := transaction.NewValidTransaction(encExt, txv)
vtx := transaction.NewValidTransaction(ext, txv)
s.transactionState.AddToPool(vtx)
}
}
Expand Down
Loading