stackitem: introduce Convertible interface
We have a lot of native contract types that are converted to stack items before serialization, then deserialized as stack items and converted back to regular structures. stackitem.Convertible allows to remove a lot of repetitive io.Serializable code. This also introduces to/from converter in testserdes which unfortunately required to change util tests to avoid circular references.
This commit is contained in:
parent
2d993d0da5
commit
aab18c3083
23 changed files with 223 additions and 339 deletions
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEncodeDecodeContractState(t *testing.T) {
|
||||
func TestContractStateToFromSI(t *testing.T) {
|
||||
script := []byte("testscript")
|
||||
|
||||
h := hash.Hash160(script)
|
||||
|
@ -52,9 +52,9 @@ func TestEncodeDecodeContractState(t *testing.T) {
|
|||
}
|
||||
contract.NEF.Checksum = contract.NEF.CalculateChecksum()
|
||||
|
||||
t.Run("Serializable", func(t *testing.T) {
|
||||
t.Run("Convertible", func(t *testing.T) {
|
||||
contractDecoded := new(Contract)
|
||||
testserdes.EncodeDecodeBinary(t, contract, contractDecoded)
|
||||
testserdes.ToFromStackItem(t, contract, contractDecoded)
|
||||
})
|
||||
t.Run("JSON", func(t *testing.T) {
|
||||
contractDecoded := new(Contract)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue