Skip to content

Commit

Permalink
Instrumented the test to allow generation of data
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSnow committed Apr 22, 2021
1 parent 7bd1658 commit a56edc9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions node/average.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/pegnet/pegnetd/fat/fat2"
)

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

// getPegNetRateAverages
// Gets all the rates for the AveragePeriod (the number of blocks contributing to the average), and computes
Expand Down
37 changes: 29 additions & 8 deletions node/average_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"testing"

"github.com/pegnet/pegnetd/node/conversions"

"github.com/pegnet/pegnetd/config"

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

func TestAveragePeriod(t *testing.T) {

t.Skip("Should not be run as part of automated tests")
//t.Skip("Should not be run as part of automated tests")

ctx, cancel := context.WithCancel(context.Background())
exit.GlobalExitHandler.AddCancel(cancel)
_ = ctx

// Open a file to write values that can be pulled into a spreadsheet and plotted.
//fctDat, _ := os.Create("FCT.tsv")
//defer fctDat.Close()
fctDat, _ := os.Create("FCT.tsv")
defer fctDat.Close()

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

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

// Write out a tab delineated file to plot to double check the averages against the values
//
// // Get the rate for FCT at the current height
// price := n.LastAveragesData[fat2.PTickerFCT][len(n.LastAveragesData[fat2.PTickerFCT])-1]
// avgPrice := averages[fat2.PTickerFCT]
// fctDat.WriteString(fmt.Sprintf("%f\t%f\n", float64(price)/100000000, float64(avgPrice)/100000000))
// Get the rate for FCT at the current height
ufp := func(x uint64) float64 { return float64(x) / 100000000 }
fp := func(x int64) float64 { return float64(x) / 100000000 }
FCTprice := n.LastAveragesData[fat2.PTickerFCT][len(n.LastAveragesData[fat2.PTickerFCT])-1]
FCTavgPrice := averages[fat2.PTickerFCT]
BTCprice := n.LastAveragesData[fat2.PTickerXBT][len(n.LastAveragesData[fat2.PTickerXBT])-1]
BTCavgPrice := averages[fat2.PTickerXBT]

AveragePeriod = 144 * 4
AverageRequired = AveragePeriod / 2

config.PIP10AverageActivation = i + 1
convert1, err := conversions.Convert(i, 100000000000, FCTprice, FCTavgPrice, BTCprice, BTCavgPrice)
if err != nil {
t.Fatal("should not fail")
}
config.PIP10AverageActivation = i
convert2, err := conversions.Convert(i, 100000000000, FCTprice, FCTavgPrice, BTCprice, BTCavgPrice)
if err != nil {
t.Fatal("should not fail")
}
fctDat.WriteString(fmt.Sprintf("%f\t%f\t%f\t%f\t%f\t%f\n",
ufp(FCTprice), ufp(FCTavgPrice), ufp(BTCprice), ufp(BTCavgPrice), fp(convert1), fp(convert2)))

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

0 comments on commit a56edc9

Please sign in to comment.