From d96cfc66386ed1ed1245b22ee3a3a00278baa225 Mon Sep 17 00:00:00 2001 From: Jeffrey Picard Date: Wed, 23 Feb 2022 17:26:43 -0500 Subject: [PATCH] more tests --- db/db.go | 4 +- db/db_test.go | 112 +++++++++++++++++++++++++++++++++++++++-- main.go | 9 +++- testdata/I_resolve.csv | 2 + testdata/V_resolve.csv | 2 + testdata/W_resolve.csv | 11 ++++ 6 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 testdata/I_resolve.csv create mode 100644 testdata/V_resolve.csv create mode 100644 testdata/W_resolve.csv diff --git a/db/db.go b/db/db.go index f86709e..4d0a776 100644 --- a/db/db.go +++ b/db/db.go @@ -318,9 +318,9 @@ func GetRepostedCount(db *ReadOnlyDBColumnFamily, claimHash []byte) (int, error) key := prefixes.NewRepostedKey(claimHash) keyPrefix := prefixes.RepostedKeyPackPartial(key, 1) // Prefix and handle - options := NewIterateOptions().WithPrefix(prefix).WithCfHandle(handle) + options := NewIterateOptions().WithPrefix(keyPrefix).WithCfHandle(handle) // Start and stop bounds - options = options.WithStart(keyPrefix) + // options = options.WithStart(keyPrefix) // Don't include the key options = options.WithIncludeValue(false) diff --git a/db/db_test.go b/db/db_test.go index e565cc3..ff2a3c5 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -294,7 +294,6 @@ 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) @@ -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) { filePath := "../testdata/Z_resolve.csv" CatCSV(filePath) @@ -337,7 +403,6 @@ func TestGetClaimsInChannelCount(t *testing.T) { } } -// TestPrintClaimShortId Utility function to cat the ClaimShortId csv func TestPrintClaimShortId(t *testing.T) { filePath := "../testdata/F_cat.csv" 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) { filePath := "../testdata/S_resolve.csv" want := uint64(586370959900) @@ -433,8 +537,6 @@ func TestGetEffectiveAmount(t *testing.T) { if amount != want { t.Errorf("Expected %d, got %d", want, amount) } - - log.Println(amount) } func TestGetSupportAmount(t *testing.T) { diff --git a/main.go b/main.go index 202b37f..2e627e9 100644 --- a/main.go +++ b/main.go @@ -111,17 +111,22 @@ func main() { return } else if args.CmdType == server.DBCmd3 { + // streamHash, _ := hex.DecodeString("9a0ed686ecdad9b6cb965c4d6681c02f0bbc66a6") channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd") // name := util.NormalizeName("@Styxhexenhammer666") // txNum := uint32(0x6284e3) // position := uint16(0x0) + // For stream claim + // txNum := uint32(0x369e2b2) + // position := uint16(0x0) // typ := uint8(prefixes.ACTIVATED_CLAIM_TXO_TYPE) - var rawPrefix byte = prefixes.ActiveAmount + var rawPrefix byte = prefixes.RepostedClaim var startRaw []byte = nil prefix := []byte{rawPrefix} columnFamily := string(prefix) // 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() // start := &prefixes.ChannelCountKey{ // Prefix: prefix, diff --git a/testdata/I_resolve.csv b/testdata/I_resolve.csv new file mode 100644 index 0000000..46db000 --- /dev/null +++ b/testdata/I_resolve.csv @@ -0,0 +1,2 @@ +I,, +I,499a0ed686ecdad9b6cb965c4d6681c02f0bbc66a60369e2b20000,2556ed1cab9d17f2a9392030a9ad7f5d138f11bd diff --git a/testdata/V_resolve.csv b/testdata/V_resolve.csv new file mode 100644 index 0000000..0bf871f --- /dev/null +++ b/testdata/V_resolve.csv @@ -0,0 +1,2 @@ +V,, +V,56000009ca6e0caaaef16872b4bd4f6f1b8c2363e2,dbdfb6cd5e83baf342eaab8b19662ed0c71aae9a diff --git a/testdata/W_resolve.csv b/testdata/W_resolve.csv new file mode 100644 index 0000000..43e2c36 --- /dev/null +++ b/testdata/W_resolve.csv @@ -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