Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
19 changes: 19 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package baseapp

import (
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -757,6 +758,24 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res
Value: []byte(app.version),
}

case "snapshots":

response := app.ListSnapshots(abci.RequestListSnapshots{})

var responseValue []byte

responseValue, err := json.Marshal(response)

if err != nil {
sdkerrors.QueryResult(sdkerrors.Wrap(err, fmt.Sprintf("failed to marshal list snapshots response %v", response)))
}

return abci.ResponseQuery{
Codespace: sdkerrors.RootCodespace,
Height: req.Height,
Value: responseValue,
}

default:
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query: %s", path))
}
Expand Down
28 changes: 23 additions & 5 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package baseapp
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
Expand Down Expand Up @@ -1821,17 +1822,34 @@ func TestListSnapshots(t *testing.T) {
require.NoError(t, err)
defer teardown()

expected := abci.ResponseListSnapshots{Snapshots: []*abci.Snapshot{
{Height: 4, Format: 1, Chunks: 2},
{Height: 2, Format: 1, Chunks: 1},
}}

resp := app.ListSnapshots(abci.RequestListSnapshots{})
for _, s := range resp.Snapshots {
queryResponse := app.Query(abci.RequestQuery{
Path: "/app/snapshots",
})

queryListSnapshotsResp := abci.ResponseListSnapshots{}
err = json.Unmarshal(queryResponse.Value, &queryListSnapshotsResp)
require.NoError(t, err)

for i, s := range resp.Snapshots {
querySnapshot := queryListSnapshotsResp.Snapshots[i]
// we check that the query snapshot and function snapshot are equal
// Then we check that the hash and metadata are not empty. We atm
// do not have a good way to generate the expected value for these.
assert.Equal(t, *s, *querySnapshot)
assert.NotEmpty(t, s.Hash)
assert.NotEmpty(t, s.Metadata)
// Set hash and metadata to nil, so we can check the other snapshot
// fields against expected
s.Hash = nil
s.Metadata = nil
}
assert.Equal(t, abci.ResponseListSnapshots{Snapshots: []*abci.Snapshot{
{Height: 4, Format: 1, Chunks: 2},
{Height: 2, Format: 1, Chunks: 1},
}}, resp)
assert.Equal(t, expected, resp)
}

func TestSnapshotWithPruning(t *testing.T) {
Expand Down