2019-11-28 16:06:09 +00:00
|
|
|
package state
|
2019-09-30 16:52:16 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
2020-03-26 14:43:24 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
2020-06-09 09:12:56 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
2019-09-30 16:52:16 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncodeDecodeContractState(t *testing.T) {
|
|
|
|
script := []byte("testscript")
|
|
|
|
|
2020-06-09 09:12:56 +00:00
|
|
|
h := hash.Hash160(script)
|
2020-11-20 08:02:58 +00:00
|
|
|
m := manifest.NewManifest(h, "Test")
|
2020-06-09 09:12:56 +00:00
|
|
|
m.ABI.Methods = []manifest.Method{{
|
|
|
|
Name: "main",
|
|
|
|
Parameters: []manifest.Parameter{
|
|
|
|
{
|
|
|
|
Name: "amount",
|
|
|
|
Type: smartcontract.IntegerType,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "hash",
|
|
|
|
Type: smartcontract.Hash160Type,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ReturnType: smartcontract.BoolType,
|
|
|
|
}}
|
2019-11-28 16:06:09 +00:00
|
|
|
contract := &Contract{
|
2020-06-09 09:12:56 +00:00
|
|
|
ID: 123,
|
|
|
|
Script: script,
|
|
|
|
Manifest: *m,
|
2019-09-30 16:52:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 09:12:56 +00:00
|
|
|
assert.Equal(t, h, contract.ScriptHash())
|
2019-10-10 14:56:58 +00:00
|
|
|
|
2020-06-09 09:12:56 +00:00
|
|
|
t.Run("Serializable", func(t *testing.T) {
|
|
|
|
contractDecoded := new(Contract)
|
|
|
|
testserdes.EncodeDecodeBinary(t, contract, contractDecoded)
|
|
|
|
assert.Equal(t, contract.ScriptHash(), contractDecoded.ScriptHash())
|
|
|
|
})
|
|
|
|
t.Run("JSON", func(t *testing.T) {
|
|
|
|
contractDecoded := new(Contract)
|
|
|
|
testserdes.MarshalUnmarshalJSON(t, contract, contractDecoded)
|
|
|
|
assert.Equal(t, contract.ScriptHash(), contractDecoded.ScriptHash())
|
|
|
|
})
|
2019-10-10 14:56:58 +00:00
|
|
|
}
|