|
@ -151,8 +151,8 @@ type testReactorParams struct { |
|
|
mockA bool |
|
|
mockA bool |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func newTestReactor(p testReactorParams) *BlockchainReactor { |
|
|
|
|
|
store, state, _ := newReactorStore(p.genDoc, p.privVals, p.startHeight) |
|
|
|
|
|
|
|
|
func newTestReactor(t *testing.T, p testReactorParams) *BlockchainReactor { |
|
|
|
|
|
store, state, _ := newReactorStore(t, p.genDoc, p.privVals, p.startHeight) |
|
|
reporter := behavior.NewMockReporter() |
|
|
reporter := behavior.NewMockReporter() |
|
|
|
|
|
|
|
|
var appl blockApplier |
|
|
var appl blockApplier |
|
@ -164,15 +164,12 @@ func newTestReactor(p testReactorParams) *BlockchainReactor { |
|
|
cc := proxy.NewLocalClientCreator(app) |
|
|
cc := proxy.NewLocalClientCreator(app) |
|
|
proxyApp := proxy.NewAppConns(cc) |
|
|
proxyApp := proxy.NewAppConns(cc) |
|
|
err := proxyApp.Start() |
|
|
err := proxyApp.Start() |
|
|
if err != nil { |
|
|
|
|
|
panic(fmt.Errorf("error start app: %w", err)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
db := dbm.NewMemDB() |
|
|
db := dbm.NewMemDB() |
|
|
stateStore := sm.NewStore(db) |
|
|
stateStore := sm.NewStore(db) |
|
|
appl = sm.NewBlockExecutor(stateStore, p.logger, proxyApp.Consensus(), mock.Mempool{}, sm.EmptyEvidencePool{}) |
|
|
appl = sm.NewBlockExecutor(stateStore, p.logger, proxyApp.Consensus(), mock.Mempool{}, sm.EmptyEvidencePool{}) |
|
|
if err = stateStore.Save(state); err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
err = stateStore.Save(state) |
|
|
|
|
|
require.NoError(t, err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
r := newReactor(state, store, reporter, appl, true) |
|
|
r := newReactor(state, store, reporter, appl, true) |
|
@ -400,7 +397,7 @@ func TestReactorHelperMode(t *testing.T) { |
|
|
for _, tt := range tests { |
|
|
for _, tt := range tests { |
|
|
tt := tt |
|
|
tt := tt |
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
reactor := newTestReactor(params) |
|
|
|
|
|
|
|
|
reactor := newTestReactor(t, params) |
|
|
mockSwitch := &mockSwitchIo{switchedToConsensus: false} |
|
|
mockSwitch := &mockSwitchIo{switchedToConsensus: false} |
|
|
reactor.io = mockSwitch |
|
|
reactor.io = mockSwitch |
|
|
err := reactor.Start() |
|
|
err := reactor.Start() |
|
@ -457,7 +454,7 @@ func TestReactorSetSwitchNil(t *testing.T) { |
|
|
defer os.RemoveAll(config.RootDir) |
|
|
defer os.RemoveAll(config.RootDir) |
|
|
genDoc, privVals := factory.RandGenesisDoc(config, 1, false, 30) |
|
|
genDoc, privVals := factory.RandGenesisDoc(config, 1, false, 30) |
|
|
|
|
|
|
|
|
reactor := newTestReactor(testReactorParams{ |
|
|
|
|
|
|
|
|
reactor := newTestReactor(t, testReactorParams{ |
|
|
logger: log.TestingLogger(), |
|
|
logger: log.TestingLogger(), |
|
|
genDoc: genDoc, |
|
|
genDoc: genDoc, |
|
|
privVals: privVals, |
|
|
privVals: privVals, |
|
@ -487,15 +484,14 @@ type testApp struct { |
|
|
abci.BaseApplication |
|
|
abci.BaseApplication |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Why are we importing the entire blockExecutor dependency graph here
|
|
|
|
|
|
// when we have the facilities to
|
|
|
|
|
|
func newReactorStore( |
|
|
func newReactorStore( |
|
|
|
|
|
t *testing.T, |
|
|
genDoc *types.GenesisDoc, |
|
|
genDoc *types.GenesisDoc, |
|
|
privVals []types.PrivValidator, |
|
|
privVals []types.PrivValidator, |
|
|
maxBlockHeight int64) (*store.BlockStore, sm.State, *sm.BlockExecutor) { |
|
|
maxBlockHeight int64) (*store.BlockStore, sm.State, *sm.BlockExecutor) { |
|
|
if len(privVals) != 1 { |
|
|
|
|
|
panic("only support one validator") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
t.Helper() |
|
|
|
|
|
|
|
|
|
|
|
require.Len(t, privVals, 1) |
|
|
app := &testApp{} |
|
|
app := &testApp{} |
|
|
cc := proxy.NewLocalClientCreator(app) |
|
|
cc := proxy.NewLocalClientCreator(app) |
|
|
proxyApp := proxy.NewAppConns(cc) |
|
|
proxyApp := proxy.NewAppConns(cc) |
|
@ -507,18 +503,13 @@ func newReactorStore( |
|
|
stateDB := dbm.NewMemDB() |
|
|
stateDB := dbm.NewMemDB() |
|
|
blockStore := store.NewBlockStore(dbm.NewMemDB()) |
|
|
blockStore := store.NewBlockStore(dbm.NewMemDB()) |
|
|
stateStore := sm.NewStore(stateDB) |
|
|
stateStore := sm.NewStore(stateDB) |
|
|
state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(fmt.Errorf("error constructing state from genesis file: %w", err)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
state, err := sm.MakeGenesisState(genDoc) |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
db := dbm.NewMemDB() |
|
|
|
|
|
stateStore = sm.NewStore(db) |
|
|
|
|
|
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(), |
|
|
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(), |
|
|
mock.Mempool{}, sm.EmptyEvidencePool{}) |
|
|
mock.Mempool{}, sm.EmptyEvidencePool{}) |
|
|
if err = stateStore.Save(state); err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
err = stateStore.Save(state) |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
// add blocks in
|
|
|
// add blocks in
|
|
|
for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ { |
|
|
for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ { |
|
@ -533,9 +524,7 @@ func newReactorStore( |
|
|
lastBlockMeta.BlockID, |
|
|
lastBlockMeta.BlockID, |
|
|
time.Now(), |
|
|
time.Now(), |
|
|
) |
|
|
) |
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
lastCommit = types.NewCommit(vote.Height, vote.Round, |
|
|
lastCommit = types.NewCommit(vote.Height, vote.Round, |
|
|
lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()}) |
|
|
lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()}) |
|
|
} |
|
|
} |
|
@ -546,9 +535,7 @@ func newReactorStore( |
|
|
blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()} |
|
|
blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()} |
|
|
|
|
|
|
|
|
state, _, err = blockExec.ApplyBlock(state, blockID, thisBlock) |
|
|
state, _, err = blockExec.ApplyBlock(state, blockID, thisBlock) |
|
|
if err != nil { |
|
|
|
|
|
panic(fmt.Errorf("error apply block: %w", err)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
blockStore.SaveBlock(thisBlock, thisParts, lastCommit) |
|
|
blockStore.SaveBlock(thisBlock, thisParts, lastCommit) |
|
|
} |
|
|
} |
|
|