11package v2_test
22
33import (
4+ "math/big"
45 "testing"
56 "time"
67
@@ -11,7 +12,6 @@ import (
1112
1213 "github.com/smartcontractkit/chainlink-evm/pkg/assets"
1314 "github.com/smartcontractkit/chainlink-evm/pkg/config/toml"
14- "github.com/smartcontractkit/chainlink-evm/pkg/types"
1515 "github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
1616 "github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
1717 "github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
@@ -27,38 +27,38 @@ func TestStartHeartbeats(t *testing.T) {
2727 vrfKey := cltest .MustGenerateRandomKey (t )
2828 sendEth (t , ownerKey , uni .backend , vrfKey .Address , 10 )
2929 gasLanePriceWei := assets .GWei (1 )
30- gasLimit := 3_000_000
30+ gasLimit := uint64 ( 3_000_000 )
3131
3232 consumers := uni .vrfConsumers
3333
3434 // generate n BHS keys to make sure BHS job rotates sending keys
35- var bhsKeyAddresses []string
36- var keySpecificOverrides []toml.KeySpecific
37- var keys []any
35+ bhsKeyAddresses := make ( []string , 0 , len ( consumers ))
36+ keySpecificOverrides := make ( []toml.KeySpecific , 0 , len ( consumers ) + 1 )
37+ keys := make ( []any , 0 , len ( consumers ) + 2 )
3838 for range consumers {
3939 bhsKey := cltest .MustGenerateRandomKey (t )
4040 bhsKeyAddresses = append (bhsKeyAddresses , bhsKey .Address .String ())
4141 keys = append (keys , bhsKey )
4242 keySpecificOverrides = append (keySpecificOverrides , toml.KeySpecific {
43- Key : ptr [types. EIP55Address ] (bhsKey .EIP55Address ),
43+ Key : new (bhsKey.EIP55Address ),
4444 GasEstimator : toml.KeySpecificGasEstimator {PriceMax : gasLanePriceWei },
4545 })
4646 sendEth (t , ownerKey , uni .backend , bhsKey .Address , 10 )
4747 }
4848 keySpecificOverrides = append (keySpecificOverrides , toml.KeySpecific {
4949 // Gas lane.
50- Key : ptr [types. EIP55Address ] (vrfKey .EIP55Address ),
50+ Key : new (vrfKey.EIP55Address ),
5151 GasEstimator : toml.KeySpecificGasEstimator {PriceMax : gasLanePriceWei },
5252 })
5353
5454 keys = append (keys , ownerKey , vrfKey )
5555
5656 config , _ := heavyweight .FullTestDBV2 (t , func (c * chainlink.Config , s * chainlink.Secrets ) {
5757 simulatedOverrides (t , gasLanePriceWei , keySpecificOverrides ... )(c , s )
58- c .EVM [0 ].MinIncomingConfirmations = ptr [ uint32 ]( 2 )
59- c .Feature .LogPoller = ptr (true )
60- c .EVM [0 ].FinalityDepth = ptr [ uint32 ]( 2 )
61- c .EVM [0 ].GasEstimator .LimitDefault = ptr ( uint64 ( gasLimit ) )
58+ c .EVM [0 ].MinIncomingConfirmations = new ( uint32 ( 2 ) )
59+ c .Feature .LogPoller = new (true )
60+ c .EVM [0 ].FinalityDepth = new ( uint32 ( 2 ) )
61+ c .EVM [0 ].GasEstimator .LimitDefault = new ( gasLimit )
6262 c .EVM [0 ].LogPollInterval = commonconfig .MustNewDuration (time .Second )
6363 })
6464
@@ -86,11 +86,18 @@ func TestStartHeartbeats(t *testing.T) {
8686 diff := heartbeatPeriod + 1 * time .Second
8787 t .Logf ("Sleeping %.2f seconds before checking blockhash in BHS added by BHS_Heartbeats_Service\n " , diff .Seconds ())
8888 time .Sleep (diff )
89- // storeEarliest in BHS contract stores blocktip - 256 in the Blockhash Store (BHS)
90- tipHeader , err := uni .backend .Client ().HeaderByNumber (testutils .Context (t ), nil )
91- require .NoError (t , err )
92- // the storeEarliest transaction will end up in a new block, hence the + 1 below.
93- blockNumberStored := tipHeader .Number .Uint64 () - 256 + 1
94- verifyBlockhashStored (t , uni .coordinatorV2UniverseCommon , blockNumberStored )
89+ // The heartbeat store tx may not reach the mempool before the first
90+ // Commit under load, so we can't predict which block it mines in.
91+ // Commit blocks and check current_tip-256 on each attempt until BHS
92+ // has a blockhash stored at that offset.
93+ require .Eventually (t , func () bool {
94+ uni .backend .Commit ()
95+ tip , tipErr := uni .backend .Client ().HeaderByNumber (testutils .Context (t ), nil )
96+ if tipErr != nil || tip == nil || tip .Number .Uint64 () < 256 {
97+ return false
98+ }
99+ _ , err := uni .bhsContract .GetBlockhash (nil , new (big.Int ).SetUint64 (tip .Number .Uint64 ()- 256 ))
100+ return err == nil
101+ }, testutils .WaitTimeoutCustom (t , 5 * time .Minute ), time .Second )
95102 })
96103}
0 commit comments