diff --git a/packages/curl/batch_hasher_test.go b/packages/curl/batch_hasher_test.go index c76727330117a1c0655dd974a6c8bb810295ef21..7cd6bb4e84d81d96b24bca996332be8795b66e03 100644 --- a/packages/curl/batch_hasher_test.go +++ b/packages/curl/batch_hasher_test.go @@ -42,15 +42,33 @@ func BenchmarkEd25519(b *testing.B) { wg.Wait() } -func BenchmarkBlake2b(b *testing.B) { - data := make([]byte, 750) +var sampleTransactionData = make([]byte, 750) + +func BenchmarkBytesToTrits(b *testing.B) { + bytes := blake2b.Sum512(sampleTransactionData) + b.ResetTimer() + + var wg sync.WaitGroup + for i := 0; i < b.N; i++ { + wg.Add(1) + + go func() { + _, _ = trinary.BytesToTrits(bytes[:]) + + wg.Done() + }() + } + wg.Wait() +} + +func BenchmarkBlake2b(b *testing.B) { var wg sync.WaitGroup for i := 0; i < b.N; i++ { wg.Add(1) go func() { - blake2b.Sum256(data) + blake2b.Sum256(sampleTransactionData) wg.Done() }() diff --git a/packages/identity/identity.go b/packages/identity/identity.go index ac5a417ec6881829c8eaa06d4c6a743498929cd3..022af162586fa9bd2e66d406c15697bd3ed39891 100644 --- a/packages/identity/identity.go +++ b/packages/identity/identity.go @@ -22,9 +22,11 @@ type Identity struct { func NewIdentity(publicKey []byte, optionalPrivateKey ...[]byte) *Identity { this := &Identity{ Identifier: crypto.Hash20(publicKey), - PublicKey: publicKey, + PublicKey: make([]byte, len(publicKey)), } + copy(this.PublicKey, publicKey) + this.StringIdentifier = fmt.Sprintf("%x", this.Identifier) if len(optionalPrivateKey) == 1 { diff --git a/plugins/autopeering/types/peer/peer_test.go b/plugins/autopeering/types/peer/peer_test.go new file mode 100644 index 0000000000000000000000000000000000000000..f587001abf445e852595609e6d9da40664e02ba7 --- /dev/null +++ b/plugins/autopeering/types/peer/peer_test.go @@ -0,0 +1,31 @@ +package peer + +import ( + "net" + "testing" + "time" + + "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" + + "github.com/iotaledger/goshimmer/packages/identity" + "github.com/magiconair/properties/assert" +) + +func TestPeer_MarshalUnmarshal(t *testing.T) { + peer := &Peer{ + Address: net.IPv4(127, 0, 0, 1), + Identity: identity.GenerateRandomIdentity(), + GossipPort: 123, + PeeringPort: 456, + Salt: salt.New(30 * time.Second), + } + + restoredPeer, _ := Unmarshal(peer.Marshal()) + + assert.Equal(t, peer.Address, restoredPeer.Address) + assert.Equal(t, peer.Identity.StringIdentifier, restoredPeer.Identity.StringIdentifier) + assert.Equal(t, peer.Identity.PublicKey, restoredPeer.Identity.PublicKey) + assert.Equal(t, peer.GossipPort, restoredPeer.GossipPort) + assert.Equal(t, peer.PeeringPort, restoredPeer.PeeringPort) + assert.Equal(t, peer.Salt, restoredPeer.Salt) +} diff --git a/plugins/autopeering/types/response/response_test.go b/plugins/autopeering/types/response/response_test.go new file mode 100644 index 0000000000000000000000000000000000000000..4f6c1e232e0d12b952aa52d6551653acd8a2b726 --- /dev/null +++ b/plugins/autopeering/types/response/response_test.go @@ -0,0 +1,55 @@ +package response + +import ( + "net" + "testing" + "time" + + "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" + + "github.com/iotaledger/goshimmer/packages/identity" + "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" +) + +func TestPeer_MarshalUnmarshal(t *testing.T) { + issuer := &peer.Peer{ + Address: net.IPv4(127, 0, 0, 1), + Identity: identity.GenerateRandomIdentity(), + GossipPort: 123, + PeeringPort: 456, + Salt: salt.New(30 * time.Second), + } + + peers := make([]*peer.Peer, 0) + peers = append(peers, &peer.Peer{ + Address: net.IPv4(127, 0, 0, 1), + Identity: identity.GenerateRandomIdentity(), + GossipPort: 124, + PeeringPort: 457, + Salt: salt.New(30 * time.Second), + }, &peer.Peer{ + Address: net.IPv4(127, 0, 0, 1), + Identity: identity.GenerateRandomIdentity(), + GossipPort: 125, + PeeringPort: 458, + Salt: salt.New(30 * time.Second), + }, &peer.Peer{ + Address: net.IPv4(127, 0, 0, 1), + Identity: identity.GenerateRandomIdentity(), + GossipPort: 126, + PeeringPort: 459, + Salt: salt.New(30 * time.Second), + }) + + response := &Response{ + Issuer: issuer, + Type: TYPE_ACCEPT, + Peers: peers, + } + response.Sign() + + _, err := Unmarshal(response.Marshal()) + if err != nil { + t.Error(err) + } +} diff --git a/plugins/bundleprocessor/bundleprocessor_test.go b/plugins/bundleprocessor/bundleprocessor_test.go index 06539a0023293a5cb481ad04e07084b513867a16..14834c67c2b0ed49ef7b418cee8309c5f7e21afd 100644 --- a/plugins/bundleprocessor/bundleprocessor_test.go +++ b/plugins/bundleprocessor/bundleprocessor_test.go @@ -21,7 +21,7 @@ import ( var seed = client.NewSeed("YFHQWAUPCXC9S9DSHP9NDF9RLNPMZVCMSJKUKQP9SWUSUCPRQXCMDVDVZ9SHHESHIQNCXWBJF9UJSWE9Z", consts.SecurityLevelMedium) -func Benchmark(b *testing.B) { +func BenchmarkValidateSignatures(b *testing.B) { bundleFactory := client.NewBundleFactory() bundleFactory.AddInput(seed.GetAddress(0), -400) bundleFactory.AddOutput(seed.GetAddress(1), 400, "Testmessage") @@ -54,11 +54,11 @@ func TestValidateSignatures(t *testing.T) { generatedBundle := bundleFactory.GenerateBundle(tipselection.GetRandomTip(), tipselection.GetRandomTip()) - successfull, err := ValidateSignatures(generatedBundle.GetEssenceHash(), generatedBundle.GetTransactions()) + successful, err := ValidateSignatures(generatedBundle.GetEssenceHash(), generatedBundle.GetTransactions()) if err != nil { t.Error(err) } - assert.Equal(t, successfull, true, "validation failed") + assert.Equal(t, successful, true, "validation failed") } func TestProcessSolidBundleHead_Data(t *testing.T) { diff --git a/plugins/bundleprocessor/valuebundleprocessor.go b/plugins/bundleprocessor/valuebundleprocessor.go index 08c208d965cff885d88f2acad06fb48a6ec4f79c..271fdb0633df4e48e5e25c4a0a503190088e38f0 100644 --- a/plugins/bundleprocessor/valuebundleprocessor.go +++ b/plugins/bundleprocessor/valuebundleprocessor.go @@ -70,7 +70,7 @@ func ValidateSignatures(bundleHash trinary.Hash, txs []*value_transaction.ValueT } // validate all the fragments against the address using Kerl - valid, err := signing.ValidateSignatures(address, fragments, bundleHash, signing.NewKerl) + valid, err := signing.ValidateSignatures(address, fragments, bundleHash) if err != nil { return false, err }