From eeb2fb700436b1cc01f08f1738422c985e1e2659 Mon Sep 17 00:00:00 2001 From: Vsevolod Brekelov Date: Thu, 12 Dec 2019 21:13:54 +0300 Subject: [PATCH] integration: add signing tx --- integration/performance_test.go | 46 ++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/integration/performance_test.go b/integration/performance_test.go index f794e1502..2a3b8789d 100644 --- a/integration/performance_test.go +++ b/integration/performance_test.go @@ -8,7 +8,10 @@ import ( "github.com/CityOfZion/neo-go/pkg/core" "github.com/CityOfZion/neo-go/pkg/core/storage" "github.com/CityOfZion/neo-go/pkg/core/transaction" + "github.com/CityOfZion/neo-go/pkg/crypto" + "github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/network" + "github.com/CityOfZion/neo-go/pkg/rpc" "github.com/stretchr/testify/require" ) @@ -28,16 +31,46 @@ func BenchmarkTXPerformanceTest(t *testing.B) { serverConfig := network.NewServerConfig(cfg) server := network.NewServer(serverConfig, chain) + data := prepareData(t) + t.ResetTimer() + for n := 0; n < t.N; n++ { - tx := getTX() - require.Equal(t, server.RelayTxn(tx), network.RelaySucceed) - require.Equal(t, server.RelayTxn(tx), network.RelayAlreadyExists) + require.Equal(t, server.RelayTxn(data[n]), network.RelaySucceed) + require.Equal(t, server.RelayTxn(data[n]), network.RelayAlreadyExists) } chain.Close() } +func prepareData(t *testing.B) []*transaction.Transaction { + var data []*transaction.Transaction + + wif := getWif(t) + + for n := 0; n < t.N; n++ { + tx := getTX(t, wif) + require.NoError(t, rpc.SignTx(tx, wif)) + data = append(data, tx) + } + return data +} + +// getWif returns Wif. +func getWif(t *testing.B) *keys.WIF { + var ( + wifEncoded = "KxhEDBQyyEFymvfJD96q8stMbJMbZUb6D1PmXqBWZDU2WvbvVs9o" + version = byte(0x00) + ) + wif, err := keys.WIFDecode(wifEncoded, version) + require.NoError(t, err) + return wif +} + // getTX returns Invocation transaction with some random attributes in order to have different hashes. -func getTX() *transaction.Transaction { +func getTX(t *testing.B, wif *keys.WIF) *transaction.Transaction { + fromAddress := wif.PrivateKey.Address() + fromAddressHash, err := crypto.Uint160DecodeAddress(fromAddress) + require.NoError(t, err) + tx := &transaction.Transaction{ Type: transaction.InvocationType, Version: 0, @@ -57,6 +90,11 @@ func getTX() *transaction.Transaction { Usage: transaction.Description, Data: []byte(randString(10)), }) + tx.Attributes = append(tx.Attributes, + transaction.Attribute{ + Usage: transaction.Script, + Data: fromAddressHash.BytesBE(), + }) return tx }