-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cover transaction manager with additional test cases #561 #601
Conversation
I'm going to extend |
Yes, this approach looks good. #537 was merged, so now it is possible to overwrite timeout for waiting. But what about that wg.Wait? Did you found what was causing that problem? |
ctx, cancel = context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()
if err := m.ethTxClient.SendTransaction(ctx, signedTx); err != nil {
return hash, err
} Looks like return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", common.ToHex(data)) line in |
go-ethereum/rpc/initproc.go, L29: go handler.ServeCodec(NewJSONCodec(p1), OptionMethodInvocation|OptionSubscriptions) I believe that goroutine is getting killed on the server side so client context is still alive until it times out. |
It's also possible to pull |
@canercidam thanks for a research, i think you are right. adding default timeout that is used for context to transaction manager and then overwriting it in tests sounds goods. i think that we should even use transaction context for every call, but it is definitely not for this PR. i will do a review tomorrow probably |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks good, need to verify how it works with testify and added a couple of style comments
geth/transactions/txqueue_manager.go
Outdated
@@ -32,6 +32,7 @@ type Manager struct { | |||
addrLock *AddrLocker | |||
notify bool | |||
completionTimeout time.Duration | |||
ctxTimeout time.Duration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rpcCallTimeout ?
s.txServiceMock.EXPECT().GasPrice(gomock.Any()).Return(big.NewInt(10), nil) | ||
s.txServiceMock.EXPECT().EstimateGas(gomock.Any(), gomock.Any()).Return(&gas, nil) | ||
s.txServiceMock.EXPECT().SendRawTransaction(gomock.Any(), gomock.Any()).Return(gethcommon.Hash{}, txErr) | ||
func (s *TxQueueTestSuite) setupTransactionPoolAPI(tx *common.QueuedTx, config *params.NodeConfig, account *common.SelectedExtKey, nonce *hexutil.Uint64, gas *hexutil.Big, txErr error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about preparing tx earlier and passing it to this method? it looks like it will cleanup an interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what do you mean by "preparing tx earlier and passing it to this method"? Isn't that already how it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought that it is possible to pass types.Transaction instead of tx *common.QueuedTx, config *params.NodeConfig, account *common.SelectedExtKey, nonce *hexutil.Uint64, gas *hexutil.Big
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean, I may be able to further reduce the code using types.Transaction
. I'll look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second glance, it will just result in moving lines elsewhere because one has to form both types.Transaction
and common.QueuedTx
objects in the same case. In other words, if I define a types.Transaction
object in the test case and pass it to setupTransactionPoolAPI
instead, that means I can remove forming a new object from s.rlpEncode
and it doesn't make a difference about how I handle rest of the args such as gas, gas price and nonce.
But it's definitely possible to reduce the amount of args there by having default test values so I'm going to do that instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thanks for checking
s.NoError(WaitClosed(w, time.Second)) | ||
s.Equal(hash, rst.Hash) | ||
for _, testCase := range testCases { | ||
s.T().Run(testCase.name, func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never used it with testify, will it allow to use testify.m the same way as before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it doesn't detect that. But IMHO, it's certainly more readable & DRY and all tests run in few seconds anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good i think
go test ./geth/transactions/ -v -testify.m=TestCompleteTransaction$
=== RUN TestTxQueueTestSuite
=== RUN TestTxQueueTestSuite/TestCompleteTransaction
=== RUN TestTxQueueTestSuite/TestCompleteTransaction/noGasDef
=== RUN TestTxQueueTestSuite/TestCompleteTransaction/gasDefined
=== RUN TestTxQueueTestSuite/TestCompleteTransaction/gasPriceDefined
--- PASS: TestTxQueueTestSuite (0.01s)
--- PASS: TestTxQueueTestSuite/TestCompleteTransaction (0.01s)
--- PASS: TestTxQueueTestSuite/TestCompleteTransaction/noGasDef (0.00s)
--- PASS: TestTxQueueTestSuite/TestCompleteTransaction/gasDefined (0.00s)
--- PASS: TestTxQueueTestSuite/TestCompleteTransaction/gasPriceDefined (0.00s)
PASS
ok github.com/status-im/status-go/geth/transactions 0.055s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be rebased ofcourse
@dshulyak Can you please review the last small change? |
var ( | ||
testGas = (*hexutil.Big)(big.NewInt(defaultGas + 1)) | ||
testGasPrice = (*hexutil.Big)(big.NewInt(10)) | ||
testNonce = hexutil.Uint64(10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will be using non-default nonce here #538 , so it is not very good idea. but you can leave it if you want. i can rebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay. I'll just revert changes for nonce then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
@mandrigin Whoops, it wasn't ready yet. :) |
Anyway, doesn't make a big difference. I was going to rollback a change and squash commits. Thanks for your time and efforts! @mandrigin @dshulyak |
Changes
setupTransactionPoolAPI
to prepare mock functions in a more strictly covering way, regarding gas, gas price and resulting transaction.Closes #561
@dshulyak