Skip to content

Commit

Permalink
minor test clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
bharath-123 committed Sep 23, 2024
1 parent 401c3d5 commit 5cae0da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions grpc/execution/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func TestExecutionService_GetBlock(t *testing.T) {
getBlockRequst: &astriaPb.GetBlockRequest{
Identifier: &astriaPb.BlockIdentifier{Identifier: &astriaPb.BlockIdentifier_BlockNumber{BlockNumber: 1}},
},
expectedReturnCode: 0,
expectedReturnCode: codes.OK,
},
{
description: "Get block by block hash",
getBlockRequst: &astriaPb.GetBlockRequest{
Identifier: &astriaPb.BlockIdentifier{Identifier: &astriaPb.BlockIdentifier_BlockHash{BlockHash: ethservice.BlockChain().GetBlockByNumber(4).Hash().Bytes()}},
},
expectedReturnCode: 0,
expectedReturnCode: codes.OK,
},
{
description: "Get block which is not present",
Expand All @@ -97,6 +97,8 @@ func TestExecutionService_GetBlock(t *testing.T) {
if tt.expectedReturnCode > 0 {
require.NotNil(t, err, "GetBlock should return an error")
require.Equal(t, tt.expectedReturnCode, status.Code(err), "GetBlock failed")
} else {
require.Nil(t, err, "GetBlock failed")
}
if err == nil {
require.NotNil(t, blockInfo, "Block not found")
Expand All @@ -115,7 +117,6 @@ func TestExecutionService_GetBlock(t *testing.T) {
require.Equal(t, block.Hash().Bytes(), blockInfo.Hash, "BlockHash is not correct")
}
})

}
}

Expand All @@ -138,7 +139,7 @@ func TestExecutionServiceServerV1Alpha2_BatchGetBlocks(t *testing.T) {
{Identifier: &astriaPb.BlockIdentifier_BlockHash{BlockHash: ethservice.BlockChain().GetBlockByNumber(5).Hash().Bytes()}},
},
},
expectedReturnCode: 0,
expectedReturnCode: codes.OK,
},
{
description: "BatchGetBlocks with block numbers",
Expand All @@ -151,7 +152,7 @@ func TestExecutionServiceServerV1Alpha2_BatchGetBlocks(t *testing.T) {
{Identifier: &astriaPb.BlockIdentifier_BlockNumber{BlockNumber: 5}},
},
},
expectedReturnCode: 0,
expectedReturnCode: codes.OK,
},
{
description: "BatchGetBlocks block not found",
Expand All @@ -174,6 +175,8 @@ func TestExecutionServiceServerV1Alpha2_BatchGetBlocks(t *testing.T) {
if tt.expectedReturnCode > 0 {
require.NotNil(t, err, "BatchGetBlocks should return an error")
require.Equal(t, tt.expectedReturnCode, status.Code(err), "BatchGetBlocks failed")
} else {
require.Nil(t, err, "BatchGetBlocks failed")
}

for _, batchBlock := range batchBlocksRes.GetBlocks() {
Expand Down Expand Up @@ -224,7 +227,7 @@ func TestExecutionServiceServerV1Alpha2_ExecuteBlock(t *testing.T) {
prevBlockHash: ethservice.BlockChain().CurrentSafeBlock().Hash().Bytes(),
timestamp: ethservice.BlockChain().CurrentSafeBlock().Time + 2,
depositTxAmount: big.NewInt(0),
expectedReturnCode: 0,
expectedReturnCode: codes.OK,
},
{
description: "ExecuteBlock with 5 txs and a deposit tx",
Expand All @@ -233,7 +236,7 @@ func TestExecutionServiceServerV1Alpha2_ExecuteBlock(t *testing.T) {
prevBlockHash: ethservice.BlockChain().CurrentSafeBlock().Hash().Bytes(),
timestamp: ethservice.BlockChain().CurrentSafeBlock().Time + 2,
depositTxAmount: big.NewInt(1000000000000000000),
expectedReturnCode: 0,
expectedReturnCode: codes.OK,
},
{
description: "ExecuteBlock with incorrect previous block hash",
Expand Down Expand Up @@ -267,13 +270,11 @@ func TestExecutionServiceServerV1Alpha2_ExecuteBlock(t *testing.T) {

// create the txs to send
// create 5 txs
txs := []*types.Transaction{}
marshalledTxs := []*sequencerblockv1alpha1.RollupData{}
for i := 0; i < 5; i++ {
unsignedTx := types.NewTransaction(uint64(i), testToAddress, big.NewInt(1), params.TxGas, big.NewInt(params.InitialBaseFee*2), nil)
tx, err := types.SignTx(unsignedTx, types.LatestSigner(ethservice.BlockChain().Config()), testKey)
require.Nil(t, err, "Failed to sign tx")
txs = append(txs, tx)

marshalledTx, err := tx.MarshalBinary()
require.Nil(t, err, "Failed to marshal tx")
Expand Down Expand Up @@ -336,7 +337,6 @@ func TestExecutionServiceServerV1Alpha2_ExecuteBlock(t *testing.T) {

require.Exactly(t, commitmentStateBeforeExecuteBlock, commitmentStateAfterExecuteBlock, "Commitment state should not be updated")
}

})
}
}
Expand All @@ -359,13 +359,11 @@ func TestExecutionServiceServerV1Alpha2_ExecuteBlockAndUpdateCommitment(t *testi
require.NotNil(t, previousBlock, "Previous block not found")

// create 5 txs
txs := []*types.Transaction{}
marshalledTxs := []*sequencerblockv1alpha1.RollupData{}
for i := 0; i < 5; i++ {
unsignedTx := types.NewTransaction(uint64(i), testToAddress, big.NewInt(1), params.TxGas, big.NewInt(params.InitialBaseFee*2), nil)
tx, err := types.SignTx(unsignedTx, types.LatestSigner(ethservice.BlockChain().Config()), testKey)
require.Nil(t, err, "Failed to sign tx")
txs = append(txs, tx)

marshalledTx, err := tx.MarshalBinary()
require.Nil(t, err, "Failed to marshal tx")
Expand Down
2 changes: 1 addition & 1 deletion grpc/execution/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block, stri

genesis := &core.Genesis{
Config: &config,
Alloc: core.GenesisAlloc{
Alloc: types.GenesisAlloc{
testAddr: {Balance: testBalance},
},
ExtraData: []byte("test genesis"),
Expand Down

0 comments on commit 5cae0da

Please sign in to comment.