more tests

This commit is contained in:
Jeffrey Picard 2022-02-23 17:26:43 -05:00
parent f282294e07
commit d96cfc6638
6 changed files with 131 additions and 9 deletions

View file

@ -318,9 +318,9 @@ func GetRepostedCount(db *ReadOnlyDBColumnFamily, claimHash []byte) (int, error)
key := prefixes.NewRepostedKey(claimHash) key := prefixes.NewRepostedKey(claimHash)
keyPrefix := prefixes.RepostedKeyPackPartial(key, 1) keyPrefix := prefixes.RepostedKeyPackPartial(key, 1)
// Prefix and handle // Prefix and handle
options := NewIterateOptions().WithPrefix(prefix).WithCfHandle(handle) options := NewIterateOptions().WithPrefix(keyPrefix).WithCfHandle(handle)
// Start and stop bounds // Start and stop bounds
options = options.WithStart(keyPrefix) // options = options.WithStart(keyPrefix)
// Don't include the key // Don't include the key
options = options.WithIncludeValue(false) options = options.WithIncludeValue(false)

View file

@ -294,7 +294,6 @@ func TestResolve(t *testing.T) {
log.Println(expandedResolveResult) log.Println(expandedResolveResult)
} }
// TestGetDBState Tests reading the db state from rocksdb
func TestGetDBState(t *testing.T) { func TestGetDBState(t *testing.T) {
filePath := "../testdata/s_resolve.csv" filePath := "../testdata/s_resolve.csv"
want := uint32(1072108) want := uint32(1072108)
@ -313,7 +312,74 @@ func TestGetDBState(t *testing.T) {
} }
} }
// TestPrintChannelCount Utility function to cat the ClaimShortId csv func TestGetRepostedClaim(t *testing.T) {
channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd")
want := 5
// Should be non-existent
channelHash2, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bf")
filePath := "../testdata/W_resolve.csv"
db, _, toDefer, err := OpenAndFillTmpDBColumnFamlies(filePath)
if err != nil {
t.Error(err)
}
defer toDefer()
count, err := dbpkg.GetRepostedCount(db, channelHash)
if err != nil {
t.Error(err)
}
log.Println(count)
if count != want {
t.Errorf("Expected %d, got %d", want, count)
}
count2, err := dbpkg.GetRepostedCount(db, channelHash2)
if err != nil {
t.Error(err)
}
if count2 != 0 {
t.Errorf("Expected 0, got %d", count2)
}
}
func TestPrintRepost(t *testing.T) {
filePath := "../testdata/V_resolve.csv"
CatCSV(filePath)
}
func TestGetRepost(t *testing.T) {
channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd")
channelHash2, _ := hex.DecodeString("000009ca6e0caaaef16872b4bd4f6f1b8c2363e2")
filePath := "../testdata/V_resolve.csv"
// want := uint32(3670)
db, _, toDefer, err := OpenAndFillTmpDBColumnFamlies(filePath)
if err != nil {
t.Error(err)
}
defer toDefer()
res, err := dbpkg.GetRepost(db, channelHash)
if err != nil {
t.Error(err)
}
if !bytes.Equal(res, []byte{}) {
t.Errorf("Expected empty, got %#v", res)
}
res2, err := dbpkg.GetRepost(db, channelHash2)
if err != nil {
t.Error(err)
}
if bytes.Equal(res2, []byte{}) {
t.Errorf("Expected non empty, got %#v", res2)
}
}
func TestPrintChannelCount(t *testing.T) { func TestPrintChannelCount(t *testing.T) {
filePath := "../testdata/Z_resolve.csv" filePath := "../testdata/Z_resolve.csv"
CatCSV(filePath) CatCSV(filePath)
@ -337,7 +403,6 @@ func TestGetClaimsInChannelCount(t *testing.T) {
} }
} }
// TestPrintClaimShortId Utility function to cat the ClaimShortId csv
func TestPrintClaimShortId(t *testing.T) { func TestPrintClaimShortId(t *testing.T) {
filePath := "../testdata/F_cat.csv" filePath := "../testdata/F_cat.csv"
CatCSV(filePath) CatCSV(filePath)
@ -413,6 +478,45 @@ func TestGetTXOToClaim(t *testing.T) {
} }
} }
func TestGetClaimToChannel(t *testing.T) {
streamHashStr := "9a0ed686ecdad9b6cb965c4d6681c02f0bbc66a6"
claimHashStr := "2556ed1cab9d17f2a9392030a9ad7f5d138f11bd"
claimHash, _ := hex.DecodeString(claimHashStr)
streamHash, _ := hex.DecodeString(streamHashStr)
txNum := uint32(0x6284e3)
position := uint16(0x0)
streamTxNum := uint32(0x369e2b2)
streamPosition := uint16(0x0)
var val []byte = nil
filePath := "../testdata/I_resolve.csv"
db, _, toDefer, err := OpenAndFillTmpDBColumnFamlies(filePath)
if err != nil {
t.Error(err)
}
defer toDefer()
val, err = dbpkg.GetChannelForClaim(db, claimHash, txNum, position)
if err != nil {
t.Error(err)
}
if val != nil {
t.Errorf("Expected nil, got %s", hex.EncodeToString(val))
}
val, err = dbpkg.GetChannelForClaim(db, streamHash, streamTxNum, streamPosition)
if err != nil {
t.Error(err)
}
valStr := hex.EncodeToString(val)
if valStr != claimHashStr {
t.Errorf("Expected %s, got %s", claimHashStr, valStr)
}
}
func TestGetEffectiveAmount(t *testing.T) { func TestGetEffectiveAmount(t *testing.T) {
filePath := "../testdata/S_resolve.csv" filePath := "../testdata/S_resolve.csv"
want := uint64(586370959900) want := uint64(586370959900)
@ -433,8 +537,6 @@ func TestGetEffectiveAmount(t *testing.T) {
if amount != want { if amount != want {
t.Errorf("Expected %d, got %d", want, amount) t.Errorf("Expected %d, got %d", want, amount)
} }
log.Println(amount)
} }
func TestGetSupportAmount(t *testing.T) { func TestGetSupportAmount(t *testing.T) {

View file

@ -111,17 +111,22 @@ func main() {
return return
} else if args.CmdType == server.DBCmd3 { } else if args.CmdType == server.DBCmd3 {
// streamHash, _ := hex.DecodeString("9a0ed686ecdad9b6cb965c4d6681c02f0bbc66a6")
channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd") channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd")
// name := util.NormalizeName("@Styxhexenhammer666") // name := util.NormalizeName("@Styxhexenhammer666")
// txNum := uint32(0x6284e3) // txNum := uint32(0x6284e3)
// position := uint16(0x0) // position := uint16(0x0)
// For stream claim
// txNum := uint32(0x369e2b2)
// position := uint16(0x0)
// typ := uint8(prefixes.ACTIVATED_CLAIM_TXO_TYPE) // typ := uint8(prefixes.ACTIVATED_CLAIM_TXO_TYPE)
var rawPrefix byte = prefixes.ActiveAmount var rawPrefix byte = prefixes.RepostedClaim
var startRaw []byte = nil var startRaw []byte = nil
prefix := []byte{rawPrefix} prefix := []byte{rawPrefix}
columnFamily := string(prefix) columnFamily := string(prefix)
// start := prefixes.NewClaimTakeoverKey(name) // start := prefixes.NewClaimTakeoverKey(name)
start := prefixes.NewActiveAmountKey(channelHash, prefixes.ACTIVATED_SUPPORT_TXO_TYPE, 0) // start := prefixes.NewActiveAmountKey(channelHash, prefixes.ACTIVATED_SUPPORT_TXO_TYPE, 0)
start := prefixes.NewRepostedKey(channelHash)
startRaw = start.PackKey() startRaw = start.PackKey()
// start := &prefixes.ChannelCountKey{ // start := &prefixes.ChannelCountKey{
// Prefix: prefix, // Prefix: prefix,

2
testdata/I_resolve.csv vendored Normal file
View file

@ -0,0 +1,2 @@
I,,
I,499a0ed686ecdad9b6cb965c4d6681c02f0bbc66a60369e2b20000,2556ed1cab9d17f2a9392030a9ad7f5d138f11bd
1 I
2 I 499a0ed686ecdad9b6cb965c4d6681c02f0bbc66a60369e2b20000 2556ed1cab9d17f2a9392030a9ad7f5d138f11bd

2
testdata/V_resolve.csv vendored Normal file
View file

@ -0,0 +1,2 @@
V,,
V,56000009ca6e0caaaef16872b4bd4f6f1b8c2363e2,dbdfb6cd5e83baf342eaab8b19662ed0c71aae9a
1 V
2 V 56000009ca6e0caaaef16872b4bd4f6f1b8c2363e2 dbdfb6cd5e83baf342eaab8b19662ed0c71aae9a

11
testdata/W_resolve.csv vendored Normal file
View file

@ -0,0 +1,11 @@
W,,
W,572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00812cb90000,fa3a1c918fafd094083240fd54a3c8577b7f1094
W,572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00812ce70000,1b845565203eca16cb6135e6fb70d4d2cec4ee9b
W,572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00812ce90000,c2bfc30ebdf2511a2a9a22b463f80d1f751ee38c
W,572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00812d3f0000,f9c6adebfb970aa9ab1cac21f82eb007b2421a20
W,572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00e7b0800000,a3cfb4a2a4b7efda98d5f680d6dbc30b4ebb328b
W,57255761310145baa958b5587d9b5571423e5a0d3c0208ba650000,2ae0dadba7d5931105ca2e5cb1c12ec61100b9b5
W,57255761310145baa958b5587d9b5571423e5a0d3c0208dc150000,a9389febb41d9a1c63deef395273b903caf4a18d
W,57255761310145baa958b5587d9b5571423e5a0d3c0208e3eb0000,68ab6c0cdd615540062b6f6d637f8b47ab0e615b
W,57255761310145baa958b5587d9b5571423e5a0d3c0208f7210000,3d8ee0471ae8751e016b62dca9cee5cfebc9b30d
W,57255761310145baa958b5587d9b5571423e5a0d3c02090a7b0000,0a059f3e94ed2c5a9d43986f0f14cf29f02d01ce
1 W
2 W 572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00812cb90000 fa3a1c918fafd094083240fd54a3c8577b7f1094
3 W 572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00812ce70000 1b845565203eca16cb6135e6fb70d4d2cec4ee9b
4 W 572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00812ce90000 c2bfc30ebdf2511a2a9a22b463f80d1f751ee38c
5 W 572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00812d3f0000 f9c6adebfb970aa9ab1cac21f82eb007b2421a20
6 W 572556ed1cab9d17f2a9392030a9ad7f5d138f11bd00e7b0800000 a3cfb4a2a4b7efda98d5f680d6dbc30b4ebb328b
7 W 57255761310145baa958b5587d9b5571423e5a0d3c0208ba650000 2ae0dadba7d5931105ca2e5cb1c12ec61100b9b5
8 W 57255761310145baa958b5587d9b5571423e5a0d3c0208dc150000 a9389febb41d9a1c63deef395273b903caf4a18d
9 W 57255761310145baa958b5587d9b5571423e5a0d3c0208e3eb0000 68ab6c0cdd615540062b6f6d637f8b47ab0e615b
10 W 57255761310145baa958b5587d9b5571423e5a0d3c0208f7210000 3d8ee0471ae8751e016b62dca9cee5cfebc9b30d
11 W 57255761310145baa958b5587d9b5571423e5a0d3c02090a7b0000 0a059f3e94ed2c5a9d43986f0f14cf29f02d01ce