@@ -11,6 +11,12 @@ import (
1111
1212 "github.com/ethereum/go-ethereum/common/hexutil"
1313 "github.com/stretchr/testify/assert"
14+ "github.com/stretchr/testify/require"
15+ "github.com/vechain/thor/v2/genesis"
16+ "github.com/vechain/thor/v2/test/datagen"
17+ "github.com/vechain/thor/v2/test/testchain"
18+ "github.com/vechain/thor/v2/thor"
19+ "github.com/vechain/thor/v2/tx"
1420)
1521
1622func TestCalculateRewards (t * testing.T ) {
@@ -113,3 +119,89 @@ func TestCalculateRewards(t *testing.T) {
113119 })
114120 }
115121}
122+
123+ func TestRewardsBeforeAndAfterGalactica (t * testing.T ) {
124+ forkConfig := thor .NoFork
125+ forkConfig .GALACTICA = 2
126+
127+ thorChain , err := testchain .NewWithFork (& forkConfig )
128+ assert .NoError (t , err )
129+
130+ addr := thor .BytesToAddress ([]byte ("to" ))
131+ cla := tx .NewClause (& addr ).WithValue (big .NewInt (10000 ))
132+
133+ trx1 := tx .NewBuilder (tx .TypeLegacy ).
134+ ChainTag (thorChain .Repo ().ChainTag ()).
135+ GasPriceCoef (100 ).
136+ Expiration (720 ).
137+ Gas (21000 ).
138+ Nonce (datagen .RandUint64 ()).
139+ Clause (cla ).
140+ BlockRef (tx .NewBlockRef (0 )).
141+ Build ()
142+ trx2 := tx .NewBuilder (tx .TypeLegacy ).
143+ ChainTag (thorChain .Repo ().ChainTag ()).
144+ GasPriceCoef (0 ).
145+ Expiration (720 ).
146+ Gas (21000 ).
147+ Nonce (datagen .RandUint64 ()).
148+ Clause (cla ).
149+ BlockRef (tx .NewBlockRef (0 )).
150+ Build ()
151+ assert .NoError (t ,
152+ thorChain .MintBlock (
153+ genesis .DevAccounts ()[0 ],
154+ tx .MustSign (trx1 , genesis .DevAccounts ()[0 ].PrivateKey ),
155+ tx .MustSign (trx2 , genesis .DevAccounts ()[0 ].PrivateKey ),
156+ ),
157+ )
158+
159+ trx3 := tx .NewBuilder (tx .TypeLegacy ).
160+ ChainTag (thorChain .Repo ().ChainTag ()).
161+ GasPriceCoef (10 ).
162+ Expiration (720 ).
163+ Gas (21000 ).
164+ Nonce (datagen .RandUint64 ()).
165+ Clause (cla ).
166+ BlockRef (tx .NewBlockRef (0 )).
167+ Build ()
168+ assert .NoError (t , thorChain .MintBlock (genesis .DevAccounts ()[0 ], tx .MustSign (trx3 , genesis .DevAccounts ()[0 ].PrivateKey )))
169+
170+ feesData := newFeesData (thorChain .Repo (), thorChain .Stater (), 10 )
171+
172+ bestBlockSummary := thorChain .Repo ().BestBlockSummary ()
173+
174+ blockCount := 2
175+ oldestBlockID , baseFees , gasUsedRatios , rewards , err := feesData .resolveRange (bestBlockSummary , uint32 (blockCount ), []float64 {25 , 50 , 75 })
176+ assert .NoError (t , err )
177+ assert .NotNil (t , oldestBlockID )
178+ assert .Len (t , baseFees , blockCount )
179+ assert .Len (t , gasUsedRatios , blockCount )
180+ assert .Len (t , rewards , blockCount )
181+
182+ // Before GALACTICA
183+ assert .NotNil (t , baseFees [0 ])
184+ assert .Equal (t , baseFees [0 ], (* hexutil .Big )(big .NewInt (0 )))
185+
186+ assert .NotNil (t , rewards [0 ])
187+ assert .Len (t , rewards [0 ], 3 )
188+ for _ , reward := range rewards [0 ] {
189+ assert .NotNil (t , reward )
190+ assert .True (t , big .NewInt (0 ).Cmp ((* big .Int )(reward )) == 0 )
191+ }
192+
193+ // After GALACTICA
194+ assert .NotNil (t , baseFees [1 ])
195+ assert .Equal (t , baseFees [1 ], (* hexutil .Big )(big .NewInt (thor .InitialBaseFee )))
196+
197+ assert .NotNil (t , rewards [1 ])
198+ assert .Len (t , rewards [1 ], 3 )
199+
200+ expectedReward , ok := new (big.Int ).SetString ("1029215686274509" , 10 )
201+ require .True (t , ok , "failed to parse expected reward" )
202+
203+ for _ , reward := range rewards [1 ] {
204+ assert .NotNil (t , reward )
205+ assert .True (t , expectedReward .Cmp ((* big .Int )(reward )) == 0 )
206+ }
207+ }
0 commit comments