Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 {
responseValue = []byte(err.Error())
}

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
29 changes: 24 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,35 @@ 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]

assert.NotEmpty(t, s.Hash)
assert.NotEmpty(t, s.Metadata)
s.Hash = nil
s.Metadata = nil

assert.NotEmpty(t, querySnapshot.Hash)
assert.NotEmpty(t, querySnapshot.Metadata)
querySnapshot.Hash = nil
querySnapshot.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)
assert.Equal(t, expected, queryListSnapshotsResp)
}

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