forked from Murmuration-Labs/bitscreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitscreen_test.go
87 lines (70 loc) · 1.54 KB
/
bitscreen_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package bitscreen
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"testing"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/ipfs/go-cid"
"gotest.tools/assert"
)
func ScreenDealProposal(deal storagemarket.MinerDeal) bool {
cid := deal.ProposalCid
return BlockCid(cid)
}
func _handleErr(e error) error {
log.Fatal(e)
return e
}
func _buildDeal() (storagemarket.MinerDeal, error) {
f := "./test_deal.json"
j, err := os.Open(f)
if err != nil {
fmt.Println(err)
}
defer j.Close()
b, _ := ioutil.ReadAll(j)
var d storagemarket.MinerDeal
if e := json.Unmarshal(b, &d); e != nil {
return d, _handleErr(e)
}
return d, nil
}
func _maybeDeleteBitscreen() {
p := GetPath()
if FileExists(p) {
e := os.RemoveAll(p)
if e != nil {
sigterm(e)
}
}
}
func _setCID(c cid.Cid) (cid.Cid, error) {
p := GetPath()
return c, ioutil.WriteFile(p, []byte(c.String()+"\n"), os.ModePerm)
}
func TestScreenDealProposalExists(t *testing.T) {
os.Setenv("BITSCREEN_FILENAME", "test/bitscreen")
// Test CID exists in bitscreen, should return 1
MaybeCreateBitscreen()
d, e := _buildDeal()
if e != nil {
_handleErr(e)
}
_setCID(d.ProposalCid)
result := ScreenDealProposal(d)
assert.Equal(t, result, true)
_maybeDeleteBitscreen()
}
func TestScreenDealProposalNotExists(t *testing.T) {
os.Setenv("BITSCREEN_FILENAME", "test/bitscreen")
// Test CID does not exist in bitscreen, should return 0
d, e := _buildDeal()
if e != nil {
_handleErr(e)
}
result := ScreenDealProposal(d)
assert.Equal(t, result, false)
}