diff --git a/rpc/codec.go b/rpc/codec.go deleted file mode 100644 index 750a5a88e8a6ea672fe635ef41c2f69d2c36274d..0000000000000000000000000000000000000000 --- a/rpc/codec.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017 Monax Industries Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rpc - -import ( - "io" -) - -// Used for rpc request and response data. -type Codec interface { - EncodeBytes(interface{}) ([]byte, error) - Encode(interface{}, io.Writer) error - DecodeBytes(interface{}, []byte) error - DecodeBytesPtr(interface{}, []byte) error - Decode(interface{}, io.Reader) error -} diff --git a/rpc/jsonrpc.go b/rpc/rpc.go similarity index 86% rename from rpc/jsonrpc.go rename to rpc/rpc.go index fc04317a43ebd77faa3850e9f781fedb1e627143..a42e57c0ca349f11cc007fffaf3556e5c9128787 100644 --- a/rpc/jsonrpc.go +++ b/rpc/rpc.go @@ -16,6 +16,7 @@ package rpc import ( "encoding/json" + "io" ) // JSON-RPC 2.0 error codes. @@ -64,8 +65,26 @@ type ( // Note: Data is currently unused, and the data member may be omitted // Data interface{} `json:"data"` } + + Codec interface { + EncodeBytes(interface{}) ([]byte, error) + Encode(interface{}, io.Writer) error + DecodeBytes(interface{}, []byte) error + Decode(interface{}, io.Reader) error + } ) +// Create a new RPC request. This is the generic struct that is passed to RPC +// methods +func NewRPCRequest(id string, method string, params json.RawMessage) *RPCRequest { + return &RPCRequest{ + JSONRPC: "2.0", + Id: id, + Method: method, + Params: params, + } +} + // NewRPCResponse creates a new response object from a result func NewRPCResponse(id string, res interface{}) RPCResponse { return RPCResponse(&RPCResultResponse{ diff --git a/rpc/tendermint/test/rpc_client_test.go b/rpc/tendermint/test/rpc_client_test.go index d53ff9d713ffcee49a4646c7d303fd55a42a51ec..80f0f250868d2b77f22ad709e3e784eaf93b73da 100644 --- a/rpc/tendermint/test/rpc_client_test.go +++ b/rpc/tendermint/test/rpc_client_test.go @@ -20,10 +20,11 @@ package test import ( "bytes" "fmt" - "golang.org/x/crypto/ripemd160" "testing" "time" + "golang.org/x/crypto/ripemd160" + consensus_types "github.com/eris-ltd/eris-db/consensus/types" edbcli "github.com/eris-ltd/eris-db/rpc/tendermint/client" "github.com/eris-ltd/eris-db/txs" diff --git a/rpc/v0/codec.go b/rpc/v0/codec.go index 344c1c98f12977352419dcd1247659b0de59e4ec..ecc01f823b441bd119d45560a4ffe25fe4bbe2de 100644 --- a/rpc/v0/codec.go +++ b/rpc/v0/codec.go @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 import ( "io" "io/ioutil" - wire "github.com/tendermint/go-wire" + "reflect" - rpc "github.com/eris-ltd/eris-db/rpc" + "github.com/eris-ltd/eris-db/rpc" + wire "github.com/tendermint/go-wire" ) // Codec that uses tendermints 'binary' package for JSON. @@ -45,8 +46,6 @@ func (this *TCodec) EncodeBytes(v interface{}) ([]byte, error) { return wire.JSONBytes(v), nil } -// TODO: [ben] implement EncodeBytesPtr ? - // Decode from an io.Reader. func (this *TCodec) Decode(v interface{}, r io.Reader) error { bts, errR := ioutil.ReadAll(r) @@ -61,13 +60,11 @@ func (this *TCodec) Decode(v interface{}, r io.Reader) error { // Decode from a byte array. func (this *TCodec) DecodeBytes(v interface{}, bts []byte) error { var err error - wire.ReadJSON(v, bts, &err) - return err -} - -// Decode from a byte array pointer. -func (this *TCodec) DecodeBytesPtr(v interface{}, bts []byte) error { - var err error - wire.ReadJSONPtr(v, bts, &err) + rv := reflect.ValueOf(v) + if rv.Kind() == reflect.Ptr { + wire.ReadJSONPtr(v, bts, &err) + } else { + wire.ReadJSON(v, bts, &err) + } return err } diff --git a/rpc/v0/json_service_data_test.go b/rpc/v0/codec_test.go similarity index 96% rename from rpc/v0/json_service_data_test.go rename to rpc/v0/codec_test.go index 96be04138a4d5399650a4ae00570049754600b88..c300ee649838e20ac3035b2731623b556f5556a4 100644 --- a/rpc/v0/json_service_data_test.go +++ b/rpc/v0/codec_test.go @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 import ( "encoding/json" "testing" - "github.com/eris-ltd/eris-db/rpc" "github.com/eris-ltd/eris-db/txs" + "github.com/eris-ltd/eris-db/rpc" "github.com/stretchr/testify/assert" ) @@ -64,7 +64,7 @@ func TestCallTxJsonFormatCodec(t *testing.T) { request := &rpc.RPCRequest{} assert.NoError(t, json.Unmarshal(testBroadcastCallTxJsonRequest, request), "Provided JSON test data does not unmarshal to rpc.RPCRequest object.") - assert.NoError(t, codec.DecodeBytesPtr(param, request.Params), + assert.NoError(t, codec.DecodeBytes(param, request.Params), "RPC codec failed to decode params as transaction type.") _, ok := (*param).(*txs.CallTx) assert.True(t, ok, "Type byte 0x02 should unmarshal into CallTx.") diff --git a/rpc/v0/json_service.go b/rpc/v0/json_rpc_server.go similarity index 99% rename from rpc/v0/json_service.go rename to rpc/v0/json_rpc_server.go index 77bc4ffaa32a8c6e6e6f38104ecf440494b5951e..d8a8bf8f3901fe41c78fea4fb26758de77046a16 100644 --- a/rpc/v0/json_service.go +++ b/rpc/v0/json_rpc_server.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 import ( "encoding/json" @@ -22,7 +22,7 @@ import ( definitions "github.com/eris-ltd/eris-db/definitions" event "github.com/eris-ltd/eris-db/event" - rpc "github.com/eris-ltd/eris-db/rpc" + "github.com/eris-ltd/eris-db/rpc" server "github.com/eris-ltd/eris-db/server" ) diff --git a/rpc/v0/json_rpc_server_test.go b/rpc/v0/json_rpc_server_test.go new file mode 100644 index 0000000000000000000000000000000000000000..fb5a41ec03ca38448c2061c1174819f1a3536f78 --- /dev/null +++ b/rpc/v0/json_rpc_server_test.go @@ -0,0 +1,50 @@ +// Copyright 2017 Monax Industries Limited +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v0 + +import ( + "testing" + + "github.com/eris-ltd/eris-db/account" + "github.com/eris-ltd/eris-db/manager/eris-mint/evm/opcodes" + "github.com/eris-ltd/eris-db/rpc" + "github.com/eris-ltd/eris-db/txs" + "github.com/stretchr/testify/assert" + "github.com/tendermint/go-wire" +) + +func TestBroadcastTx(t *testing.T) { + testData := LoadTestData() + pipe := NewMockPipe(testData) + methods := NewErisDbMethods(NewTCodec(), pipe) + pubKey := account.GenPrivAccount().PubKey + address := []byte{1} + code := opcodes.Bytecode(opcodes.PUSH1, 1, opcodes.PUSH1, 1, opcodes.ADD) + var tx txs.Tx = txs.NewCallTxWithNonce(pubKey, address, code, 10, 2, + 1, 0) + jsonBytes := wire.JSONBytesPretty(wrappedTx{tx}) + request := rpc.NewRPCRequest("TestBroadcastTx", "BroacastTx", jsonBytes) + result, _, err := methods.BroadcastTx(request, "TestBroadcastTx") + assert.NoError(t, err) + receipt, ok := result.(*txs.Receipt) + assert.True(t, ok, "Should get Receipt pointer") + assert.Equal(t, txs.TxHash(testData.GetChainId.Output.ChainId, tx), receipt.TxHash) +} + +// Allows us to get the type byte included but then omit the outer struct and +// embedded field +type wrappedTx struct { + txs.Tx `json:"unwrap"` +} diff --git a/rpc/rpc_test.go b/rpc/v0/json_rpc_test.go similarity index 78% rename from rpc/rpc_test.go rename to rpc/v0/json_rpc_test.go index fbdfca374c8cd4a764ea064d06e74ce5b5ca0e4b..27ef8f455a8e541b2136248ccd965d05f42524e1 100644 --- a/rpc/rpc_test.go +++ b/rpc/v0/json_rpc_test.go @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc +package v0 import ( "testing" + "github.com/eris-ltd/eris-db/rpc" "github.com/stretchr/testify/assert" ) @@ -24,12 +25,12 @@ import ( func TestNewJsonRpcResponse(t *testing.T) { id := "testId" data := "a string" - resp := RPCResponse(&RPCResultResponse{ + resp := rpc.RPCResponse(&rpc.RPCResultResponse{ Result: data, Id: id, JSONRPC: "2.0", }) - respGen := NewRPCResponse(id, data) + respGen := rpc.NewRPCResponse(id, data) assert.Equal(t, respGen, resp) } @@ -38,11 +39,11 @@ func TestNewJsonRpcErrorResponse(t *testing.T) { id := "testId" code := 100 message := "the error" - resp := RPCResponse(&RPCErrorResponse{ - Error: &RPCError{code, message}, + resp := rpc.RPCResponse(&rpc.RPCErrorResponse{ + Error: &rpc.RPCError{code, message}, Id: id, JSONRPC: "2.0", }) - respGen := NewRPCErrorResponse(id, code, message) + respGen := rpc.NewRPCErrorResponse(id, code, message) assert.Equal(t, respGen, resp) } diff --git a/rpc/v0/methods.go b/rpc/v0/methods.go index 6a26848cc8f3a6cb38afe01b704a19d98f57c611..93db17522a556477b09d538de4a1a52ec16ee8ec 100644 --- a/rpc/v0/methods.go +++ b/rpc/v0/methods.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 import ( "github.com/eris-ltd/eris-db/blockchain" @@ -359,13 +359,12 @@ func (erisDbMethods *ErisDbMethods) CallCode(request *rpc.RPCRequest, requester } func (erisDbMethods *ErisDbMethods) BroadcastTx(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { - // Accept all transaction types as parameter for broadcast. - param := new(txs.Tx) - err := erisDbMethods.codec.DecodeBytesPtr(param, request.Params) + tx := new(txs.Tx) + err := erisDbMethods.codec.DecodeBytes(tx, request.Params) if err != nil { return nil, rpc.INVALID_PARAMS, err } - receipt, errC := erisDbMethods.pipe.Transactor().BroadcastTx(*param) + receipt, errC := erisDbMethods.pipe.Transactor().BroadcastTx(*tx) if errC != nil { return nil, rpc.INTERNAL_ERROR, errC } diff --git a/rpc/v0/restServer_pipe_test.go b/rpc/v0/mock_pipe_test.go similarity index 95% rename from rpc/v0/restServer_pipe_test.go rename to rpc/v0/mock_pipe_test.go index 6b084b9edb23b07c8976b912cbc25a426559caf6..6bb864d51f9cc57f42c2cdfbf56e7896ea088fca 100644 --- a/rpc/v0/restServer_pipe_test.go +++ b/rpc/v0/mock_pipe_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 import ( "fmt" @@ -36,7 +36,7 @@ import ( // Base struct. type MockPipe struct { - testData *TestData + testData TestData accounts definitions.Accounts blockchain blockchain_types.Blockchain consensusEngine consensus_types.ConsensusEngine @@ -49,9 +49,9 @@ type MockPipe struct { // Create a new mock tendermint pipe. func NewMockPipe(td *TestData) definitions.Pipe { return &MockPipe{ - testData: td, + testData: *td, accounts: &accounts{td}, - blockchain: &mockBlockchain{td}, + blockchain: &chain{td}, consensusEngine: &consensusEngine{td}, events: &eventer{td}, namereg: &namereg{td}, @@ -152,23 +152,23 @@ func (acc *accounts) StorageAt(address, key []byte) (*core_types.StorageItem, er } // Blockchain -type mockBlockchain struct { +type chain struct { testData *TestData } -func (this *mockBlockchain) ChainId() string { +func (this *chain) ChainId() string { return this.testData.GetChainId.Output.ChainId } -func (this *mockBlockchain) Height() int { +func (this *chain) Height() int { return this.testData.GetLatestBlockHeight.Output.Height } -func (this *mockBlockchain) Block(height int) *mintTypes.Block { +func (this *chain) Block(height int) *mintTypes.Block { return this.testData.GetBlock.Output } -func (this *mockBlockchain) BlockMeta(height int) *mintTypes.BlockMeta { +func (this *chain) BlockMeta(height int) *mintTypes.BlockMeta { return &mintTypes.BlockMeta{} } @@ -276,7 +276,8 @@ func (trans *transactor) CallCode(from, code, data []byte) (*core_types.Call, er } func (trans *transactor) BroadcastTx(tx txs.Tx) (*txs.Receipt, error) { - return nil, nil + receipt := txs.GenerateReceipt(trans.testData.GetChainId.Output.ChainId, tx) + return &receipt, nil } func (trans *transactor) Transact(privKey, address, data []byte, gasLimit, fee int64) (*txs.Receipt, error) { diff --git a/rpc/v0/restServer_data_test.go b/rpc/v0/mock_test_data_test.go similarity index 99% rename from rpc/v0/restServer_data_test.go rename to rpc/v0/mock_test_data_test.go index 31fbaeb3b169dc78bbb76fe6700c4698843b2a4a..c62c6f6224563df088874f6863a2c47817e6cc41 100644 --- a/rpc/v0/restServer_data_test.go +++ b/rpc/v0/mock_test_data_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 import ( account "github.com/eris-ltd/eris-db/account" diff --git a/rpc/v0/params.go b/rpc/v0/params.go index e6f565557ea65247391e8532b282e3fbe80383d8..a33665c429d9b8fe7370ad98308dcfe4313362a6 100644 --- a/rpc/v0/params.go +++ b/rpc/v0/params.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 import ( "github.com/eris-ltd/eris-db/account" diff --git a/rpc/v0/restServer.go b/rpc/v0/rest_server.go similarity index 99% rename from rpc/v0/restServer.go rename to rpc/v0/rest_server.go index 18fb507ec3569df4699af3172eccf7c9d6910471..bc89b4225f25e1efb3ed038691dd7f1f8fe62ddc 100644 --- a/rpc/v0/restServer.go +++ b/rpc/v0/rest_server.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 import ( "encoding/hex" diff --git a/rpc/v0/restServer_test.go b/rpc/v0/rest_server_test.go similarity index 99% rename from rpc/v0/restServer_test.go rename to rpc/v0/rest_server_test.go index 7cdf28039bd5fd11bd5d76201961710eb7867963..b0f070349a89819ade18837c9683804c3975a57e 100644 --- a/rpc/v0/restServer_test.go +++ b/rpc/v0/rest_server_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 // Basic imports import ( @@ -28,10 +28,10 @@ import ( account "github.com/eris-ltd/eris-db/account" core_types "github.com/eris-ltd/eris-db/core/types" event "github.com/eris-ltd/eris-db/event" - rpc "github.com/eris-ltd/eris-db/rpc" server "github.com/eris-ltd/eris-db/server" "github.com/eris-ltd/eris-db/txs" + "github.com/eris-ltd/eris-db/rpc" "github.com/eris-ltd/eris-db/rpc/v0/shared" "github.com/gin-gonic/gin" "github.com/stretchr/testify/suite" diff --git a/rpc/v0/wsService.go b/rpc/v0/websocket_service.go similarity index 91% rename from rpc/v0/wsService.go rename to rpc/v0/websocket_service.go index daea0d01b75844cf3d19aaba958ed8bff9cf6308..d5985941725da123991302d52ca51ec6e75f2db1 100644 --- a/rpc/v0/wsService.go +++ b/rpc/v0/websocket_service.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rpc_v0 +package v0 import ( "encoding/json" @@ -20,7 +20,7 @@ import ( definitions "github.com/eris-ltd/eris-db/definitions" "github.com/eris-ltd/eris-db/event" - rpc "github.com/eris-ltd/eris-db/rpc" + "github.com/eris-ltd/eris-db/rpc" server "github.com/eris-ltd/eris-db/server" "github.com/eris-ltd/eris-db/txs" ) @@ -54,13 +54,15 @@ func (this *ErisDbWsService) Process(msg []byte, session *server.WSSession) { // Error when unmarshaling. if errU != nil { - this.writeError("Failed to parse request: "+errU.Error()+" . Raw: "+string(msg), "", rpc.PARSE_ERROR, session) + this.writeError("Failed to parse request: "+errU.Error()+" . Raw: "+string(msg), + "", rpc.PARSE_ERROR, session) return } // Wrong protocol version. if req.JSONRPC != "2.0" { - this.writeError("Wrong protocol version: "+req.JSONRPC, req.Id, rpc.INVALID_REQUEST, session) + this.writeError("Wrong protocol version: "+req.JSONRPC, req.Id, + rpc.INVALID_REQUEST, session) return } @@ -74,7 +76,8 @@ func (this *ErisDbWsService) Process(msg []byte, session *server.WSSession) { this.writeResponse(req.Id, resp, session) } } else { - this.writeError("Method not found: "+mName, req.Id, rpc.METHOD_NOT_FOUND, session) + this.writeError("Method not found: "+mName, req.Id, + rpc.METHOD_NOT_FOUND, session) } } @@ -132,7 +135,8 @@ func (this *ErisDbWsService) EventSubscribe(request *rpc.RPCRequest, return &event.EventSub{subId}, 0, nil } -func (this *ErisDbWsService) EventUnsubscribe(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbWsService) EventUnsubscribe(request *rpc.RPCRequest, + requester interface{}) (interface{}, int, error) { param := &EventIdParam{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { @@ -147,6 +151,7 @@ func (this *ErisDbWsService) EventUnsubscribe(request *rpc.RPCRequest, requester return &event.EventUnsub{true}, 0, nil } -func (this *ErisDbWsService) EventPoll(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { +func (this *ErisDbWsService) EventPoll(request *rpc.RPCRequest, + requester interface{}) (interface{}, int, error) { return nil, rpc.INTERNAL_ERROR, fmt.Errorf("Cannot poll with websockets") } diff --git a/test/server/scumbag.go b/test/server/scumbag.go index 67751442e23b3b5ad948fb0b88ce33a8758ab9f3..3d153b322bdbdf3f67d3b0d6c5f63ac685c9dafc 100644 --- a/test/server/scumbag.go +++ b/test/server/scumbag.go @@ -19,10 +19,10 @@ import ( "os" "runtime" - rpc "github.com/eris-ltd/eris-db/rpc" "github.com/eris-ltd/eris-db/server" "github.com/gin-gonic/gin" "github.com/tendermint/log15" + "github.com/eris-ltd/eris-db/rpc" ) func init() { diff --git a/test/testdata/filters/testdata_filters.g_ b/test/testdata/filters/testdata_filters.g_ deleted file mode 100644 index fefc112eb2dc53dd94108d9e8db4cedeaca996e3..0000000000000000000000000000000000000000 --- a/test/testdata/filters/testdata_filters.g_ +++ /dev/null @@ -1,299 +0,0 @@ -package filters - -import ( - core_types "github.com/eris-ltd/eris-db/core/types" - - stypes "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" - "github.com/tendermint/tendermint/types" -) - -var testDataJson = `{ - "chain_data": { - "priv_validator": { - "address": "37236DF251AB70022B1DA351F08A20FB52443E37", - "pub_key": [1, "CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"], - "priv_key": [1, "6B72D45EB65F619F11CE580C8CAED9E0BADC774E9C9C334687A65DCBAD2C4151CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"], - "last_height": 0, - "last_round": 0, - "last_step": 0 - }, - "genesis": { - "chain_id": "my_tests", - "accounts": [ - { - "address": "1000000000000000000000000000000000000000", - "amount": 0 - }, - { - "address": "0000000000000000000000000000000000000001", - "amount": 1 - }, - { - "address": "0000000000000000000000000000000000000002", - "amount": 2 - }, - { - "address": "0000000000000000000000000000000000000003", - "amount": 3 - }, - { - "address": "0000000000000000000000000000000000000004", - "amount": 4 - }, - { - "address": "0000000000000000000000000000000000000005", - "amount": 5 - }, - { - "address": "0000000000000000000000000000000000000006", - "amount": 6 - }, - { - "address": "0000000000000000000000000000000000000007", - "amount": 7 - }, - { - "address": "0000000000000000000000000000000000000008", - "amount": 8 - }, - { - "address": "0000000000000000000000000000000000000009", - "amount": 9 - }, - { - "address": "000000000000000000000000000000000000000A", - "amount": 10 - }, - { - "address": "000000000000000000000000000000000000000B", - "amount": 11 - }, - { - "address": "000000000000000000000000000000000000000C", - "amount": 12 - }, - { - "address": "000000000000000000000000000000000000000D", - "amount": 13 - }, - { - "address": "000000000000000000000000000000000000000E", - "amount": 14 - }, - { - "address": "000000000000000000000000000000000000000F", - "amount": 15 - } - ], - "validators": [ - { - "pub_key": "CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906", - "amount": 5000000000, - "unbond_to": [ - { - "address": "93E243AC8A01F723DE353A4FA1ED911529CCB6E5", - "amount": 5000000000 - } - ] - } - ] - } - }, - "GetAccounts0": { - "input": [ - { - "field": "balance", - "op": "==", - "value": "0" - } - ], - "output": { - "accounts": [ - { - "address": "1000000000000000000000000000000000000000", - "pub_key": null, - "sequence": 0, - "balance": 0, - "code": "", - "storage_root": "", - "permissions": { - "base": { - "perms": 0, - "set": 0 - }, - "roles": [] - } - } - ] - } - }, - "GetAccounts1": { - "input": [ - { - "field": "balance", - "op": ">", - "value": "12" - } - ], - "output": { - "accounts": [ - { - "address": "0000000000000000000000000000000000000000", - "pub_key": null, - "sequence": 0, - "balance": 1337, - "code": "", - "storage_root": "", - "permissions": { - "base": { - "perms": 2302, - "set": 16383 - }, - "roles": [ - - ] - } - }, - { - "address": "000000000000000000000000000000000000000D", - "pub_key": null, - "sequence": 0, - "balance": 13, - "code": "", - "storage_root": "", - "permissions": { - "base": { - "perms": 0, - "set": 0 - }, - "roles": [] - } - }, - { - "address": "000000000000000000000000000000000000000E", - "pub_key": null, - "sequence": 0, - "balance": 14, - "code": "", - "storage_root": "", - "permissions": { - "base": { - "perms": 0, - "set": 0 - }, - "roles": [] - } - }, - { - "address": "000000000000000000000000000000000000000F", - "pub_key": null, - "sequence": 0, - "balance": 15, - "code": "", - "storage_root": "", - "permissions": { - "base": { - "perms": 0, - "set": 0 - }, - "roles": [] - } - } - ] - } - }, - "GetAccounts2": { - "input": [ - { - "field": "balance", - "op": ">=", - "value": "5" - }, - { - "field": "balance", - "op": "<", - "value": "8" - } - ], - "output": { - "accounts": [ - { - "address": "0000000000000000000000000000000000000005", - "pub_key": null, - "sequence": 0, - "balance": 5, - "code": "", - "storage_root": "", - "permissions": { - "base": { - "perms": 0, - "set": 0 - }, - "roles": [] - } - }, - { - "address": "0000000000000000000000000000000000000006", - "pub_key": null, - "sequence": 0, - "balance": 6, - "code": "", - "storage_root": "", - "permissions": { - "base": { - "perms": 0, - "set": 0 - }, - "roles": [] - } - }, - { - "address": "0000000000000000000000000000000000000007", - "pub_key": null, - "sequence": 0, - "balance": 7, - "code": "", - "storage_root": "", - "permissions": { - "base": { - "perms": 0, - "set": 0 - }, - "roles": [] - } - } - ] - } - } -}` - -var serverDuration uint = 100 - -type ( - ChainData struct { - PrivValidator *types.PrivValidator `json:"priv_validator"` - Genesis *stypes.GenesisDoc `json:"genesis"` - } - - GetAccountData struct { - Input []*event.FilterData `json:"input"` - Output *core_types.AccountList `json:"output"` - } - - TestData struct { - ChainData *ChainData `json:"chain_data"` - GetAccounts0 *GetAccountData - GetAccounts1 *GetAccountData - GetAccounts2 *GetAccountData - } -) - -func LoadTestData() *TestData { - codec := core_types.NewTCodec() - testData := &TestData{} - err := codec.DecodeBytes(testData, []byte(testDataJson)) - if err != nil { - panic(err) - } - return testData -}