github.com/lmittmann/w3@v0.20.0/module/eth/get_logs_test.go (about) 1 package eth_test 2 3 import ( 4 "testing" 5 6 "github.com/ethereum/go-ethereum" 7 "github.com/ethereum/go-ethereum/common" 8 "github.com/ethereum/go-ethereum/core/types" 9 "github.com/google/go-cmp/cmp" 10 "github.com/lmittmann/w3" 11 "github.com/lmittmann/w3/module/eth" 12 "github.com/lmittmann/w3/rpctest" 13 ) 14 15 func TestLogs(t *testing.T) { 16 srv := rpctest.NewFileServer(t, "testdata/get_logs.golden") 17 defer srv.Close() 18 19 client := w3.MustDial(srv.URL()) 20 defer client.Close() 21 22 var ( 23 filterQuery = ethereum.FilterQuery{ 24 FromBlock: w3.I("10000000"), 25 ToBlock: w3.I("10010000"), 26 Topics: [][]common.Hash{{w3.H("0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9")}}, 27 } 28 29 logs []types.Log 30 wantLogs = []types.Log{ 31 { 32 Address: w3.A("0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"), 33 Topics: []common.Hash{ 34 w3.H("0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9"), 35 w3.H("0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"), 36 w3.H("0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"), 37 }, 38 Data: w3.B("0x000000000000000000000000b4e16d0168e52d35cacd2c6185b44281ec28c9dc0000000000000000000000000000000000000000000000000000000000000001"), 39 BlockNumber: 10008355, 40 TxHash: w3.H("0xd07cbde817318492092cc7a27b3064a69bd893c01cb593d6029683ffd290ab3a"), 41 TxIndex: 38, 42 BlockHash: w3.H("0x359d1dc4f14f9a07cba3ae8416958978ce98f78ad7b8d505925dad9722081f04"), 43 Index: 34, 44 }, 45 { 46 Address: w3.A("0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"), 47 Topics: []common.Hash{ 48 w3.H("0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9"), 49 w3.H("0x0000000000000000000000008e870d67f660d95d5be530380d0ec0bd388289e1"), 50 w3.H("0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"), 51 }, 52 Data: w3.B("0x0000000000000000000000003139ffc91b99aa94da8a2dc13f1fc36f9bdc98ee0000000000000000000000000000000000000000000000000000000000000002"), 53 BlockNumber: 10008500, 54 TxHash: w3.H("0xb0621ca74cee9f540dda6d575f6a7b876133b42684c1259aaeb59c831410ccb2"), 55 TxIndex: 35, 56 BlockHash: w3.H("0x27ff22f242123ca65b93d3886f1fa62bfa8f2a5d1c224750a7356b1c18b821f4"), 57 Index: 28, 58 }, 59 } 60 ) 61 if err := client.Call(eth.Logs(filterQuery).Returns(&logs)); err != nil { 62 t.Fatalf("Request failed: %v", err) 63 } 64 if diff := cmp.Diff(wantLogs, logs); diff != "" { 65 t.Fatalf("(-want, +got)\n%s", diff) 66 } 67 }