Skip to content

Commit

Permalink
Merge pull request #1530 from orbs-network/bugfix/run-query-for-speci…
Browse files Browse the repository at this point in the history
…fic-block-height

Return error for queries with specific block height
  • Loading branch information
Kirill Maksimov authored Feb 4, 2020
2 parents 33c9e0c + b90999c commit 59b3464
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
16 changes: 11 additions & 5 deletions services/virtualmachine/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,21 @@ func NewVirtualMachine(
func (s *service) ProcessQuery(ctx context.Context, input *services.ProcessQueryInput) (*services.ProcessQueryOutput, error) {
logger := s.logger.WithTags(trace.LogFieldFrom(ctx))

if input.BlockHeight != 0 {
panic("Run local method with specific block height is not yet supported")
}

committedBlockHeight, committedBlockTimestamp, committedBlockProposerAddress, err := s.getRecentCommittedBlockInfo(ctx)
if err != nil {
return &services.ProcessQueryOutput{
CallResult: protocol.EXECUTION_RESULT_ERROR_UNEXPECTED,
OutputArgumentArray: []byte{},
OutputArgumentArray: protocol.ArgumentsArrayEmpty().Raw(),
ReferenceBlockHeight: committedBlockHeight,
ReferenceBlockTimestamp: committedBlockTimestamp,
}, err
}

if input.BlockHeight != 0 {
err := errors.New("Run local method with specific block height is not yet supported")
return &services.ProcessQueryOutput{
CallResult: protocol.EXECUTION_RESULT_ERROR_INPUT,
OutputArgumentArray: protocol.ArgumentsArrayEmpty().Raw(),
ReferenceBlockHeight: committedBlockHeight,
ReferenceBlockTimestamp: committedBlockTimestamp,
}, err
Expand Down
28 changes: 28 additions & 0 deletions services/virtualmachine/test/process_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/orbs-network/orbs-network-go/test/with"
"github.com/orbs-network/orbs-spec/types/go/primitives"
"github.com/orbs-network/orbs-spec/types/go/protocol"
"github.com/orbs-network/orbs-spec/types/go/services"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"testing"
Expand Down Expand Up @@ -95,3 +96,30 @@ func TestProcessQuery_UnexpectedError(t *testing.T) {
})
})
}

func TestProcessQuery_WithSpecificBlockHeight(t *testing.T) {
with.Context(func(ctx context.Context) {
with.Logging(t, func(parent *with.LoggingHarness) {

h := newHarness(parent.Logger)

h.expectStateStorageLastCommittedBlockInfoBlockHeightRequested(12)
output, err := h.service.ProcessQuery(ctx, &services.ProcessQueryInput{
BlockHeight: 123,
SignedQuery: (&protocol.SignedQueryBuilder{
Query: &protocol.QueryBuilder{
Signer: nil,
ContractName: "SomeContract",
MethodName: "SomeMethod",
InputArgumentArray: []byte{},
},
}).Build(),
})

require.Error(t, err, "Run local method with specific block height is not yet supported")
require.EqualValues(t, protocol.EXECUTION_RESULT_ERROR_INPUT, output.CallResult)
require.EqualValues(t, 12, output.ReferenceBlockHeight)
h.verifyStateStorageBlockHeightRequested(t)
})
})
}

0 comments on commit 59b3464

Please sign in to comment.