@@ -20,7 +20,6 @@ import (
2020 inittypes "github.com/filecoin-project/go-state-types/builtin/v8/init"
2121 "github.com/filecoin-project/go-state-types/exitcode"
2222
23- "github.com/filecoin-project/lotus/build"
2423 "github.com/filecoin-project/lotus/build/buildconstants"
2524 "github.com/filecoin-project/lotus/chain/actors/policy"
2625 "github.com/filecoin-project/lotus/chain/types"
@@ -401,43 +400,38 @@ func TestEthBlockNumberAliases(t *testing.T) {
401400 ens .InterconnectAll ().BeginMining (blockTime )
402401 ens .Start ()
403402
404- build .Clock .Sleep (time .Second )
405-
406403 ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
407404 defer cancel ()
408405
409- head := client .WaitTillChain (ctx , kit .HeightAtLeast (policy .ChainFinality + 100 ))
410- // latest should be head-1 (parents)
411- var latestEthBlk ethtypes.EthBlock
412- for {
413- var err error
414- latestEthBlk , err = client .EVM ().EthGetBlockByNumber (ctx , "latest" , true )
415- require .NoError (t , err )
416- afterHead , err := client .ChainHead (ctx )
417- require .NoError (t , err )
418- if afterHead .Height () == head .Height () {
419- break
420- }
421- // else: whoops, we had a chain increment between getting head and getting "latest" so they're
422- // clearly not going to match, try again
423- head = afterHead
406+ client .WaitTillChain (ctx , kit .HeightAtLeast (policy .ChainFinality + 100 ))
407+
408+ for _ , tc := range []struct {
409+ param string
410+ expectedLag abi.ChainEpoch
411+ }{
412+ {"latest" , 1 }, // head - 1
413+ {"safe" , 30 + 1 }, // "latest" - 30
414+ {"finalized" , policy .ChainFinality + 1 }, // "latest" - 900
415+ } {
416+ t .Run (tc .param , func (t * testing.T ) {
417+ head , err := client .ChainHead (ctx )
418+ require .NoError (t , err )
419+ var blk ethtypes.EthBlock
420+ for { // get a block while retaining a stable "head" reference
421+ blk , err = client .EVM ().EthGetBlockByNumber (ctx , tc .param , true )
422+ require .NoError (t , err )
423+ afterHead , err := client .ChainHead (ctx )
424+ require .NoError (t , err )
425+ if afterHead .Height () == head .Height () {
426+ break
427+ }
428+ // else: whoops, we had a chain increment between getting head and getting "latest" so
429+ // we won't be able to use head as a stable reference for comparison
430+ head = afterHead
431+ }
432+ ts , err := client .ChainGetTipSetByHeight (ctx , head .Height ()- tc .expectedLag , head .Key ())
433+ require .NoError (t , err )
434+ require .EqualValues (t , ts .Height (), blk .Number )
435+ })
424436 }
425-
426- diff := int64 (latestEthBlk .Number ) - int64 (head .Height ()- 1 )
427- require .GreaterOrEqual (t , diff , int64 (0 ))
428- require .LessOrEqual (t , diff , int64 (2 ))
429-
430- // safe should be latest-30
431- safeEthBlk , err := client .EVM ().EthGetBlockByNumber (ctx , "safe" , true )
432- require .NoError (t , err )
433- diff = int64 (latestEthBlk .Number - 30 ) - int64 (safeEthBlk .Number )
434- require .GreaterOrEqual (t , diff , int64 (0 ))
435- require .LessOrEqual (t , diff , int64 (2 ))
436-
437- // finalized should be Finality blocks behind latest
438- finalityEthBlk , err := client .EVM ().EthGetBlockByNumber (ctx , "finalized" , true )
439- require .NoError (t , err )
440- diff = int64 (latestEthBlk .Number ) - int64 (policy .ChainFinality ) - int64 (finalityEthBlk .Number )
441- require .GreaterOrEqual (t , diff , int64 (0 ))
442- require .LessOrEqual (t , diff , int64 (2 ))
443437}
0 commit comments