Skip to content

Commit

Permalink
fix chain head
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist authored and phritz committed Mar 22, 2019
1 parent 29f585c commit 3691d38
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
15 changes: 12 additions & 3 deletions commands/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ var chainHeadCmd = &cmds.Command{
Tagline: "Get heaviest tipset CIDs",
},
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
headTipset := GetPorcelainAPI(env).ChainHead(req.Context)
blocks := headTipset.ToSlice()
return re.Emit(blocks)
return re.Emit(GetPorcelainAPI(env).ChainHead(req.Context).ToSortedCidSet())
},
Type: []cid.Cid{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, res []cid.Cid) error {
for _, r := range res {
_, err := fmt.Fprintln(w, r.String())
if err != nil {
return err
}
}
return nil
}),
},
}

var chainLsCmd = &cmds.Command{
Expand Down
17 changes: 17 additions & 0 deletions commands/chain_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ import (
"gx/ipfs/QmPVkJMTeRC6iBByPWdrRkD3BE5UXsj5HPzb4kPqL186mS/testify/require"
)

func TestChainHead(t *testing.T) {
t.Parallel()
require := require.New(t)
assert := assert.New(t)

d := th.NewDaemon(t).Start()
defer d.ShutdownSuccess()

op := d.RunSuccess("chain", "head")
result := op.ReadStdoutTrimNewlines()

maybeCid, err := cid.Decode(result)
require.NoError(err)

assert.Equal(result, maybeCid.String())
}

func TestChainDaemon(t *testing.T) {
t.Parallel()
t.Run("chain ls with json encoding returns the whole chain as json", func(t *testing.T) {
Expand Down

0 comments on commit 3691d38

Please sign in to comment.