Export constant, add test
This commit is contained in:
parent
78715bc128
commit
8d1135189d
4 changed files with 64 additions and 19 deletions
28
db/db.go
28
db/db.go
|
@ -22,16 +22,16 @@ import (
|
|||
//
|
||||
|
||||
const (
|
||||
nOriginalClaimExpirationTime = 262974
|
||||
nExtendedClaimExpirationTime = 2102400
|
||||
nExtendedClaimExpirationForkHeight = 400155
|
||||
nNormalizedNameForkHeight = 539940 // targeting 21 March 2019
|
||||
nMinTakeoverWorkaroundHeight = 496850
|
||||
nMaxTakeoverWorkaroundHeight = 658300 // targeting 30 Oct 2019
|
||||
nWitnessForkHeight = 680770 // targeting 11 Dec 2019
|
||||
nAllClaimsInMerkleForkHeight = 658310 // targeting 30 Oct 2019
|
||||
proportionalDelayFactor = 32
|
||||
maxTakeoverDelay = 4032
|
||||
NOriginalClaimExpirationTime = 262974
|
||||
NExtendedClaimExpirationTime = 2102400
|
||||
NExtendedClaimExpirationForkHeight = 400155
|
||||
NNormalizedNameForkHeight = 539940 // targeting 21 March 2019
|
||||
NMinTakeoverWorkaroundHeight = 496850
|
||||
NMaxTakeoverWorkaroundHeight = 658300 // targeting 30 Oct 2019
|
||||
NWitnessForkHeight = 680770 // targeting 11 Dec 2019
|
||||
NAllClaimsInMerkleForkHeight = 658310 // targeting 30 Oct 2019
|
||||
ProportionalDelayFactor = 32
|
||||
MaxTakeoverDelay = 4032
|
||||
)
|
||||
|
||||
//
|
||||
|
@ -231,12 +231,12 @@ func GetExpirationHeight(lastUpdatedHeight uint32) uint32 {
|
|||
|
||||
func GetExpirationHeightFull(lastUpdatedHeight uint32, extended bool) uint32 {
|
||||
if extended {
|
||||
return lastUpdatedHeight + nExtendedClaimExpirationTime
|
||||
return lastUpdatedHeight + NExtendedClaimExpirationTime
|
||||
}
|
||||
if lastUpdatedHeight < nExtendedClaimExpirationForkHeight {
|
||||
return lastUpdatedHeight + nOriginalClaimExpirationTime
|
||||
if lastUpdatedHeight < NExtendedClaimExpirationForkHeight {
|
||||
return lastUpdatedHeight + NOriginalClaimExpirationTime
|
||||
}
|
||||
return lastUpdatedHeight + nExtendedClaimExpirationTime
|
||||
return lastUpdatedHeight + NExtendedClaimExpirationTime
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -413,6 +413,48 @@ func TestGetTXOToClaim(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetExpirationHeight(t *testing.T) {
|
||||
var lastUpdated uint32 = 0
|
||||
var expHeight uint32 = 0
|
||||
|
||||
expHeight = dbpkg.GetExpirationHeight(lastUpdated)
|
||||
if lastUpdated+dbpkg.NOriginalClaimExpirationTime != expHeight {
|
||||
t.Errorf("Expected %d, got %d", lastUpdated+dbpkg.NOriginalClaimExpirationTime, expHeight)
|
||||
}
|
||||
|
||||
lastUpdated = dbpkg.NExtendedClaimExpirationForkHeight + 1
|
||||
expHeight = dbpkg.GetExpirationHeight(lastUpdated)
|
||||
if lastUpdated+dbpkg.NExtendedClaimExpirationTime != expHeight {
|
||||
t.Errorf("Expected %d, got %d", lastUpdated+dbpkg.NExtendedClaimExpirationTime, expHeight)
|
||||
}
|
||||
|
||||
lastUpdated = 0
|
||||
expHeight = dbpkg.GetExpirationHeightFull(lastUpdated, true)
|
||||
if lastUpdated+dbpkg.NExtendedClaimExpirationTime != expHeight {
|
||||
t.Errorf("Expected %d, got %d", lastUpdated+dbpkg.NExtendedClaimExpirationTime, expHeight)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetActivation(t *testing.T) {
|
||||
filePath := "../testdata/R_resolve.csv"
|
||||
txNum := uint32(0x6284e3)
|
||||
position := uint16(0x0)
|
||||
want := uint32(0xa6b65)
|
||||
db, _, toDefer, err := OpenAndFillTmpDBColumnFamlies(filePath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer toDefer()
|
||||
activation, err := dbpkg.GetActivation(db, txNum, position)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if activation != want {
|
||||
t.Errorf("Expected %d, got %d", want, activation)
|
||||
}
|
||||
log.Printf("activation: %#v\n", activation)
|
||||
}
|
||||
|
||||
// TestPrintClaimToTXO Utility function to cat the ClaimToTXO csv.
|
||||
func TestPrintClaimToTXO(t *testing.T) {
|
||||
filePath := "../testdata/E_resolve.csv"
|
||||
|
|
11
main.go
11
main.go
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -111,15 +110,17 @@ func main() {
|
|||
|
||||
return
|
||||
} else if args.CmdType == server.DBCmd3 {
|
||||
channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd")
|
||||
// channelHash, _ := hex.DecodeString("2556ed1cab9d17f2a9392030a9ad7f5d138f11bd")
|
||||
// name := util.NormalizeName("@Styxhexenhammer666")
|
||||
var rawPrefix byte = prefixes.ClaimToTXO
|
||||
txNum := uint32(0x6284e3)
|
||||
position := uint16(0x0)
|
||||
typ := uint8(prefixes.ACTIVATED_CLAIM_TXO_TYPE)
|
||||
var rawPrefix byte = prefixes.ActivatedClaimAndSupport
|
||||
var startRaw []byte = nil
|
||||
prefix := []byte{rawPrefix}
|
||||
columnFamily := string(prefix)
|
||||
// start := prefixes.NewClaimTakeoverKey(name)
|
||||
start := prefixes.NewClaimToTXOKey(channelHash)
|
||||
|
||||
start := prefixes.NewActivationKey(typ, txNum, position)
|
||||
startRaw = start.PackKey()
|
||||
// start := &prefixes.ChannelCountKey{
|
||||
// Prefix: prefix,
|
||||
|
|
2
testdata/R_resolve.csv
vendored
Normal file
2
testdata/R_resolve.csv
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
R,,
|
||||
R,5201006284e30000,000a6b652556ed1cab9d17f2a9392030a9ad7f5d138f11bd00134073747978686578656e68616d6d6572363636
|
|
Loading…
Reference in a new issue