Skip to content

Commit

Permalink
feat: save InitChain's ResponseDeliverTxs and add test
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz committed Jun 10, 2024
1 parent 8bcee48 commit 8fa79be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions tm2/pkg/bft/consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func (h *Handshaker) ReplayBlocks(
if err != nil {
return nil, err
}
fmt.Println("got", len(res.TxResponses), "responses after init")
abciResponse := sm.NewABCIResponsesFromNum(len(res.TxResponses))
copy(abciResponse.DeliverTxs, res.TxResponses)
statelib.SaveABCIResponses(h.stateDB, 0, abciResponse)
Expand Down
33 changes: 25 additions & 8 deletions tm2/pkg/bft/consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,19 +1174,20 @@ func (ica *initChainApp) InitChain(req abci.RequestInitChain) abci.ResponseInitC
}
}

func TestGenesisResults(t *testing.T) {
const numInitResponses = 3

func TestHandshakeGenesisResponseDeliverTx(t *testing.T) {
t.Parallel()

app := &initChainApp{}
app := &initTxsApp{}
clientCreator := proxy.NewLocalClientCreator(app)

config := ResetConfig("handshake_test_")
config, genesisFile := ResetConfig("handshake_test_")
defer os.RemoveAll(config.RootDir)
privVal := privval.LoadFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
stateDB, state, store := makeStateAndStore(config, privVal.GetPubKey(), "v0.0.0-test")
stateDB, state, store := makeStateAndStore(config, genesisFile, "v0.0.0-test")

// now start the app using the handshake - it should sync
genDoc, _ := sm.MakeGenesisDocFromFile(config.GenesisFile())
genDoc, _ := sm.MakeGenesisDocFromFile(genesisFile)
tt := reflect.TypeOf(genDoc.AppState)
fmt.Println("genDoc.AppState type", tt)
handshaker := NewHandshaker(stateDB, state, store, genDoc)
Expand All @@ -1199,7 +1200,23 @@ func TestGenesisResults(t *testing.T) {
t.Fatalf("Error on abci handshake: %v", err)
}

// reload the state, check the genesis transaction results are saved
state = sm.LoadState(stateDB)
// check that the genesis transaction results are saved
res, err := sm.LoadABCIResponses(stateDB, 0)
if err != nil {
t.Fatalf("Failed to load ABCI responses: %v", err)
}

if len(res.DeliverTxs) != numInitResponses {
t.Fatalf("Expected %d responses, got %d", numInitResponses, len(res.DeliverTxs))
}
}

type initTxsApp struct {
abci.BaseApplication
}

func (ica *initTxsApp) InitChain(req abci.RequestInitChain) abci.ResponseInitChain {
return abci.ResponseInitChain{
TxResponses: make([]abci.ResponseDeliverTx, numInitResponses),
}
}

0 comments on commit 8fa79be

Please sign in to comment.