finish migrating deals test.

This commit is contained in:
Raúl Kripalani 2021-06-13 23:43:22 +01:00
parent e84b8ab3a0
commit 183814a826
4 changed files with 32 additions and 182 deletions

View File

@ -26,11 +26,11 @@ func TestAPI(t *testing.T) {
}
type apiSuite struct {
opts []kit2.NodeOpt
opts []interface{}
}
// runAPITest is the entry point to API test suite
func runAPITest(t *testing.T, opts ...kit2.NodeOpt) {
func runAPITest(t *testing.T, opts ...interface{}) {
ts := apiSuite{opts: opts}
t.Run("version", ts.testVersion)

View File

@ -8,7 +8,6 @@ import (
"time"
"github.com/filecoin-project/lotus/itests/kit"
"github.com/filecoin-project/lotus/itests/kit2"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/abi"

View File

@ -352,75 +352,33 @@ func TestOfflineDealFlow(t *testing.T) {
t.Run("fastretrieval", func(t *testing.T) { runTest(t, true) })
}
//
// func runSecondDealRetrievalTest(t *testing.T, b kit.APIBuilder, blocktime time.Duration) {
// ctx := context.Background()
//
// fulls, miners := b(t, kit.OneFull, kit.OneMiner)
// client, miner := fulls[0].FullNode.(*impl.FullNodeAPI), miners[0]
//
// kit.ConnectAndStartMining(t, blocktime, miner, client)
//
// dh := kit.NewDealHarness(t, client, miner)
//
// {
// data1 := make([]byte, 800)
// rand.New(rand.NewSource(int64(3))).Read(data1)
// r := bytes.NewReader(data1)
//
// fcid1, err := client.ClientImportLocal(ctx, r)
// if err != nil {
// t.Fatal(err)
// }
//
// data2 := make([]byte, 800)
// rand.New(rand.NewSource(int64(9))).Read(data2)
// r2 := bytes.NewReader(data2)
//
// fcid2, err := client.ClientImportLocal(ctx, r2)
// if err != nil {
// t.Fatal(err)
// }
//
// deal1 := dh.StartDeal(ctx, fcid1, true, 0)
//
// // TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
// time.Sleep(time.Second)
// dh.WaitDealSealed(ctx, deal1, true, false, nil)
//
// deal2 := dh.StartDeal(ctx, fcid2, true, 0)
//
// time.Sleep(time.Second)
// dh.WaitDealSealed(ctx, deal2, false, false, nil)
//
// // Retrieval
// info, err := client.ClientGetDealInfo(ctx, *deal2)
// require.NoError(t, err)
//
// rf, _ := miner.SectorsRefs(ctx)
// fmt.Printf("refs: %+v\n", rf)
//
// dh.PerformRetrieval(ctx, fcid2, &info.PieceCID, false, data2)
// }
// }
//
// func runZeroPricePerByteRetrievalDealFlow(t *testing.T, b kit.APIBuilder, blocktime time.Duration, startEpoch abi.ChainEpoch) {
// ctx := context.Background()
//
// fulls, miners := b(t, kit.OneFull, kit.OneMiner)
// client, miner := fulls[0].FullNode.(*impl.FullNodeAPI), miners[0]
//
// kit.ConnectAndStartMining(t, blocktime, miner, client)
//
// dh := kit.NewDealHarness(t, client, miner)
//
// // Set price-per-byte to zero
// ask, err := miner.MarketGetRetrievalAsk(ctx)
// require.NoError(t, err)
//
// ask.PricePerByte = abi.NewTokenAmount(0)
// err = miner.MarketSetRetrievalAsk(ctx, ask)
// require.NoError(t, err)
//
// dh.MakeOnlineDeal(ctx, 6, false, false, startEpoch)
// }
func TestZeroPricePerByteRetrieval(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
kit2.QuietMiningLogs()
var (
blockTime = 10 * time.Millisecond
startEpoch = abi.ChainEpoch(2 << 12)
)
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs())
ens.InterconnectAll().BeginMining(blockTime)
ctx := context.Background()
ask, err := miner.MarketGetRetrievalAsk(ctx)
require.NoError(t, err)
ask.PricePerByte = abi.NewTokenAmount(0)
err = miner.MarketSetRetrievalAsk(ctx, ask)
require.NoError(t, err)
dh := kit2.NewDealHarness(t, client, miner)
runConcurrentDeals(t, dh, fullDealCyclesOpts{
n: 1,
startEpoch: startEpoch,
})
}

View File

@ -1,107 +0,0 @@
package kit2
import (
"context"
"fmt"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/v2/actors/builtin"
"github.com/stretchr/testify/require"
lcli "github.com/urfave/cli/v2"
)
// RunClientTest exercises some of the Client CLI commands
func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode TestFullNode) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
// Create mock CLI
mockCLI := NewMockCLI(ctx, t, cmds)
clientCLI := mockCLI.Client(clientNode.ListenAddr)
// Get the Miner address
addrs, err := clientNode.StateListMiners(ctx, types.EmptyTSK)
require.NoError(t, err)
require.Len(t, addrs, 1)
minerAddr := addrs[0]
fmt.Println("Miner:", minerAddr)
// client query-ask <Miner addr>
out := clientCLI.RunCmd("client", "query-ask", minerAddr.String())
require.Regexp(t, regexp.MustCompile("Ask:"), out)
// Create a deal (non-interactive)
// client deal --start-epoch=<start epoch> <cid> <Miner addr> 1000000attofil <duration>
res, _ := clientNode.CreateImportFile(ctx, 1, 0)
require.NoError(t, err)
startEpoch := fmt.Sprintf("--start-epoch=%d", 2<<12)
dataCid := res.Root
price := "1000000attofil"
duration := fmt.Sprintf("%d", build.MinDealDuration)
out = clientCLI.RunCmd("client", "deal", startEpoch, dataCid.String(), minerAddr.String(), price, duration)
fmt.Println("client deal", out)
// Create a deal (interactive)
// client deal
// <cid>
// <duration> (in days)
// <miner addr>
// "no" (verified Client)
// "yes" (confirm deal)
res, _ = clientNode.CreateImportFile(ctx, 2, 0)
require.NoError(t, err)
dataCid2 := res.Root
duration = fmt.Sprintf("%d", build.MinDealDuration/builtin.EpochsInDay)
cmd := []string{"client", "deal"}
interactiveCmds := []string{
dataCid2.String(),
duration,
minerAddr.String(),
"no",
"yes",
}
out = clientCLI.RunInteractiveCmd(cmd, interactiveCmds)
fmt.Println("client deal:\n", out)
// Wait for provider to start sealing deal
dealStatus := ""
for {
// client list-deals
out = clientCLI.RunCmd("client", "list-deals")
fmt.Println("list-deals:\n", out)
lines := strings.Split(out, "\n")
require.GreaterOrEqual(t, len(lines), 2)
re := regexp.MustCompile(`\s+`)
parts := re.Split(lines[1], -1)
if len(parts) < 4 {
require.Fail(t, "bad list-deals output format")
}
dealStatus = parts[3]
fmt.Println(" Deal status:", dealStatus)
st := CategorizeDealState(dealStatus)
require.NotEqual(t, TestDealStateFailed, st)
if st == TestDealStateComplete {
break
}
time.Sleep(time.Second)
}
// Retrieve the first file from the Miner
// client retrieve <cid> <file path>
tmpdir := t.TempDir()
path := filepath.Join(tmpdir, "outfile.dat")
out = clientCLI.RunCmd("client", "retrieve", dataCid.String(), path)
fmt.Println("retrieve:\n", out)
require.Regexp(t, regexp.MustCompile("Success"), out)
}