Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Cannot request data if no raw request asked
Browse files Browse the repository at this point in the history
  • Loading branch information
taobun committed Jul 2, 2020
1 parent 44c4f1b commit 401e454
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Chain

- (bug) [\#2125](https://github.com/bandprotocol/bandchain/pull/2125) Fix request with duplicate external id and empty raw request bug.
- (impv/chore) [\#2124](https://github.com/bandprotocol/bandchain/pull/2124) Add genesis ds and os and move same test logic to testapp.
- (impv) [\#2113](https://github.com/bandprotocol/bandchain/pull/2113) Add tests in types and deactivate event for activate flow.
- (impv) [\#2109](https://github.com/bandprotocol/bandchain/pull/2109) Add Validator table and handle create validator message from genesis file and tx for emitter and flusher.
Expand Down
3 changes: 3 additions & 0 deletions chain/x/oracle/keeper/owasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (k Keeper) PrepareRequest(ctx sdk.Context, r types.RequestSpec) error {
}
// Preparation complete! It's time to collect raw request ids.
req.RawRequests = env.GetRawRequests()
if len(req.RawRequests) == 0 {
return types.ErrEmptyRawRequests
}
// We now have everything we need to the request, so let's add it to the store.
id := k.AddRequest(ctx, req)
// Emit an event describing a data request and asked validators.
Expand Down
15 changes: 15 additions & 0 deletions chain/x/oracle/keeper/owasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ func TestPrepareRequestGetOracleScriptFail(t *testing.T) {
require.Error(t, err)
}

func TestPrepareRequestWithEmptyRawRequest(t *testing.T) {
_, ctx, k := testapp.CreateTestInput()
ctx = ctx.WithBlockTime(time.Unix(1581589790, 0))

oracleScriptID := types.OracleScriptID(3)
calldata := []byte("test")
askCount := uint64(1)
minCount := uint64(2)
clientID := "beeb"

m := types.NewMsgRequestData(oracleScriptID, calldata, askCount, minCount, clientID, testapp.Alice.Address)
err := k.PrepareRequest(ctx, &m)
require.EqualError(t, err, "empty raw requests")
}

func TestPrepareRequestBadWasmExecutionFail(t *testing.T) {
_, ctx, k := testapp.CreateTestInput()
ctx = ctx.WithBlockTime(time.Unix(1581589790, 0))
Expand Down
1 change: 1 addition & 0 deletions chain/x/oracle/testapp/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func getGenesisOracleScripts() []types.OracleScript {
wasms := [][]byte{
Wasm1,
Wasm2,
Wasm3,
}
for idx := 0; idx < len(wasms); idx++ {
idxStr := fmt.Sprintf("%d", idx+1)
Expand Down
24 changes: 24 additions & 0 deletions chain/x/oracle/testapp/wasm_3_empty_raw_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package testapp

// A simple Owasm script with the following specification:
// PREPARE:
// DO NOTHING
// EXECUTE:
// CALL set_return_date with RETDATE "beeb"
var Wasm3 []byte = wat2wasm([]byte(`
(module
(type $t0 (func))
(type $t1 (func (param i64 i64 i64 i64)))
(type $t2 (func (param i64 i64)))
(import "env" "ask_external_data" (func $ask_external_data (type $t1)))
(import "env" "set_return_data" (func $set_return_data (type $t2)))
(func $prepare (export "prepare") (type $t0))
(func $execute (export "execute") (type $t0)
i32.const 1024
i64.extend_u/i32
i64.const 4
call $set_return_data)
(table $T0 1 1 anyfunc)
(memory $memory (export "memory") 17)
(data (i32.const 1024) "beeb"))
`))
21 changes: 11 additions & 10 deletions chain/x/oracle/types/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ var (
ErrInvalidAskCount = sdkerrors.Register(ModuleName, 25, "invalid ask count")
ErrTooLargeCalldata = sdkerrors.Register(ModuleName, 26, "too large calldata")
ErrTooLongClientID = sdkerrors.Register(ModuleName, 27, "too long client id")
ErrEmptyReport = sdkerrors.Register(ModuleName, 28, "empty report")
ErrDuplicateExternalID = sdkerrors.Register(ModuleName, 29, "duplicate external id")
ErrTooLongSchema = sdkerrors.Register(ModuleName, 30, "too long schema")
ErrTooLongURL = sdkerrors.Register(ModuleName, 31, "too long url")
ErrTooLargeRawReportData = sdkerrors.Register(ModuleName, 32, "too large raw report data")
ErrInsufficientValidators = sdkerrors.Register(ModuleName, 33, "insufficent available validators")
ErrCreateWithDoNotModify = sdkerrors.Register(ModuleName, 34, "cannot create with [do-not-modify] content")
ErrSelfReferenceAsReporter = sdkerrors.Register(ModuleName, 35, "cannot reference self as reporter")
ErrOBIDecode = sdkerrors.Register(ModuleName, 36, "obi decode failed")
ErrUncompressionFailed = sdkerrors.Register(ModuleName, 37, "uncompression failed")
ErrEmptyRawRequests = sdkerrors.Register(ModuleName, 28, "empty raw requests")
ErrEmptyReport = sdkerrors.Register(ModuleName, 29, "empty report")
ErrDuplicateExternalID = sdkerrors.Register(ModuleName, 30, "duplicate external id")
ErrTooLongSchema = sdkerrors.Register(ModuleName, 31, "too long schema")
ErrTooLongURL = sdkerrors.Register(ModuleName, 32, "too long url")
ErrTooLargeRawReportData = sdkerrors.Register(ModuleName, 33, "too large raw report data")
ErrInsufficientValidators = sdkerrors.Register(ModuleName, 34, "insufficent available validators")
ErrCreateWithDoNotModify = sdkerrors.Register(ModuleName, 35, "cannot create with [do-not-modify] content")
ErrSelfReferenceAsReporter = sdkerrors.Register(ModuleName, 36, "cannot reference self as reporter")
ErrOBIDecode = sdkerrors.Register(ModuleName, 37, "obi decode failed")
ErrUncompressionFailed = sdkerrors.Register(ModuleName, 38, "uncompression failed")
)

// WrapMaxError wraps an error message with additional info of the current and max values.
Expand Down

0 comments on commit 401e454

Please sign in to comment.