diff --git a/rosetta-cli-conf/mainnet/config.json b/rosetta-cli-conf/mainnet/config.json index 2c0b8f5..69c25a1 100644 --- a/rosetta-cli-conf/mainnet/config.json +++ b/rosetta-cli-conf/mainnet/config.json @@ -7,7 +7,7 @@ "http_timeout": 300, "max_retries": 5, "retry_elapsed_time": 0, - "max_online_connections": 0, + "max_online_connections": 1000, "max_sync_concurrency": 0, "tip_delay": 1800, "log_configuration": false, diff --git a/rosetta-cli-conf/testnet/config.json b/rosetta-cli-conf/testnet/config.json index 7591bb5..ea1b75d 100644 --- a/rosetta-cli-conf/testnet/config.json +++ b/rosetta-cli-conf/testnet/config.json @@ -7,7 +7,7 @@ "http_timeout": 300, "max_retries": 5, "retry_elapsed_time": 0, - "max_online_connections": 0, + "max_online_connections": 1000, "max_sync_concurrency": 0, "tip_delay": 1800, "log_configuration": false, diff --git a/services/block_service.go b/services/block_service.go index 7eb76ed..b837765 100644 --- a/services/block_service.go +++ b/services/block_service.go @@ -54,6 +54,22 @@ func (s *BlockAPIService) Block( return nil, wrapErr(ErrBlockNotFound, err) } + txs := make([]*types.Transaction, len(blockResponse.OtherTransactions)) + for i, otherTx := range blockResponse.OtherTransactions { + transaction, err := s.i.GetBlockTransaction( + ctx, + blockResponse.Block.BlockIdentifier, + otherTx, + ) + if err != nil { + return nil, wrapErr(ErrTransactionNotFound, err) + } + + txs[i] = transaction + } + blockResponse.Block.Transactions = txs + + blockResponse.OtherTransactions = nil return blockResponse, nil } @@ -62,20 +78,5 @@ func (s *BlockAPIService) BlockTransaction( ctx context.Context, request *types.BlockTransactionRequest, ) (*types.BlockTransactionResponse, *types.Error) { - if s.config.Mode != configuration.Online { - return nil, wrapErr(ErrUnavailableOffline, nil) - } - - transaction, err := s.i.GetBlockTransaction( - ctx, - request.BlockIdentifier, - request.TransactionIdentifier, - ) - if err != nil { - return nil, wrapErr(ErrTransactionNotFound, err) - } - - return &types.BlockTransactionResponse{ - Transaction: transaction, - }, nil + return nil, ErrUnimplemented } diff --git a/services/block_service_test.go b/services/block_service_test.go index 9510e9f..8f7787b 100644 --- a/services/block_service_test.go +++ b/services/block_service_test.go @@ -40,8 +40,8 @@ func TestBlockService_Offline(t *testing.T) { blockTransaction, err := servicer.BlockTransaction(ctx, &types.BlockTransactionRequest{}) assert.Nil(t, blockTransaction) - assert.Equal(t, ErrUnavailableOffline.Code, err.Code) - assert.Equal(t, ErrUnavailableOffline.Message, err.Message) + assert.Equal(t, ErrUnimplemented.Code, err.Code) + assert.Equal(t, ErrUnimplemented.Message, err.Message) mockIndexer.AssertExpectations(t) } @@ -54,51 +54,49 @@ func TestBlockService_Online(t *testing.T) { servicer := NewBlockAPIService(cfg, mockIndexer) ctx := context.Background() - block := &types.Block{ + rawBlock := &types.Block{ BlockIdentifier: &types.BlockIdentifier{ Index: 100, Hash: "block 100", }, } - blockResponse := &types.BlockResponse{ - Block: block, - OtherTransactions: []*types.TransactionIdentifier{ - { - Hash: "tx1", - }, - }, - } - transaction := &types.Transaction{ TransactionIdentifier: &types.TransactionIdentifier{ Hash: "tx1", }, } + block := &types.Block{ + BlockIdentifier: &types.BlockIdentifier{ + Index: 100, + Hash: "block 100", + }, + Transactions: []*types.Transaction{ + transaction, + }, + } + + blockResponse := &types.BlockResponse{ + Block: block, + } + t.Run("nil identifier", func(t *testing.T) { mockIndexer.On( "GetBlockLazy", ctx, (*types.PartialBlockIdentifier)(nil), ).Return( - blockResponse, + &types.BlockResponse{ + Block: rawBlock, + OtherTransactions: []*types.TransactionIdentifier{ + { + Hash: "tx1", + }, + }, + }, nil, ).Once() - b, err := servicer.Block(ctx, &types.BlockRequest{}) - assert.Nil(t, err) - assert.Equal(t, blockResponse, b) - }) - - t.Run("populated identifier", func(t *testing.T) { - pbIdentifier := types.ConstructPartialBlockIdentifier(block.BlockIdentifier) - mockIndexer.On("GetBlockLazy", ctx, pbIdentifier).Return(blockResponse, nil).Once() - b, err := servicer.Block(ctx, &types.BlockRequest{ - BlockIdentifier: pbIdentifier, - }) - assert.Nil(t, err) - assert.Equal(t, blockResponse, b) - mockIndexer.On( "GetBlockTransaction", ctx, @@ -108,12 +106,42 @@ func TestBlockService_Online(t *testing.T) { transaction, nil, ).Once() - blockTransaction, err := servicer.BlockTransaction(ctx, &types.BlockTransactionRequest{ - BlockIdentifier: blockResponse.Block.BlockIdentifier, - TransactionIdentifier: transaction.TransactionIdentifier, + b, err := servicer.Block(ctx, &types.BlockRequest{}) + assert.Nil(t, err) + assert.Equal(t, blockResponse, b) + }) + + t.Run("populated identifier", func(t *testing.T) { + pbIdentifier := types.ConstructPartialBlockIdentifier(block.BlockIdentifier) + mockIndexer.On( + "GetBlockLazy", + ctx, + pbIdentifier, + ).Return( + &types.BlockResponse{ + Block: rawBlock, + OtherTransactions: []*types.TransactionIdentifier{ + { + Hash: "tx1", + }, + }, + }, + nil, + ).Once() + mockIndexer.On( + "GetBlockTransaction", + ctx, + blockResponse.Block.BlockIdentifier, + transaction.TransactionIdentifier, + ).Return( + transaction, + nil, + ).Once() + b, err := servicer.Block(ctx, &types.BlockRequest{ + BlockIdentifier: pbIdentifier, }) assert.Nil(t, err) - assert.Equal(t, transaction, blockTransaction.Transaction) + assert.Equal(t, blockResponse, b) }) mockIndexer.AssertExpectations(t)