Skip to content
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

Merged
merged 9 commits into from
Feb 5, 2018

Conversation

canercidam
Copy link
Contributor

Changes setupTransactionPoolAPI to prepare mock functions in a more strictly covering way, regarding gas, gas price and resulting transaction.

Closes #561

@dshulyak

@canercidam
Copy link
Contributor Author

I'm going to extend TestCompleteTransaction in a table-driven manner with non-nil gas and gas price cases, if these changes look good enough.

@dshulyak
Copy link
Contributor

dshulyak commented Feb 2, 2018

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?

@canercidam
Copy link
Contributor Author

canercidam commented Feb 2, 2018

ctx, cancel = context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()
if err := m.ethTxClient.SendTransaction(ctx, signedTx); err != nil {
	return hash, err
}

Looks like defaultTimeout affects that, so I'm trying to see in source code how context timeout keeps

return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", common.ToHex(data))

line in SendTransaction from finalizing. I think the quick solution at the moment is having a ctxTimeout field in Manager as well and setting it to a low value in tests.

@canercidam
Copy link
Contributor Author

canercidam commented Feb 2, 2018

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.

@canercidam
Copy link
Contributor Author

It's also possible to pull TestAccountMismatch and TestInvalidPassword into TestCompleteTransaction now.

@dshulyak
Copy link
Contributor

dshulyak commented Feb 2, 2018

@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

Copy link
Contributor

@dshulyak dshulyak left a 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

@@ -32,6 +32,7 @@ type Manager struct {
addrLock *AddrLocker
notify bool
completionTimeout time.Duration
ctxTimeout time.Duration
Copy link
Contributor

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

@canercidam canercidam Feb 5, 2018

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.

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

@dshulyak dshulyak left a 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

@canercidam
Copy link
Contributor Author

@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)
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@mandrigin mandrigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@mandrigin mandrigin merged commit 0dd47ab into status-im:develop Feb 5, 2018
@canercidam
Copy link
Contributor Author

@mandrigin Whoops, it wasn't ready yet. :)

@canercidam
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants