code cleanup, function tests
This commit is contained in:
parent
0fc4beccc6
commit
35ddd230c2
6 changed files with 525 additions and 439 deletions
|
@ -209,6 +209,7 @@ func CatCSV(filePath string) {
|
|||
}
|
||||
|
||||
func TestCatFullDB(t *testing.T) {
|
||||
t.Skip("Skipping full db test")
|
||||
// url := "lbry://@lothrop#2/lothrop-livestream-games-and-code#c"
|
||||
// "lbry://@lbry", "lbry://@lbry#3", "lbry://@lbry3f", "lbry://@lbry#3fda836a92faaceedfe398225fb9b2ee2ed1f01a", "lbry://@lbry:1", "lbry://@lbry$1"
|
||||
// url := "lbry://@Styxhexenhammer666#2/legacy-media-baron-les-moonves-(cbs#9"
|
||||
|
@ -248,12 +249,13 @@ func TestCatFullDB(t *testing.T) {
|
|||
|
||||
// TestOpenFullDB Tests running a resolve on a full db.
|
||||
func TestOpenFullDB(t *testing.T) {
|
||||
t.Skip("Skipping full db test")
|
||||
// url := "lbry://@lothrop#2/lothrop-livestream-games-and-code#c"
|
||||
// "lbry://@lbry", "lbry://@lbry#3", "lbry://@lbry3f", "lbry://@lbry#3fda836a92faaceedfe398225fb9b2ee2ed1f01a", "lbry://@lbry:1", "lbry://@lbry$1"
|
||||
// url := "lbry://@Styxhexenhammer666#2/legacy-media-baron-les-moonves-(cbs#9"
|
||||
url := "lbry://@Styxhexenhammer666#2/legacy-media-baron-les-moonves-(cbs#9"
|
||||
// url := "lbry://@lbry"
|
||||
// url := "lbry://@lbry#3fda836a92faaceedfe398225fb9b2ee2ed1f01a"
|
||||
url := "lbry://@lbry$1"
|
||||
// url := "lbry://@lbry$1"
|
||||
dbPath := "/mnt/d/data/snapshot_1072108/lbry-rocksdb/"
|
||||
prefixNames := prefixes.GetPrefixes()
|
||||
cfNames := []string{"default", "e", "d", "c"}
|
||||
|
@ -291,6 +293,49 @@ func TestResolve(t *testing.T) {
|
|||
log.Println(expandedResolveResult)
|
||||
}
|
||||
|
||||
// TestGetDBState Tests reading the db state from rocksdb
|
||||
func TestGetDBState(t *testing.T) {
|
||||
filePath := "../testdata/s_resolve.csv"
|
||||
want := uint32(1072108)
|
||||
db, _, toDefer, err := OpenAndFillTmpDBColumnFamlies(filePath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer toDefer()
|
||||
state, err := dbpkg.GetDBState(db)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
log.Printf("state: %#v\n", state)
|
||||
if state.Height != want {
|
||||
t.Errorf("Expected %d, got %d", want, state.Height)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrintChannelCount Utility function to cat the ClaimShortId csv
|
||||
func TestPrintChannelCount(t *testing.T) {
|
||||
filePath := "../testdata/Z_resolve.csv"
|
||||
CatCSV(filePath)
|
||||
}
|
||||
|
||||
func TestGetClaimsInChannelCount(t *testing.T) {
|
||||
channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd")
|
||||
filePath := "../testdata/Z_resolve.csv"
|
||||
want := uint32(3670)
|
||||
db, _, toDefer, err := OpenAndFillTmpDBColumnFamlies(filePath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer toDefer()
|
||||
count, err := dbpkg.GetClaimsInChannelCount(db, channelHash)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != want {
|
||||
t.Errorf("Expected %d, got %d", want, count)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrintClaimShortId Utility function to cat the ClaimShortId csv
|
||||
func TestPrintClaimShortId(t *testing.T) {
|
||||
filePath := "../testdata/F_cat.csv"
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v2/extras/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -136,6 +137,12 @@ type DBStateValue struct {
|
|||
EsSyncHeight uint32
|
||||
}
|
||||
|
||||
func NewDBStateKey() *DBStateKey {
|
||||
return &DBStateKey{
|
||||
Prefix: []byte{DBState},
|
||||
}
|
||||
}
|
||||
|
||||
func (k *DBStateKey) PackKey() []byte {
|
||||
prefixLen := 1
|
||||
n := prefixLen
|
||||
|
@ -1345,7 +1352,7 @@ func NewClaimToTXOKey(claimHash []byte) *ClaimToTXOKey {
|
|||
|
||||
func (v *ClaimToTXOValue) NormalizedName() string {
|
||||
//TODO implement? Might not need to do anything.
|
||||
return v.Name
|
||||
return util.NormalizeName(v.Name)
|
||||
}
|
||||
|
||||
func (k *ClaimToTXOKey) PackKey() []byte {
|
||||
|
@ -1875,6 +1882,14 @@ type ChannelToClaimValue struct {
|
|||
ClaimHash []byte `json:"claim_hash"`
|
||||
}
|
||||
|
||||
func NewChannelToClaimKey(channelHash []byte, normalizedName string) *ChannelToClaimKey {
|
||||
return &ChannelToClaimKey{
|
||||
Prefix: []byte{ChannelToClaim},
|
||||
SigningHash: channelHash,
|
||||
Name: normalizedName,
|
||||
}
|
||||
}
|
||||
|
||||
func (k *ChannelToClaimKey) PackKey() []byte {
|
||||
prefixLen := 1
|
||||
nameLen := len(k.Name)
|
||||
|
@ -1996,6 +2011,13 @@ type ChannelCountValue struct {
|
|||
Count uint32 `json:"count"`
|
||||
}
|
||||
|
||||
func NewChannelCountKey(channelHash []byte) *ChannelCountKey {
|
||||
return &ChannelCountKey{
|
||||
Prefix: []byte{ChannelCount},
|
||||
ChannelHash: channelHash,
|
||||
}
|
||||
}
|
||||
|
||||
func (k *ChannelCountKey) PackKey() []byte {
|
||||
prefixLen := 1
|
||||
// b'>20sLH'
|
||||
|
@ -3225,6 +3247,13 @@ type RepostValue struct {
|
|||
RepostedClaimHash []byte `json:"reposted_claim_hash"`
|
||||
}
|
||||
|
||||
func NewRepostKey(claimHash []byte) *RepostKey {
|
||||
return &RepostKey{
|
||||
Prefix: []byte{Repost},
|
||||
ClaimHash: claimHash,
|
||||
}
|
||||
}
|
||||
|
||||
func (k *RepostKey) PackKey() []byte {
|
||||
prefixLen := 1
|
||||
// b'>20s'
|
||||
|
@ -3334,6 +3363,13 @@ type RepostedValue struct {
|
|||
ClaimHash []byte `json:"claim_hash"`
|
||||
}
|
||||
|
||||
func NewRepostedKey(claimHash []byte) *RepostedKey {
|
||||
return &RepostedKey{
|
||||
Prefix: []byte{RepostedClaim},
|
||||
RepostedClaimHash: claimHash,
|
||||
}
|
||||
}
|
||||
|
||||
func (k *RepostedKey) PackKey() []byte {
|
||||
prefixLen := 1
|
||||
// b'>20sLH'
|
||||
|
|
17
main.go
17
main.go
|
@ -110,17 +110,16 @@ func main() {
|
|||
|
||||
return
|
||||
} else if args.CmdType == server.DBCmd3 {
|
||||
var rawPrefix byte = prefixes.TXOToClaim
|
||||
// channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd")
|
||||
var rawPrefix byte = prefixes.DBState
|
||||
prefix := []byte{rawPrefix}
|
||||
columnFamily := string(prefix)
|
||||
// start := &prefixes.ClaimShortIDKey{
|
||||
// Prefix: []byte{prefixes.ClaimShortIdPrefix},
|
||||
// NormalizedName: "cat",
|
||||
// PartialClaimId: "",
|
||||
// RootTxNum: 0,
|
||||
// RootPosition: 0,
|
||||
// start := &prefixes.ChannelCountKey{
|
||||
// Prefix: prefix,
|
||||
// ChannelHash: channelHash,
|
||||
// }
|
||||
// startRaw := prefixes.ClaimShortIDKeyPackPartial(start, 1)
|
||||
// startRaw := prefixes.ChannelCountKeyPackPartial(start, 1)
|
||||
// startRaw := start.PackKey()
|
||||
options := &db.IterOptions{
|
||||
FillCache: false,
|
||||
Prefix: prefix,
|
||||
|
@ -141,7 +140,7 @@ func main() {
|
|||
|
||||
options.CfHandle = handles[1]
|
||||
|
||||
db.ReadWriteRawNColumnFamilies(dbVal, options, fmt.Sprintf("./testdata/%s_2.csv", columnFamily), 10)
|
||||
db.ReadWriteRawNColumnFamilies(dbVal, options, fmt.Sprintf("./testdata/%s_resolve.csv", columnFamily), 1)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
2
testdata/Z_resolve.csv
vendored
Normal file
2
testdata/Z_resolve.csv
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
Z,,
|
||||
Z,5a2556ed1cab9d17f2a9392030a9ad7f5d138f11bd,00000e56
|
|
2
testdata/s_resolve.csv
vendored
Normal file
2
testdata/s_resolve.csv
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
s,,
|
||||
s,73,9c89283ba0f3227f6c03b70216b9f665f0118d5e0fa729cedf4fb34d6a34f46300105bec03f782718ccd27260ce980e7d3d0b5c5f7be1517027b68104109128a34d1cc562f32008e00105bef0014f734000700105befffffffffffffffff00105bec
|
|
Loading…
Reference in a new issue