github.com/lmittmann/w3@v0.20.0/module/eth/uncle_test.go (about)

     1  package eth_test
     2  
     3  import (
     4  	"errors"
     5  	"math/big"
     6  	"testing"
     7  
     8  	"github.com/ethereum/go-ethereum/core/types"
     9  	"github.com/lmittmann/w3"
    10  	"github.com/lmittmann/w3/module/eth"
    11  	"github.com/lmittmann/w3/rpctest"
    12  )
    13  
    14  var header15050036 = &types.Header{
    15  	BaseFee:     big.NewInt(0xa688e9452),
    16  	Difficulty:  big.NewInt(0x3252ebd268b855),
    17  	Extra:       w3.B("0x466c6578706f6f6c2f53302f484b202d20546f726f6e746f"),
    18  	GasLimit:    0x1c9c380,
    19  	GasUsed:     0x47d8e7,
    20  	Bloom:       blockBloom(w3.B("0x08200144090018000030b040821105200400800000148002000106861402e08111400008080b0420124248000008c1441a1110002a00361080c00010053a202124420000000020286900003ff080402082e6000804459404b28029019201102a1300f000020ac02082820580182028402115c420e030040288000030082a40129210210500030010005c0000020020040c10408529221058c0002040401028059a800123802664080ac0428105350210010402004010004330280204000b8840111500020400003828080000a000604108004260000900107400192a000920048114354818318008000016804104181020a210280068044000480a01020a6083")),
    21  	Coinbase:    w3.A("0x7F101fE45e6649A6fB8F3F8B43ed03D353f2B90c"),
    22  	MixDigest:   w3.H("0x99cabdd1355726d424faa49bf83b1820d456bb0f7d5fe83d53cff777294b4fe4"),
    23  	Nonce:       blockNonce(w3.B("0xfbe8b3c8c41a4459")),
    24  	Root:        w3.H("0x4143920b2a110d8956ab2edd3f6be5042c6c25a62e79d94863bd54e0e54f38da"),
    25  	ReceiptHash: w3.H("0x8bf939b3ced21c57210ef6935ed9add6803c696adab0c2be1c54e2239c674ffe"),
    26  	Number:      big.NewInt(0xe5a533),
    27  	ParentHash:  w3.H("0x8fb655702f8f86f047e9acc49842efee36f96a1ddf620d0f4ee312723f4908f7"),
    28  	TxHash:      w3.H("0xb57bedbc9fa725a7a765bc833ee3b1e946816960780693415e144bf78a9f0a95"),
    29  	UncleHash:   w3.H("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"),
    30  	Time:        0x62bd8341,
    31  }
    32  
    33  func blockNonce(data []byte) (nonce types.BlockNonce) {
    34  	copy(nonce[:], data[:])
    35  	return
    36  }
    37  
    38  func blockBloom(data []byte) (bloom types.Bloom) {
    39  	copy(bloom[:], data[:])
    40  	return
    41  }
    42  
    43  func TestUncleByBlockHashAndIndex(t *testing.T) {
    44  	rpctest.RunTestCases(t, []rpctest.TestCase[*types.Header]{
    45  		{
    46  			Golden:  "uncle_by_hash_and_index__15050036",
    47  			Call:    eth.UncleByBlockHashAndIndex(w3.H("0x7a98a492c1288a8451905bc665cb28d45fbdf8913c34d4ad756acb0609342e67"), 0),
    48  			WantRet: header15050036,
    49  		},
    50  		{
    51  			Golden:  "uncle_by_hash_and_index__15050036_1",
    52  			Call:    eth.UncleByBlockHashAndIndex(w3.H("0x7a98a492c1288a8451905bc665cb28d45fbdf8913c34d4ad756acb0609342e67"), 1),
    53  			WantErr: errors.New("w3: call failed: not found"),
    54  		},
    55  	})
    56  }
    57  
    58  func TestUncleByBlockNumberAndIndex(t *testing.T) {
    59  	rpctest.RunTestCases(t, []rpctest.TestCase[*types.Header]{
    60  		{
    61  			Golden:  "uncle_by_number_and_index__15050036",
    62  			Call:    eth.UncleByBlockNumberAndIndex(big.NewInt(15050036), 0),
    63  			WantRet: header15050036,
    64  		},
    65  	})
    66  }
    67  
    68  func TestUncleCountByBlockHash(t *testing.T) {
    69  	rpctest.RunTestCases(t, []rpctest.TestCase[uint]{
    70  		{
    71  			Golden:  "uncle_count_by_hash__15050036",
    72  			Call:    eth.UncleCountByBlockHash(w3.H("0x7a98a492c1288a8451905bc665cb28d45fbdf8913c34d4ad756acb0609342e67")),
    73  			WantRet: 1,
    74  		},
    75  	})
    76  }
    77  
    78  func TestUncleCountByBlockNumber(t *testing.T) {
    79  	rpctest.RunTestCases(t, []rpctest.TestCase[uint]{
    80  		{
    81  			Golden:  "uncle_count_by_number__15050036",
    82  			Call:    eth.UncleCountByBlockNumber(big.NewInt(15050036)),
    83  			WantRet: 1,
    84  		},
    85  	})
    86  }