github.com/annchain/OG@v0.0.9/p2p/onode/node_test.go (about)

     1  // Copyright 2018 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package onode
    18  
    19  import (
    20  	"encoding/hex"
    21  	"fmt"
    22  	"testing"
    23  
    24  	"github.com/annchain/OG/p2p/enr"
    25  	"github.com/stretchr/testify/assert"
    26  )
    27  
    28  //var pyRecord, _ = hex.DecodeString("f884b8407098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c01826964827634826970847f00000189736563703235366b31a103ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31388375647082765f")
    29  var pyRecord, _ = hex.DecodeString("83a353657101a95369676e6174757265c4401fb4a09b1eb072d998b35ca3c681902d3866507c527eb612fffbb021cbd110c34087a517948b6130914fca1cb7acb52e1c4ea4779cfb93cb74de731bf7d2415fa550616972739482a14ba26964a156c403a2763482a14ba26970a156c406c4047f00000182a14ba9736563703235366b31a156c423c42103ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd313882a14ba3756470a156c403cd765f")
    30  
    31  // TestPythonInterop checks that we can decode and verify a record produced by the Python
    32  // implementation.
    33  func TestPythonInterop(t *testing.T) {
    34  	//var r1 enr.Record
    35  	var (
    36  		wantID  = HexID("a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7")
    37  		wantSeq = uint64(1)
    38  		wantIP  = enr.IP{127, 0, 0, 1}
    39  		wantUDP = enr.UDP(30303)
    40  	)
    41  	//r1.Set(&wantIP)
    42  	//r1.Set(&wantUDP)
    43  	//r1.SetSeq(1)
    44  	// err := SignV4(&r1,privkey)
    45  	//fmt.Println(err)
    46  	//pyRecord ,err := r1.Encode(nil)
    47  	//fmt.Println(err,hex.EncodeToString(pyRecord))
    48  	var r enr.Record
    49  	if _, err := r.Decode(pyRecord); err != nil {
    50  		t.Fatalf("can't decode: %v", err)
    51  	}
    52  	n, err := New(ValidSchemes, &r)
    53  	if err != nil {
    54  		t.Fatalf("can't verify record: %v", err)
    55  	}
    56  
    57  	if n.Seq() != wantSeq {
    58  		t.Errorf("wrong seq: got %d, want %d", n.Seq(), wantSeq)
    59  	}
    60  	if n.ID() != wantID {
    61  		t.Errorf("wrong id: got %x, want %x", n.ID(), wantID)
    62  	}
    63  	want := map[enr.Entry]interface{}{new(enr.IP): &wantIP, new(enr.UDP): &wantUDP}
    64  	for k, v := range want {
    65  		desc := fmt.Sprintf("loading key %q", k.ENRKey())
    66  		if assert.NoError(t, n.Load(k), desc) {
    67  			assert.Equal(t, k, v, desc)
    68  		}
    69  	}
    70  }