Skip to content

Commit 1a77f7c

Browse files
authored
using native lotus types & ldevnet for tests (textileio#79)
* use lotus types, create ldevnet Signed-off-by: jsign <jsign.uy@gmail.com> * check deal complete before considering test success Signed-off-by: jsign <jsign.uy@gmail.com>
1 parent 5d2a92c commit 1a77f7c

35 files changed

Lines changed: 1105 additions & 1059 deletions

.github/workflows/test.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ jobs:
1515
uses: actions/setup-go@v1
1616
with:
1717
go-version: 1.13
18+
- name: Install Rust
19+
uses: actions-rs/toolchain@v1
20+
with:
21+
toolchain: stable
22+
override: true
23+
- name: OpenCL dependencies
24+
run: sudo apt-get install mesa-opencl-icd ocl-icd-opencl-dev
1825
- name: Check out code
1926
uses: actions/checkout@v1
2027
- name: Cache dependencies
@@ -25,9 +32,7 @@ jobs:
2532
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
2633
restore-keys: |
2734
${{ runner.os }}-go-
28-
- name: Get dependencies
29-
if: steps.cache-dependencies.outputs.cache-hit != 'true'
30-
run: |
31-
go mod download
35+
- name: Get extern dependencies
36+
run: make all
3237
- name: Test
33-
run: go test ./... -short
38+
run: TRUST_PARAMS=1 go test ./... -short -v

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616

1717
# vscode config folder
1818
.vscode/
19+
20+
.filecoin-build
21+
.update-modules

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "extern/filecoin-ffi"]
2+
path = extern/filecoin-ffi
3+
url = https://github.com/filecoin-project/filecoin-ffi.git

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
all: build
2+
.PHONY: all
3+
4+
SUBMODULES=.update-modules
5+
6+
FFI_PATH:=./extern/filecoin-ffi/
7+
FFI_DEPS:=libfilecoin.a filecoin.pc filecoin.h
8+
FFI_DEPS:=$(addprefix $(FFI_PATH),$(FFI_DEPS))
9+
10+
$(FFI_DEPS): .filecoin-build ;
11+
12+
.filecoin-build: $(FFI_PATH)
13+
$(MAKE) -C $(FFI_PATH) $(FFI_DEPS:$(FFI_PATH)%=%)
14+
@touch $@
15+
16+
.update-modules:
17+
git submodule update --init --recursive
18+
@touch $@
19+
20+
build: .update-modules .filecoin-build
21+
22+
clean:
23+
rm -f .filecoin-build
24+
rm -f .update-modules

api/client/deals.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"context"
55
"io"
66

7+
"github.com/filecoin-project/go-address"
8+
"github.com/filecoin-project/lotus/chain/types"
79
cid "github.com/ipfs/go-cid"
810
"github.com/textileio/filecoin/deals"
911
pb "github.com/textileio/filecoin/deals/pb"
1012
"github.com/textileio/filecoin/index/ask"
11-
"github.com/textileio/filecoin/lotus/types"
13+
1214
"google.golang.org/grpc/codes"
1315
"google.golang.org/grpc/status"
1416
)
@@ -105,8 +107,12 @@ func (d *Deals) Store(ctx context.Context, addr string, data io.Reader, dealConf
105107

106108
failedDeals := make([]deals.DealConfig, len(reply.GetFailedDeals()))
107109
for i, dealConfig := range reply.GetFailedDeals() {
110+
addr, err := address.NewFromString(dealConfig.GetMiner())
111+
if err != nil {
112+
return nil, nil, err
113+
}
108114
failedDeals[i] = deals.DealConfig{
109-
Miner: dealConfig.GetMiner(),
115+
Miner: addr.String(),
110116
EpochPrice: types.NewInt(dealConfig.GetEpochPrice()),
111117
}
112118
}

chainstore/chainstore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"strconv"
99
"sync"
1010

11+
"github.com/filecoin-project/lotus/chain/types"
1112
"github.com/ipfs/go-datastore"
1213
"github.com/ipfs/go-datastore/query"
1314
cbor "github.com/ipfs/go-ipld-cbor"
14-
"github.com/textileio/filecoin/lotus/types"
1515
)
1616

1717
const (

chainstore/chainstore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"os"
77
"testing"
88

9+
"github.com/filecoin-project/lotus/chain/types"
910
"github.com/google/go-cmp/cmp"
1011
"github.com/ipfs/go-cid"
1112
cbor "github.com/ipfs/go-ipld-cbor"
1213
"github.com/multiformats/go-multihash"
13-
"github.com/textileio/filecoin/lotus/types"
1414
"github.com/textileio/filecoin/tests"
1515
)
1616

