add file i didnt add before

This commit is contained in:
whyrusleeping 2019-11-06 08:10:44 -08:00 committed by Łukasz Magiera
parent 9863942fe2
commit a49b949dca

69
api/test/deals.go Normal file
View File

@ -0,0 +1,69 @@
package test
import (
"context"
"fmt"
"io"
"math/rand"
"testing"
"time"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/impl"
)
func TestDealFlow(t *testing.T, b APIBuilder) {
ctx := context.TODO()
n, sn := b(t, 1, []int{0})
client := n[0].FullNode.(*impl.FullNodeAPI)
miner := sn[0]
_ = miner
addrinfo, err := client.NetAddrsListen(ctx)
if err != nil {
t.Fatal(err)
}
addrinfo.Addrs = nil
if err := miner.NetConnect(ctx, addrinfo); err != nil {
t.Fatal(err)
}
time.Sleep(time.Second)
r := io.LimitReader(rand.New(rand.NewSource(17)), 350)
fcid, err := client.ClientImportLocal(ctx, r)
if err != nil {
t.Fatal(err)
}
maddr, err := address.NewFromString("t0101")
if err != nil {
t.Fatal(err)
}
fmt.Println("FILE CID: ", fcid)
go func() {
time.Sleep(time.Second)
fmt.Println("mining a block now")
if err := n[0].MineOne(ctx); err != nil {
t.Fatal(err)
}
fmt.Println("mined a block")
time.Sleep(time.Second)
fmt.Println("mining a block now")
if err := n[0].MineOne(ctx); err != nil {
t.Fatal(err)
}
}()
deal, err := client.ClientStartDeal(ctx, fcid, maddr, types.NewInt(1), 100)
if err != nil {
t.Fatal(err)
}
fmt.Println("Deal done!", deal)
time.Sleep(time.Second * 10)
}