github.com/lmittmann/w3@v0.20.0/module/admin/admin_test.go (about) 1 package admin_test 2 3 import ( 4 "math/big" 5 "net" 6 "testing" 7 8 "github.com/ethereum/go-ethereum/p2p/enode" 9 "github.com/ethereum/go-ethereum/p2p/enr" 10 "github.com/google/go-cmp/cmp/cmpopts" 11 "github.com/lmittmann/w3" 12 "github.com/lmittmann/w3/module/admin" 13 "github.com/lmittmann/w3/rpctest" 14 ) 15 16 func TestAddPeer(t *testing.T) { 17 rpctest.RunTestCases(t, []rpctest.TestCase[bool]{ 18 { 19 Golden: "add_peer", 20 Call: admin.AddPeer(enode.MustParse("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303")), 21 WantRet: true, 22 }, 23 }) 24 } 25 26 func TestRemovePeer(t *testing.T) { 27 rpctest.RunTestCases(t, []rpctest.TestCase[bool]{ 28 { 29 Golden: "remove_peer", 30 Call: admin.RemovePeer(enode.MustParse("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303")), 31 WantRet: true, 32 }, 33 }) 34 } 35 36 func TestAddTrustedPeer(t *testing.T) { 37 rpctest.RunTestCases(t, []rpctest.TestCase[bool]{ 38 { 39 Golden: "add_trusted_peer", 40 Call: admin.AddTrustedPeer(enode.MustParse("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303")), 41 WantRet: true, 42 }, 43 }) 44 } 45 46 func TestRemoveTrustedPeer(t *testing.T) { 47 rpctest.RunTestCases(t, []rpctest.TestCase[bool]{ 48 { 49 Golden: "remove_trusted_peer", 50 Call: admin.RemoveTrustedPeer(enode.MustParse("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303")), 51 WantRet: true, 52 }, 53 }) 54 } 55 56 func TestNodeInfo(t *testing.T) { 57 rpctest.RunTestCases(t, []rpctest.TestCase[*admin.NodeInfoResponse]{ 58 { 59 Golden: "node_info", 60 Call: admin.NodeInfo(), 61 WantRet: &admin.NodeInfoResponse{ 62 Enode: enode.MustParse("enode://44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d@[::]:30303"), 63 ID: "44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d", 64 IP: net.ParseIP("::"), 65 ListenAddr: "[::]:30303", 66 Name: "reth/v0.0.1/x86_64-unknown-linux-gnu", 67 Ports: &admin.PortsInfo{ 68 Discovery: 30303, 69 Listener: 30303, 70 }, 71 Protocols: map[string]*admin.ProtocolInfo{ 72 "eth": { 73 Difficulty: w3.I("17334254859343145000"), 74 Genesis: w3.H("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"), 75 Head: w3.H("0xb83f73fbe6220c111136aefd27b160bf4a34085c65ba89f24246b3162257c36a"), 76 Network: 1, 77 }, 78 }, 79 }, 80 }, 81 }, cmpopts.IgnoreUnexported(big.Int{}, enode.Node{}, enr.Record{})) 82 }