chainsync/chainsync.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package chainsync
33
import (
44
"context"
55

6-
"github.com/textileio/filecoin/lotus/types"
6+
"github.com/filecoin-project/lotus/chain/store"
7+
"github.com/filecoin-project/lotus/chain/types"
78
)
89

910
// API provides an abstraction to a Filecoin full-node
1011
type API interface {
11-
ChainGetPath(context.Context, types.TipSetKey, types.TipSetKey) ([]*types.HeadChange, error)
12+
ChainGetPath(context.Context, types.TipSetKey, types.TipSetKey) ([]*store.HeadChange, error)
1213
ChainGetGenesis(context.Context) (*types.TipSet, error)
1314
}
1415

@@ -34,7 +35,7 @@ func (cs *ChainSync) Precedes(ctx context.Context, from, to types.TipSetKey) (bo
3435
if len(fpath) == 0 {
3536
return true, nil
3637
}
37-
norevert := fpath[0].Type == types.HCApply
38+
norevert := fpath[0].Type == store.HCApply
3839
return norevert, nil
3940
}
4041

@@ -48,7 +49,7 @@ func ResolveBase(ctx context.Context, api API, left *types.TipSetKey, right type
4849
return nil, nil, err
4950
}
5051
path = append(path, genesis)
51-
gtsk := types.NewTipSetKey(genesis.Cids...)
52+
gtsk := types.NewTipSetKey(genesis.Cids()...)
5253
left = &gtsk
5354
}
5455

