github.com/amazechain/amc@v0.1.3/internal/network/service_test.go (about) 1 // Copyright 2022 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain 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 AmazeChain 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 AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package network 18 19 import ( 20 "crypto/rand" 21 "github.com/libp2p/go-libp2p/core/crypto" 22 "github.com/libp2p/go-libp2p/core/peer" 23 "testing" 24 ) 25 26 func TestNewService(t *testing.T) { 27 //blockchain := configs.NetWorkConfig{} 28 //NewService(context.TODO(), &blockchain) 29 30 } 31 32 func TestPeerKey(t *testing.T) { 33 peerKey, _, err := crypto.GenerateECDSAKeyPair(rand.Reader) 34 if err != nil { 35 t.Fatal(err) 36 } 37 38 id, err := peer.IDFromPrivateKey(peerKey) 39 if err != nil { 40 t.Fatal(err) 41 } 42 43 t.Logf("id = %s", id.String()) 44 45 bKey, err := crypto.MarshalPrivateKey(peerKey) 46 if err != nil { 47 t.Fatal(err) 48 } 49 50 t.Logf("bKey %v", bKey) 51 sKey := crypto.ConfigEncodeKey(bKey) 52 t.Logf("sKey %s", sKey) 53 54 bKey2, err := crypto.ConfigDecodeKey(sKey) 55 if err != nil { 56 t.Fatal(err) 57 } 58 59 peerKey2, err := crypto.UnmarshalPrivateKey(bKey2) 60 if err != nil { 61 t.Fatal(err) 62 } 63 64 id2, err := peer.IDFromPrivateKey(peerKey2) 65 if err != nil { 66 t.Fatal(err) 67 } 68 69 t.Logf("id2 = %s , id1 = %s", id2.String(), id.String()) 70 } 71 72 func TestStartService(t *testing.T) { 73 //strKey := "CAMSeTB3AgEBBCBZandzyO1LLLNawa6diRUh/A7FTOkxLlHuaIaQJ2piDqAKBggqhkjOPQMBB6FEA0IABEhI/zTNfeaDp31XUoGwUACXZ1HswgWtJGxYoqq9CIxfEvMl3HnMn2ZVcSz2z590k/CpfnrsTLik/8dUiXBfh2U=" 74 //bKey, err := crypto.ConfigDecodeKey(strKey) 75 //if err != nil { 76 // t.Fatal(err) 77 //} 78 // 79 //peerKey, err := crypto.UnmarshalPrivateKey(bKey) 80 //if err != nil { 81 // t.Fatal(err) 82 //} 83 //blockchain := configs.NetWorkConfig{ 84 // ListenersAddress: []string{"/ip4/0.0.0.0/tcp/0"}, 85 // BootstrapPeers: nil, 86 // LocalPeerKey: strKey, 87 //} 88 // 89 ////s := NewService(context.TODO(), &blockchain) 90 //if s == nil { 91 // t.Fatal("error") 92 //} 93 // 94 //if err := s.Start(); err != nil { 95 // t.Fatal(err) 96 //} 97 }