Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MetaProtocol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nebula
MetaProtocol
Commits
83e05cc4
Commit
83e05cc4
authored
Dec 01, 2022
by
Ubuntu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compare tx hash
parent
c5023e6c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
52 deletions
+121
-52
grcp-tx_test.go
grcp-tx_test.go
+121
-52
No files found.
grcp-tx_test.go
View file @
83e05cc4
package
main_test
import
(
"bytes"
"context"
"crypto/ecdsa"
"errors"
"fmt"
"sync"
...
...
@@ -126,14 +128,21 @@ func (*RingServer) SendTxAsAny(ctx context.Context, in *base.Transaction) (*ring
return
&
ring
.
SendRawTransactionResponse
{
TxHash
:
ethTx
.
Hash
()
.
Bytes
()},
nil
default
:
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"server expected tx type: %T and %T, but actually is %T"
,
base
.
EthTx
{},
base
.
StdTx
{},
msg
))
}
return
&
ring
.
SendRawTransactionResponse
{},
nil
}
func
(
*
RingServer
)
SendTxAsBytes
(
ctx
context
.
Context
,
req
*
base
.
TransactionBytes
)
(
*
ring
.
SendRawTransactionResponse
,
error
)
{
func
(
*
RingServer
)
SendTxAsBytes
(
ctx
context
.
Context
,
in
*
base
.
TransactionBytes
)
(
*
ring
.
SendRawTransactionResponse
,
error
)
{
return
&
ring
.
SendRawTransactionResponse
{},
nil
ethTx
:=
types
.
Transaction
{}
if
err
:=
ethTx
.
UnmarshalBinary
(
in
.
Tx
);
err
!=
nil
{
return
nil
,
err
}
return
&
ring
.
SendRawTransactionResponse
{
TxHash
:
ethTx
.
Hash
()
.
Bytes
()},
nil
}
func
TestGrpcServer
(
t
*
testing
.
T
)
{
...
...
@@ -164,6 +173,11 @@ func pricedTransaction(to common.Address, nonce uint64, gaslimit uint64, gaspric
// go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=3s
// go test -v -run BenchmarkBytesEth -bench BenchmarkBytesEth -benchtime=3s
// go test -v -run BenchmarkEthTx -bench BenchmarkEthTx -benchtime=1s
// go test -v -run BenchmarkStdTx -bench BenchmarkStdTx -benchtime=1s
// go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=1s
// go test -v -run BenchmarkBytesEth -bench BenchmarkBytesEth -benchtime=1s
// go test -v -run TestGrpcServer -timeout 0
//BenchmarkAny
...
...
@@ -192,6 +206,8 @@ func int() {
var
count
int64
var
countParallel
int64
var
onceHash
sync
.
Once
func
BenchmarkEthTx
(
b
*
testing
.
B
)
{
// count++
...
...
@@ -261,6 +277,14 @@ func BenchmarkEthTx(b *testing.B) {
_
=
res
if
bytes
.
Compare
(
tx
.
Hash
()
.
Bytes
(),
res
.
TxHash
)
!=
0
{
b
.
Fatal
(
err
)
}
onceHash
.
Do
(
func
()
{
b
.
Logf
(
"response: %x local: %x
\n
"
,
res
.
TxHash
,
tx
.
Hash
()
.
Bytes
())
})
//fmt.Printf("%x \n", res.TxHash)
}
...
...
@@ -327,6 +351,13 @@ func BenchmarkStdTx(b *testing.B) {
_
=
res
//fmt.Printf("%x \n", res.TxHash)
if
bytes
.
Compare
(
tx
.
Hash
()
.
Bytes
(),
res
.
TxHash
)
!=
0
{
b
.
Fatal
(
err
)
}
onceHash
.
Do
(
func
()
{
b
.
Logf
(
"response: %x local: %x
\n
"
,
res
.
TxHash
,
tx
.
Hash
()
.
Bytes
())
})
}
})
...
...
@@ -395,6 +426,93 @@ func BenchmarkAnyTx(b *testing.B) {
_
=
res
if
bytes
.
Compare
(
tx
.
Hash
()
.
Bytes
(),
res
.
TxHash
)
!=
0
{
b
.
Fatal
(
err
)
}
onceHash
.
Do
(
func
()
{
b
.
Logf
(
"response: %x local: %x
\n
"
,
res
.
TxHash
,
tx
.
Hash
()
.
Bytes
())
})
}
})
}
func
BenchmarkBytesEth
(
b
*
testing
.
B
)
{
onceFunc
:=
func
()
{
local
,
_
:=
crypto
.
HexToECDSA
(
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
)
publicKey
:=
local
.
Public
()
publicKeyECDSA
,
_
:=
publicKey
.
(
*
ecdsa
.
PublicKey
)
fromAddr
=
crypto
.
PubkeyToAddress
(
*
publicKeyECDSA
)
remote
,
_
:=
crypto
.
GenerateKey
()
tx
=
pricedTransaction
(
crypto
.
PubkeyToAddress
(
remote
.
PublicKey
),
0
,
100000
,
big
.
NewInt
(
1
),
local
)
}
once
.
Do
(
onceFunc
)
b
.
ReportAllocs
()
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
for
pb
.
Next
()
{
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9006"
,
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
()))
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
defer
conn
.
Close
()
c
:=
ring
.
NewRingServiceClient
(
conn
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
)
defer
cancel
()
txAsBytes
,
err
:=
tx
.
MarshalBinary
()
// inner := base.EthTxData{
// AccountNonce: tx.Nonce(),
// Price: tx.GasPrice().Bytes(),
// GasLimit: tx.Gas(),
// Payload: tx.Data(),
// }
// v, r, sigs := tx.RawSignatureValues()
// inner.V = v.Bytes()
// inner.R = r.Bytes()
// inner.S = sigs.Bytes()
// inner.Amount = tx.Value().Bytes()
// addr := base.Address{Address: tx.To().Bytes()}
// inner.Recipient = &addr
// inner.From = fromAddr.Bytes()
// txAsRes := &base.TransactionEth{Tx: &base.EthTx{Inner: &inner}}
// txAsRes.
// if err != nil {
// b.Fatal(err)
// }
res
,
err
:=
c
.
SendTxAsBytes
(
ctx
,
&
base
.
TransactionBytes
{
Tx
:
txAsBytes
,
From
:
fromAddr
[
:
]})
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
_
=
res
if
bytes
.
Compare
(
tx
.
Hash
()
.
Bytes
(),
res
.
TxHash
)
!=
0
{
b
.
Fatal
(
err
)
}
onceHash
.
Do
(
func
()
{
b
.
Logf
(
"response: %x local: %x
\n
"
,
res
.
TxHash
,
tx
.
Hash
()
.
Bytes
())
})
}
})
}
...
...
@@ -519,52 +637,3 @@ func TestAnyTx(t *testing.T) {
// }
// })
}
func
BenchmarkBytesEth
(
b
*
testing
.
B
)
{
onceFunc
:=
func
()
{
local
,
_
:=
crypto
.
HexToECDSA
(
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
)
publicKey
:=
local
.
Public
()
publicKeyECDSA
,
_
:=
publicKey
.
(
*
ecdsa
.
PublicKey
)
fromAddr
=
crypto
.
PubkeyToAddress
(
*
publicKeyECDSA
)
remote
,
_
:=
crypto
.
GenerateKey
()
tx
=
pricedTransaction
(
crypto
.
PubkeyToAddress
(
remote
.
PublicKey
),
0
,
100000
,
big
.
NewInt
(
1
),
local
)
}
once
.
Do
(
onceFunc
)
b
.
ReportAllocs
()
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
for
pb
.
Next
()
{
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9006"
,
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
()))
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
defer
conn
.
Close
()
c
:=
ring
.
NewRingServiceClient
(
conn
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
)
defer
cancel
()
txAsBytes
,
err
:=
tx
.
MarshalBinary
()
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
res
,
err
:=
c
.
SendTxAsBytes
(
ctx
,
&
base
.
TransactionBytes
{
Tx
:
txAsBytes
,
From
:
fromAddr
[
:
]})
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
_
=
res
}
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment