@@ -18,7 +18,7 @@ import (
1818
1919func TestAveragePeriod (t * testing.T ) {
2020
21- // t.Skip("Should not be run as part of automated tests")
21+ t .Skip ("Should not be run as part of automated tests" )
2222
2323 ctx , cancel := context .WithCancel (context .Background ())
2424 exit .GlobalExitHandler .AddCancel (cancel )
@@ -85,3 +85,73 @@ func TestAveragePeriod(t *testing.T) {
8585 }
8686 }
8787}
88+
89+ func TestAveragePeriodBTC2FCT (t * testing.T ) {
90+
91+ t .Skip ("Should not be run as part of automated tests" )
92+
93+ ctx , cancel := context .WithCancel (context .Background ())
94+ exit .GlobalExitHandler .AddCancel (cancel )
95+ _ = ctx
96+
97+ // Open a file to write values that can be pulled into a spreadsheet and plotted.
98+ fctDat , _ := os .Create ("FCT.tsv" )
99+ defer fctDat .Close ()
100+
101+ // Get the config
102+ conf := viper .GetViper ()
103+ conf .Set (config .Network , "MainNet" )
104+ conf .SetConfigName ("pegnetd-conf" )
105+ conf .Set (config .SqliteDBPath , "$HOME/.pegnetd/mainnet/sql.db" )
106+ configpath := os .ExpandEnv ("$HOME/.pegnetd/pegnetd-conf.toml" )
107+ conf .SetConfigFile (os .ExpandEnv (configpath ))
108+
109+ n , err := NewPegnetd (ctx , conf )
110+ if err != nil {
111+ t .Fatal (err )
112+ }
113+ // Min 206422 293471
114+ for i := uint32 (207500 ); i < 211500 ; i ++ {
115+
116+ averages := n .GetPegNetRateAverages (ctx , i ).(map [fat2.PTicker ]uint64 )
117+ _ = averages
118+
119+ for pAsset , v := range averages {
120+ fmt .Sprintf ("%6s %15d" , pAsset , v )
121+ }
122+
123+ // Write out a tab delineated file to plot to double check the averages against the values
124+ //
125+ // Get the rate for FCT at the current height
126+ ufp := func (x uint64 ) float64 { return float64 (x ) / 100000000 }
127+ fp := func (x int64 ) float64 { return float64 (x ) / 100000000 }
128+ FCTprice := n .LastAveragesData [fat2 .PTickerFCT ][len (n .LastAveragesData [fat2 .PTickerFCT ])- 1 ]
129+ FCTavgPrice := averages [fat2 .PTickerFCT ]
130+ BTCprice := n .LastAveragesData [fat2 .PTickerXBT ][len (n .LastAveragesData [fat2 .PTickerXBT ])- 1 ]
131+ BTCavgPrice := averages [fat2 .PTickerXBT ]
132+
133+ AveragePeriod = 144 * 1
134+ AverageRequired = AveragePeriod / 2
135+
136+ config .PIP10AverageActivation = i + 1
137+ convert1 , err := conversions .Convert (i , 100000000000 , BTCprice , BTCavgPrice , FCTprice , FCTavgPrice )
138+ if err != nil {
139+ t .Fatal ("should not fail" )
140+ }
141+ config .PIP10AverageActivation = i
142+ convert2 , err := conversions .Convert (i , 100000000000 , BTCprice , BTCavgPrice , FCTprice , FCTavgPrice )
143+ if err != nil {
144+ t .Fatal ("should not fail" )
145+ }
146+ fctDat .WriteString (fmt .Sprintf ("%f\t %f\t %f\t %f\t %f\t %f\n " ,
147+ ufp (FCTprice ), ufp (FCTavgPrice ), ufp (BTCprice ), ufp (BTCavgPrice ), fp (convert1 ), fp (convert2 )))
148+
149+ if i % 10000 == 0 {
150+ fmt .Printf ("%6d " , i )
151+ println ()
152+ if i == 206709 {
153+ println ()
154+ }
155+ }
156+ }
157+ }
0 commit comments