From c73c078c264495d232d207a94347e9e7b86cfcb4 Mon Sep 17 00:00:00 2001 From: Jeffrey Picard Date: Tue, 22 Feb 2022 12:12:19 -0500 Subject: [PATCH] another test --- db/db_test.go | 32 ++++++++++++++++++++++++++++++++ main.go | 13 +++++++------ testdata/a_resolve.csv | 2 ++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 testdata/a_resolve.csv diff --git a/db/db_test.go b/db/db_test.go index 9fe2a21..7009ba9 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -413,6 +413,38 @@ func TestGetTXOToClaim(t *testing.T) { } } +// TestPrintClaimToTXO Utility function to cat the ClaimToTXO csv. +func TestPrintSupportAmount(t *testing.T) { + filePath := "../testdata/a_resolve.csv" + CatCSV(filePath) +} + +// TestGetClaimToTXO Tests getting a ClaimToTXO value from the db. +func TestGetSupportAmount(t *testing.T) { + claimHashStr := "2556ed1cab9d17f2a9392030a9ad7f5d138f11bd" + want := uint64(8654754160700) + claimHash, err := hex.DecodeString(claimHashStr) + if err != nil { + t.Error(err) + return + } + filePath := "../testdata/a_resolve.csv" + db, _, toDefer, err := OpenAndFillTmpDBColumnFamlies(filePath) + if err != nil { + t.Error(err) + return + } + defer toDefer() + res, err := dbpkg.GetSupportAmount(db, claimHash) + if err != nil { + t.Error(err) + return + } + if res != want { + t.Errorf("Expected %d, got %d", want, res) + } +} + func TestGetExpirationHeight(t *testing.T) { var lastUpdated uint32 = 0 var expHeight uint32 = 0 diff --git a/main.go b/main.go index d5eb36c..a89c6e9 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "encoding/hex" "fmt" "log" "os" @@ -110,17 +111,17 @@ func main() { return } else if args.CmdType == server.DBCmd3 { - // channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd") + channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd") // name := util.NormalizeName("@Styxhexenhammer666") - txNum := uint32(0x6284e3) - position := uint16(0x0) - typ := uint8(prefixes.ACTIVATED_CLAIM_TXO_TYPE) - var rawPrefix byte = prefixes.ActivatedClaimAndSupport + // txNum := uint32(0x6284e3) + // position := uint16(0x0) + // typ := uint8(prefixes.ACTIVATED_CLAIM_TXO_TYPE) + var rawPrefix byte = prefixes.SupportAmount var startRaw []byte = nil prefix := []byte{rawPrefix} columnFamily := string(prefix) // start := prefixes.NewClaimTakeoverKey(name) - start := prefixes.NewActivationKey(typ, txNum, position) + start := prefixes.NewSupportAmountKey(channelHash) startRaw = start.PackKey() // start := &prefixes.ChannelCountKey{ // Prefix: prefix, diff --git a/testdata/a_resolve.csv b/testdata/a_resolve.csv new file mode 100644 index 0000000..d5c12c6 --- /dev/null +++ b/testdata/a_resolve.csv @@ -0,0 +1,2 @@ +a,, +a,612556ed1cab9d17f2a9392030a9ad7f5d138f11bd,000007df178c203c