diff --git a/testhelpers/fat/action_client.go b/testhelpers/fat/action_client.go new file mode 100644 index 0000000000..f285e0cdf3 --- /dev/null +++ b/testhelpers/fat/action_client.go @@ -0,0 +1,67 @@ +package fat + +import ( + "context" + "encoding/json" + "fmt" + "io" + + "github.com/filecoin-project/go-filecoin/address" + "github.com/filecoin-project/go-filecoin/protocol/storage" + + "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid" + "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files" +) + +// ClientCat runs the client cat command against the filecoin process. +// A ReadCloser is returned representing the data. +// TODO(frrist): address buffering in filecoin plugins to exert appropriate backpressure on the +// reader IPTB returns. +func (f *Filecoin) ClientCat(ctx context.Context, cid cid.Cid) (io.ReadCloser, error) { + out, err := f.RunCmdWithStdin(ctx, nil, "go-filecoin", "client", "cat", cid.String()) + if err != nil { + return nil, err + } + return out.Stdout(), err +} + +// ClientImportData runs the client import data command against the filecoin process. +func (f *Filecoin) ClientImportData(ctx context.Context, data files.File) (cid.Cid, error) { + var out cid.Cid + if err := f.RunCmdJSONWithStdin(ctx, data, &out, "go-filecoin", "client", "import"); err != nil { + return cid.Undef, err + } + return out, nil +} + +// ClientProposeStorageDeal runs the client propose-storage-deal command against the filecoin process. +func (f *Filecoin) ClientProposeStorageDeal(ctx context.Context, data cid.Cid, + miner address.Address, ask uint64, duration uint64, allowDuplicates bool) (*storage.DealResponse, error) { + + var out storage.DealResponse + sData := data.String() + sMiner := miner.String() + sAsk := fmt.Sprintf("%d", ask) + sDuration := fmt.Sprintf("%d", duration) + + if err := f.RunCmdJSONWithStdin(ctx, nil, &out, "go-filecoin", "client", "propose-storage-deal", sMiner, sData, sAsk, sDuration); err != nil { + return nil, err + } + return &out, nil +} + +// ClientQueryStorageDeal runs the client query-storage-deal command against the filecoin process. +func (f *Filecoin) ClientQueryStorageDeal(ctx context.Context, prop cid.Cid) (*storage.DealResponse, error) { + var out storage.DealResponse + + if err := f.RunCmdJSONWithStdin(ctx, nil, &out, "go-filecoin", "client", "query-storage-deal", prop.String()); err != nil { + return nil, err + } + return &out, nil +} + +// ClientListAsks runs the client list-asks command against the filecoin process. +// A json decoer is returned that asks may be decoded from. +func (f *Filecoin) ClientListAsks(ctx context.Context) (*json.Decoder, error) { + return f.RunCmdLDJSONWithStdin(ctx, nil, "go-filecoin", "client", "list-asks") +} diff --git a/testhelpers/fat/action_retrieval_client.go b/testhelpers/fat/action_retrieval_client.go new file mode 100644 index 0000000000..3710581c31 --- /dev/null +++ b/testhelpers/fat/action_retrieval_client.go @@ -0,0 +1,19 @@ +package fat + +import ( + "context" + "io" + + "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid" + + "github.com/filecoin-project/go-filecoin/address" +) + +// RetrievalClientRetrievePiece runs the retrieval-client retrieve-piece commands against the filecoin process. +func (f *Filecoin) RetrievalClientRetrievePiece(ctx context.Context, pieceCID cid.Cid, minerAddr address.Address) (io.ReadCloser, error) { + out, err := f.RunCmdWithStdin(ctx, nil, "go-filecoin", "retrieval-client", "retrieve-piece", minerAddr.String(), pieceCID.String()) + if err != nil { + return nil, err + } + return out.Stdout(), nil +}