diff --git a/pkg/rpc/server_helper_test.go b/pkg/rpc/server_helper_test.go index 369562930..b1fd3b491 100644 --- a/pkg/rpc/server_helper_test.go +++ b/pkg/rpc/server_helper_test.go @@ -13,6 +13,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/network" "github.com/CityOfZion/neo-go/pkg/rpc/result" "github.com/CityOfZion/neo-go/pkg/rpc/wrappers" + "github.com/CityOfZion/neo-go/pkg/util" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" ) @@ -150,6 +151,29 @@ type GetUnspents struct { ID int `json:"id"` } +// GetContractStateResponse struct for testing. +type GetContractStateResponce struct { + Jsonrpc string `json:"jsonrpc"` + Result struct { + Version byte `json:"version"` + ScriptHash util.Uint160 `json:"hash"` + Script []byte `json:"script"` + ParamList interface{} `json:"parameters"` + ReturnType interface{} `json:"returntype"` + Name string `json:"name"` + CodeVersion string `json:"code_version"` + Author string `json:"author"` + Email string `json:"email"` + Description string `json:"description"` + Properties struct { + HasStorage bool `json:"storage"` + HasDynamicInvoke bool `json:"dynamic_invoke"` + IsPayable bool `json:"is_payable"` + } `json:"properties"` + } `json:"result"` + ID int `json:"id"` +} + func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, http.HandlerFunc) { var nBlocks uint32 @@ -165,7 +189,7 @@ func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, http.HandlerFu go chain.Run() - f, err := os.Open("testdata/50testblocks.acc") + f, err := os.Open("testdata/testblocks.acc") require.Nil(t, err) br := io.NewBinReaderFromIO(f) nBlocks = br.ReadU32LE() diff --git a/pkg/rpc/server_test.go b/pkg/rpc/server_test.go index dac20d31e..a0c83480a 100644 --- a/pkg/rpc/server_test.go +++ b/pkg/rpc/server_test.go @@ -72,6 +72,35 @@ var rpcTestCases = map[string][]rpcTestCase{ fail: true, }, }, + "getcontractstate": { + { + name: "positive", + params: `["6d1eeca891ee93de2b7a77eb91c26f3b3c04d6cf"]`, + result: func(e *executor) interface{} { return &GetContractStateResponce{} }, + check: func(t *testing.T, e *executor, result interface{}) { + res, ok := result.(*GetContractStateResponce) + require.True(t, ok) + assert.Equal(t, byte(0), res.Result.Version) + assert.Equal(t, util.Uint160{0x6d, 0x1e, 0xec, 0xa8, 0x91, 0xee, 0x93, 0xde, 0x2b, 0x7a, 0x77, 0xeb, 0x91, 0xc2, 0x6f, 0x3b, 0x3c, 0x4, 0xd6, 0xcf}, res.Result.ScriptHash) + assert.Equal(t, "0.99", res.Result.CodeVersion) + }, + }, + { + name: "negative", + params: `["6d1eeca891ee93de2b7a77eb91c26f3b3c04d6c3"]`, + fail: true, + }, + { + name: "no params", + params: `[]`, + fail: true, + }, + { + name: "invalid hash", + params: `["notahex"]`, + fail: true, + }, + }, "getassetstate": { { name: "positive", diff --git a/pkg/rpc/testdata/50testblocks.acc b/pkg/rpc/testdata/50testblocks.acc deleted file mode 100644 index 91825648d..000000000 Binary files a/pkg/rpc/testdata/50testblocks.acc and /dev/null differ diff --git a/pkg/rpc/testdata/testblocks.acc b/pkg/rpc/testdata/testblocks.acc new file mode 100644 index 000000000..3f63e2bdc Binary files /dev/null and b/pkg/rpc/testdata/testblocks.acc differ