finish migrating deals test.
This commit is contained in:
parent
e84b8ab3a0
commit
183814a826
@ -26,11 +26,11 @@ func TestAPI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type apiSuite struct {
|
type apiSuite struct {
|
||||||
opts []kit2.NodeOpt
|
opts []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// runAPITest is the entry point to API test suite
|
// 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}
|
ts := apiSuite{opts: opts}
|
||||||
|
|
||||||
t.Run("version", ts.testVersion)
|
t.Run("version", ts.testVersion)
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/itests/kit"
|
"github.com/filecoin-project/lotus/itests/kit"
|
||||||
"github.com/filecoin-project/lotus/itests/kit2"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
@ -352,75 +352,33 @@ func TestOfflineDealFlow(t *testing.T) {
|
|||||||
t.Run("fastretrieval", func(t *testing.T) { runTest(t, true) })
|
t.Run("fastretrieval", func(t *testing.T) { runTest(t, true) })
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
func TestZeroPricePerByteRetrieval(t *testing.T) {
|
||||||
// func runSecondDealRetrievalTest(t *testing.T, b kit.APIBuilder, blocktime time.Duration) {
|
if testing.Short() {
|
||||||
// ctx := context.Background()
|
t.Skip("skipping test in short mode")
|
||||||
//
|
}
|
||||||
// fulls, miners := b(t, kit.OneFull, kit.OneMiner)
|
|
||||||
// client, miner := fulls[0].FullNode.(*impl.FullNodeAPI), miners[0]
|
kit2.QuietMiningLogs()
|
||||||
//
|
|
||||||
// kit.ConnectAndStartMining(t, blocktime, miner, client)
|
var (
|
||||||
//
|
blockTime = 10 * time.Millisecond
|
||||||
// dh := kit.NewDealHarness(t, client, miner)
|
startEpoch = abi.ChainEpoch(2 << 12)
|
||||||
//
|
)
|
||||||
// {
|
|
||||||
// data1 := make([]byte, 800)
|
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs())
|
||||||
// rand.New(rand.NewSource(int64(3))).Read(data1)
|
ens.InterconnectAll().BeginMining(blockTime)
|
||||||
// r := bytes.NewReader(data1)
|
|
||||||
//
|
ctx := context.Background()
|
||||||
// fcid1, err := client.ClientImportLocal(ctx, r)
|
|
||||||
// if err != nil {
|
ask, err := miner.MarketGetRetrievalAsk(ctx)
|
||||||
// t.Fatal(err)
|
require.NoError(t, err)
|
||||||
// }
|
|
||||||
//
|
ask.PricePerByte = abi.NewTokenAmount(0)
|
||||||
// data2 := make([]byte, 800)
|
err = miner.MarketSetRetrievalAsk(ctx, ask)
|
||||||
// rand.New(rand.NewSource(int64(9))).Read(data2)
|
require.NoError(t, err)
|
||||||
// r2 := bytes.NewReader(data2)
|
|
||||||
//
|
dh := kit2.NewDealHarness(t, client, miner)
|
||||||
// fcid2, err := client.ClientImportLocal(ctx, r2)
|
runConcurrentDeals(t, dh, fullDealCyclesOpts{
|
||||||
// if err != nil {
|
n: 1,
|
||||||
// t.Fatal(err)
|
startEpoch: startEpoch,
|
||||||
// }
|
})
|
||||||
//
|
}
|
||||||
// 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)
|
|
||||||
// }
|
|
||||||
|
@ -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)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user