diff --git a/internal/state/store.go b/internal/state/store.go index 954481b81..eb2408660 100644 --- a/internal/state/store.go +++ b/internal/state/store.go @@ -89,7 +89,7 @@ type Store interface { // LoadABCIResponses loads the abciResponse for a given height LoadABCIResponses(int64) (*tmstate.ABCIResponses, error) //LoadLastABCIResponse loads the last abciResponse for a given height - LoadLastABCIResponse(int64) (*tmstate.ABCIResponsesInfo, error) + LoadLastABCIResponse(int64) (*tmstate.ABCIResponses, error) // LoadConsensusParams loads the consensus params for a given height LoadConsensusParams(int64) (types.ConsensusParams, error) // Save overwrites the previous state with the updated one @@ -454,7 +454,7 @@ func (store dbStore) LoadABCIResponses(height int64) (*tmstate.ABCIResponses, er // This is used for recovering from crashes where we called app.Commit and // before we called s.Save(). It can also be used to produce Merkle proofs of // the result of txs. -func (store dbStore) LoadLastABCIResponse(height int64) (*tmstate.ABCIResponsesInfo, error) { +func (store dbStore) LoadLastABCIResponse(height int64) (*tmstate.ABCIResponses, error) { bz, err := store.db.Get(lastABCIResponseKey) if err != nil { return nil, err @@ -476,7 +476,7 @@ func (store dbStore) LoadLastABCIResponse(height int64) (*tmstate.ABCIResponsesI if height != abciResponse.GetHeight() { return nil, errors.New("expected height %d but last stored abci responses was at height %d") } else { - return abciResponse, nil + return abciResponse.AbciResponses, nil } } diff --git a/internal/state/store_test.go b/internal/state/store_test.go index e44abbd5d..8f45c64f6 100644 --- a/internal/state/store_test.go +++ b/internal/state/store_test.go @@ -307,6 +307,13 @@ func TestABCIResponsesResultsHash(t *testing.T) { } func TestLastABCIResponses(t *testing.T) { + //if the state store is empty + stateDB := dbm.NewMemDB() + stateStore := sm.NewStore(stateDB, false) + responses, err := stateStore.LoadABCIResponses(1) + require.Nil(t, responses) + fmt.Println(responses) + //stub the abciresponses response1 := &tmstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, @@ -316,18 +323,18 @@ func TestLastABCIResponses(t *testing.T) { EndBlock: &abci.ResponseEndBlock{}, } //Create new db and state store and set discard abciresponses to false - stateDB := dbm.NewMemDB() - stateStore := sm.NewStore(stateDB, false) + stateDB = dbm.NewMemDB() + stateStore = sm.NewStore(stateDB, false) height := int64(response1.Size()) //save the last abci response - err := stateStore.SaveABCIResponses(height, response1) + err = stateStore.SaveABCIResponses(height, response1) require.NoError(t, err) //search for the last abciresponse and check if it has saved lastResponse, err := stateStore.LoadLastABCIResponse(height) require.NoError(t, err) fmt.Println(lastResponse) //check to see if the saved response height is the same as the loaded height - assert.Equal(t, lastResponse.Height, int64(response1.Size())) + assert.Equal(t, int64(lastResponse.Size()), int64(response1.Size())) //stub the second abciresponse response2 := &tmstate.ABCIResponses{ @@ -350,9 +357,9 @@ func TestLastABCIResponses(t *testing.T) { require.NotNil(t, lastResponse2) fmt.Println(lastResponse2) //check to see if the saved response height is the same as the loaded height - assert.Equal(t, lastResponse2.Height, int64(response2.Size())) + assert.Equal(t, int64(lastResponse2.Size()), int64(response2.Size())) //check if the abci response didnt save in the abciresponses - responses, err := stateStore.LoadABCIResponses(height) + responses, err = stateStore.LoadABCIResponses(height) require.Error(t, err, responses) require.Nil(t, responses) fmt.Println(responses)