oracle: implement filters

This commit is contained in:
Evgeniy Stratonikov 2021-01-22 17:32:29 +03:00
parent e4528e59dc
commit c420014cb5
6 changed files with 113 additions and 0 deletions

View file

@ -140,6 +140,10 @@ func TestOracle(t *testing.T) {
putOracleRequest(t, cs.Hash, bc, "http://get.maxallowed", nil, "handle", []byte{}, 10_000_000)
putOracleRequest(t, cs.Hash, bc, "http://get.maxallowed", nil, "handle", []byte{}, 100_000_000)
flt := "Values[1]"
putOracleRequest(t, cs.Hash, bc, "http://get.filter", &flt, "handle", []byte{}, 10_000_000)
putOracleRequest(t, cs.Hash, bc, "http://get.filterinv", &flt, "handle", []byte{}, 10_000_000)
checkResp := func(t *testing.T, id uint64, resp *transaction.OracleResponse) *state.OracleRequest {
req, err := oracleCtr.GetRequestInternal(bc.dao, id)
require.NoError(t, err)
@ -242,6 +246,19 @@ func TestOracle(t *testing.T) {
Result: make([]byte, transaction.MaxOracleResultSize),
})
})
t.Run("WithFilter", func(t *testing.T) {
checkResp(t, 10, &transaction.OracleResponse{
ID: 10,
Code: transaction.Success,
Result: []byte(`[2]`),
})
t.Run("invalid response", func(t *testing.T) {
checkResp(t, 11, &transaction.OracleResponse{
ID: 11,
Code: transaction.Error,
})
})
})
}
func TestOracleFull(t *testing.T) {
@ -354,6 +371,14 @@ func newDefaultHTTPClient() oracle.HTTPClient {
code: http.StatusOK,
body: make([]byte, transaction.MaxOracleResultSize),
},
"http://get.filter": {
code: http.StatusOK,
body: []byte(`{"Values":["one", 2, 3],"Another":null}`),
},
"http://get.filterinv": {
code: http.StatusOK,
body: []byte{0xFF},
},
},
}
}