rpc: add tests for getcontractstate RPC

This commit is contained in:
Anna Shaleva 2020-02-15 20:00:38 +03:00 committed by AnnaShaleva
parent 3c63ef3dc3
commit c99b42f738
4 changed files with 54 additions and 1 deletions

View file

@ -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()

View file

@ -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",

Binary file not shown.

BIN
pkg/rpc/testdata/testblocks.acc vendored Normal file

Binary file not shown.