Skip to content

Commit a56edc9

Browse files
committed
Instrumented the test to allow generation of data
1 parent 7bd1658 commit a56edc9

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

node/average.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"github.com/pegnet/pegnetd/fat/fat2"
77
)
88

9-
const AveragePeriod = uint64(288) // Our Average Period is 2 days (144 10 minute blocks per day)
10-
const AverageRequired = AveragePeriod / 2 // If we have at least half the rates, we can do conversions
9+
var AveragePeriod = uint64(288) // Our Average Period is 2 days (144 10 minute blocks per day)
10+
var AverageRequired = AveragePeriod / 2 // If we have at least half the rates, we can do conversions
1111

1212
// getPegNetRateAverages
1313
// Gets all the rates for the AveragePeriod (the number of blocks contributing to the average), and computes

node/average_test.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"os"
77
"testing"
88

9+
"github.com/pegnet/pegnetd/node/conversions"
10+
911
"github.com/pegnet/pegnetd/config"
1012

1113
"github.com/pegnet/pegnetd/fat/fat2"
@@ -16,15 +18,15 @@ import (
1618

1719
func TestAveragePeriod(t *testing.T) {
1820

19-
t.Skip("Should not be run as part of automated tests")
21+
//t.Skip("Should not be run as part of automated tests")
2022

2123
ctx, cancel := context.WithCancel(context.Background())
2224
exit.GlobalExitHandler.AddCancel(cancel)
2325
_ = ctx
2426

2527
// Open a file to write values that can be pulled into a spreadsheet and plotted.
26-
//fctDat, _ := os.Create("FCT.tsv")
27-
//defer fctDat.Close()
28+
fctDat, _ := os.Create("FCT.tsv")
29+
defer fctDat.Close()
2830

2931
// Get the config
3032
conf := viper.GetViper()
@@ -39,7 +41,7 @@ func TestAveragePeriod(t *testing.T) {
3941
t.Fatal(err)
4042
}
4143
// Min 206422 293471
42-
for i := uint32(208500); i < 210500; i++ {
44+
for i := uint32(208500); i < 209500; i++ {
4345

4446
averages := n.GetPegNetRateAverages(ctx, i).(map[fat2.PTicker]uint64)
4547
_ = averages
@@ -50,10 +52,29 @@ func TestAveragePeriod(t *testing.T) {
5052

5153
// Write out a tab delineated file to plot to double check the averages against the values
5254
//
53-
// // Get the rate for FCT at the current height
54-
// price := n.LastAveragesData[fat2.PTickerFCT][len(n.LastAveragesData[fat2.PTickerFCT])-1]
55-
// avgPrice := averages[fat2.PTickerFCT]
56-
// fctDat.WriteString(fmt.Sprintf("%f\t%f\n", float64(price)/100000000, float64(avgPrice)/100000000))
55+
// Get the rate for FCT at the current height
56+
ufp := func(x uint64) float64 { return float64(x) / 100000000 }
57+
fp := func(x int64) float64 { return float64(x) / 100000000 }
58+
FCTprice := n.LastAveragesData[fat2.PTickerFCT][len(n.LastAveragesData[fat2.PTickerFCT])-1]
59+
FCTavgPrice := averages[fat2.PTickerFCT]
60+
BTCprice := n.LastAveragesData[fat2.PTickerXBT][len(n.LastAveragesData[fat2.PTickerXBT])-1]
61+
BTCavgPrice := averages[fat2.PTickerXBT]
62+
63+
AveragePeriod = 144 * 4
64+
AverageRequired = AveragePeriod / 2
65+
66+
config.PIP10AverageActivation = i + 1
67+
convert1, err := conversions.Convert(i, 100000000000, FCTprice, FCTavgPrice, BTCprice, BTCavgPrice)
68+
if err != nil {
69+
t.Fatal("should not fail")
70+
}
71+
config.PIP10AverageActivation = i
72+
convert2, err := conversions.Convert(i, 100000000000, FCTprice, FCTavgPrice, BTCprice, BTCavgPrice)
73+
if err != nil {
74+
t.Fatal("should not fail")
75+
}
76+
fctDat.WriteString(fmt.Sprintf("%f\t%f\t%f\t%f\t%f\t%f\n",
77+
ufp(FCTprice), ufp(FCTavgPrice), ufp(BTCprice), ufp(BTCavgPrice), fp(convert1), fp(convert2)))
5778

5879
if i%10000 == 0 {
5980
fmt.Printf("%6d ", i)

0 commit comments

Comments
 (0)