@@ -59,9 +60,9 @@ func ResolveBase(ctx context.Context, api API, left *types.TipSetKey, right type
5960

6061
var base *types.TipSetKey
6162
for _, ts := range fpath {
62-
if ts.Type == types.HCApply {
63+
if ts.Type == store.HCApply {
6364
if base == nil {
64-
b := types.NewTipSetKey(ts.Val.Blocks[0].Parents...)
65+
b := types.NewTipSetKey(ts.Val.Blocks()[0].Parents...)
6566
base = &b
6667
}
6768
path = append(path, ts.Val)

chainsync/chainsync_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"context"
55
"testing"
66

7+
"github.com/filecoin-project/lotus/chain/types"
78
"github.com/textileio/filecoin/lotus"
8-
"github.com/textileio/filecoin/lotus/types"
9+
910
"github.com/textileio/filecoin/tests"
1011
)
1112

@@ -24,8 +25,8 @@ func TestPrecede(t *testing.T) {
2425
checkErr(t, err)
2526

2627
csync := New(c)
27-
head := types.NewTipSetKey(h.Cids...)
28-
prevhead := types.NewTipSetKey(h.Blocks[0].Parents...)
28+
head := h.Key()
29+
prevhead := types.NewTipSetKey(h.Blocks()[0].Parents...)
2930
yes, err := csync.Precedes(ctx, prevhead, head)
3031
checkErr(t, err)
3132
if !yes {

deals/deals.go

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import (
1010
"reflect"
1111
"time"
1212

13+
"github.com/filecoin-project/go-address"
14+
"github.com/filecoin-project/lotus/api"
15+
str "github.com/filecoin-project/lotus/chain/store"
16+
"github.com/filecoin-project/lotus/chain/types"
1317
"github.com/ipfs/go-cid"
1418
"github.com/ipfs/go-datastore"
1519
logging "github.com/ipfs/go-log"
16-
"github.com/textileio/filecoin/lotus/types"
1720
)
1821

1922
const (
@@ -28,7 +31,6 @@ var (
2831
// Module exposes storage, monitoring, and Asks from the market.
2932
type Module struct {
3033
api API
31-
ds datastore.Datastore
3234
basePathImport string
3335
}
3436

@@ -54,35 +56,31 @@ type DealInfo struct {
5456

5557
// API interacts with a Filecoin full-node
5658
type API interface {
57-
ClientStartDeal(ctx context.Context, data cid.Cid, addr string, miner string, epochPrice types.BigInt, blocksDuration uint64) (*cid.Cid, error)
59+
ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Address, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error)
5860
ClientImport(ctx context.Context, path string) (cid.Cid, error)
59-
ClientGetDealInfo(context.Context, cid.Cid) (*types.DealInfo, error)
60-
ChainNotify(context.Context) (<-chan []*types.HeadChange, error)
61+
ClientGetDealInfo(context.Context, cid.Cid) (*api.DealInfo, error)
62+
ChainNotify(ctx context.Context) (<-chan []*str.HeadChange, error)
6163
}
6264

6365
// New creates a new deal module
6466
func New(ds datastore.Datastore, api API) *Module {
6567
// can't avoid home base path, ipfs checks: cannot add filestore references outside ipfs root (home folder)
66-
home, err := os.UserHomeDir()
67-
if err != nil {
68-
panic(err)
69-
}
68+
home := os.TempDir()
69+
os.MkdirAll(filepath.Join(home, "textilefc"), os.ModePerm)
7070
dm := &Module{
7171
api: api,
72-
ds: ds,
7372
basePathImport: filepath.Join(home, "textilefc"),
7473
}
7574
return dm
7675
}
7776

7877
// Store creates a proposal deal for data using wallet addr to all miners indicated
7978
// by dealConfigs for duration epochs
80-
func (m *Module) Store(ctx context.Context, addr string, data io.Reader, dealConfigs []DealConfig, duration uint64) ([]cid.Cid, []DealConfig, error) {
79+
func (m *Module) Store(ctx context.Context, strAddr string, data io.Reader, dealConfigs []DealConfig, duration uint64) ([]cid.Cid, []DealConfig, error) {
8180
tmpF, err := ioutil.TempFile(m.basePathImport, "import-*")
8281
if err != nil {
8382
return nil, nil, fmt.Errorf("error when creating tmpfile: %s", err)
8483
}
85-
defer os.Remove(tmpF.Name())
8684
defer tmpF.Close()
8785
if _, err := io.Copy(tmpF, data); err != nil {
8886
return nil, nil, fmt.Errorf("error when copying data to tmpfile: %s", err)
@@ -91,19 +89,24 @@ func (m *Module) Store(ctx context.Context, addr string, data io.Reader, dealCon
9189
if err != nil {
9290
return nil, nil, fmt.Errorf("error when importing data: %s", err)
9391
}
92+
addr, err := address.NewFromString(strAddr)
93+
if err != nil {
94+
return nil, nil, err
95+
}
9496

9597
var proposals []cid.Cid
9698
var failed []DealConfig
97-
for _, dconfig := range dealConfigs {
99+
for _, c := range dealConfigs {
100+
maddr, err := address.NewFromString(c.Miner)
98101
if err != nil {
99-
log.Errorf("miner addr is invalid %v: %s", dconfig, err)
100-
failed = append(failed, dconfig)
102+
log.Errorf("invalid miner address %v: %s", c, err)
103+
failed = append(failed, c)
101104
continue
102105
}
103-
proposal, err := m.api.ClientStartDeal(ctx, dataCid, addr, dconfig.Miner, dconfig.EpochPrice, duration)
106+
proposal, err := m.api.ClientStartDeal(ctx, dataCid, addr, maddr, c.EpochPrice, duration)
104107
if err != nil {
105-
log.Errorf("error when starting deal with %v: %s", dconfig, err)
106-
failed = append(failed, dconfig)
108+
log.Errorf("starting deal with %v: %s", c, err)
109+
failed = append(failed, c)
107110
continue
108111
}
109112
proposals = append(proposals, *proposal)
@@ -121,7 +124,7 @@ func (m *Module) Watch(ctx context.Context, proposals []cid.Cid) (<-chan DealInf
121124
go func() {
122125
defer close(ch)
123126

124-
currentState := make(map[cid.Cid]types.DealInfo)
127+
currentState := make(map[cid.Cid]api.DealInfo)
125128
tout := time.After(initialWait)
126129
for {
127130
select {
@@ -141,7 +144,7 @@ func (m *Module) Watch(ctx context.Context, proposals []cid.Cid) (<-chan DealInf
141144
return ch, nil
142145
}
143146

144-
func (m *Module) pushNewChanges(ctx context.Context, currState map[cid.Cid]types.DealInfo, proposals []cid.Cid, ch chan<- DealInfo) error {
147+
func (m *Module) pushNewChanges(ctx context.Context, currState map[cid.Cid]api.DealInfo, proposals []cid.Cid, ch chan<- DealInfo) error {
145148
for _, pcid := range proposals {
146149
dinfo, err := m.api.ClientGetDealInfo(ctx, pcid)
147150
if err != nil {
@@ -153,8 +156,8 @@ func (m *Module) pushNewChanges(ctx context.Context, currState map[cid.Cid]types
153156
newState := DealInfo{
154157
ProposalCid: dinfo.ProposalCid,
155158
StateID: dinfo.State,
156-
StateName: types.DealStates[dinfo.State],
157-
Miner: dinfo.Provider,
159+
StateName: api.DealStates[dinfo.State],
160+
Miner: dinfo.Provider.String(),
158161
PieceRef: dinfo.PieceRef,
159162
Size: dinfo.Size,
160163
PricePerEpoch: dinfo.PricePerEpoch,

0 commit comments

Comments
 (0)