-
Notifications
You must be signed in to change notification settings - Fork 11
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
refactor: break up transformer and rpc package logic into smaller func and add unit tests #1313
base: staging
Are you sure you want to change the base?
Conversation
…nto m/refactor-indexing-v2
…Values & TestCalculateTxFee methods
…nto m/refactor-indexing-v2
… calculateUncleReward & verifyName methods
…ly & getERC20ContractDecimals method
…nto m/refactor-indexing-v2
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.
There is a lot of good things in that pr but I'm wondering if some changes go maybe too far (too many little functions, too many tests that test not exported func without direct link to usage, ...) and will be a burden in the long run.
@@ -207,6 +207,16 @@ func (b *BlockchainBackend) DeployContract(t *testing.T, contractData []byte) co | |||
return receipt.ContractAddress | |||
} | |||
|
|||
func (b *BlockchainBackend) NewERC20Metadata(t *testing.T, address common.Address) (*contracts.IERC20Metadata, 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.
I don't really see the point of this function, it's just a wrapper around contracts.NewIERC20Metadata
but without adding anything.
uncles := getBlockUncles(block.Uncles()) | ||
baseFee := getBaseFee(block) | ||
blobGasUsed := getBlobGasUsed(block) | ||
excessBlobGas := getExcessBlobGas(block) |
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.
those can be moved when we create types.Eth1Block
like
&types.Eth1Block{
...
BaseFee: getBaseFee(block),
...
}
to := getReceiver(tx) | ||
maxFeePerBlobGas := getMaxFeePerBlobGas(tx) | ||
blobVersionedHashes := getBlobVersionedHashes(tx) | ||
blobGasPrice := getBlobGasPrice(receipt) |
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.
same, inline when possible
|
||
// TestGetInternalTxs tests the getInternalTxs function | ||
// which returns the internal transactions of a transaction at a given position | ||
func TestGetInternalTxs(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.
do we really want those comments on top of each tests ? this doesn't bring anything new IMO
|
||
// TestGetMaxFeePerBlobGas tests the getMaxFeePerBlobGas function | ||
// which extracts the max fee per blob gas from a transaction | ||
func TestGetMaxFeePerBlobGas(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.
Do we really want to test each individual function like that ? Too much tests is like too much codes, harder to maintain, more complex and prone to brake.
I mean what this test is really testing ? Following this logic we could do a test for each field of a block. IMO it's better to create one test where we test each field all together.
if err != nil && tt.expectedErr == nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
if err == nil && tt.expectedErr != nil { |
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.
same
if err != nil && tt.expectedErr == nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
if err == nil && tt.expectedErr != nil { |
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.
same
return v | ||
} | ||
|
||
func updateITxStatus(internalTx []*types.Eth1InternalTransaction, indexedTx *types.Eth1TransactionIndexed) { |
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.
minor suggestion but the signature would better if reversed and internalTx should be plural
func updateITxStatus(indexedTx *types.Eth1TransactionIndexed, internals []*types.Eth1InternalTransaction)
@@ -320,7 +269,8 @@ func TransformITx(chainID string, block *types.Eth1Block, res *IndexedBlock) err | |||
var transactions []data.InternalWithIndexes | |||
for i, tx := range block.GetTransactions() { | |||
for j, itx := range tx.GetItx() { | |||
if itx.Path == "0" || itx.Path == "[]" || bytes.Equal(itx.Value, []byte{0x0}) { // skip top level and empty calls | |||
// skip top level and empty calls |
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.
this comment should be inside isValidItx
func IMO
if (result == nil && tt.expected != nil) || (result != nil && tt.expected == nil) { | ||
t.Errorf("got %v, want %v", result, tt.expected) | ||
} else if result != nil && tt.expected != nil && result.Error() != tt.expected.Error() { | ||
t.Errorf("got %v, want %v", result, tt.expected) |
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.
same
Changes:
transformer.go
functions in the/executionlayer
package by breaking them into smaller, more readable functionserigon.go
andgeth.go
functions in the/rpc
package by splitting them into smaller functions and introducedutils.go
to share common functionality between themutils_test.go
anderigon_test.go
in the/rpc
packagetransformer_test.go
in the/executionlayer
package