2020-03-04 09:40:01 +00:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"testing"
|
|
|
|
|
2020-11-23 11:09:00 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/random"
|
|
|
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
2020-03-04 09:40:01 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-03-26 14:43:24 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
2020-03-04 09:40:01 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestContextItem_AddSignature(t *testing.T) {
|
|
|
|
item := &Item{Signatures: make(map[string][]byte)}
|
|
|
|
|
|
|
|
priv1, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pub1 := priv1.PublicKey()
|
|
|
|
sig1 := []byte{1, 2, 3}
|
|
|
|
item.AddSignature(pub1, sig1)
|
|
|
|
require.Equal(t, sig1, item.GetSignature(pub1))
|
|
|
|
|
|
|
|
priv2, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pub2 := priv2.PublicKey()
|
|
|
|
sig2 := []byte{5, 6, 7}
|
|
|
|
item.AddSignature(pub2, sig2)
|
|
|
|
require.Equal(t, sig2, item.GetSignature(pub2))
|
|
|
|
require.Equal(t, sig1, item.GetSignature(pub1))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContextItem_MarshalJSON(t *testing.T) {
|
|
|
|
priv1, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
priv2, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expected := &Item{
|
2021-03-03 12:52:33 +00:00
|
|
|
Script: []byte{1, 2, 3},
|
2020-03-04 09:40:01 +00:00
|
|
|
Parameters: []smartcontract.Parameter{{
|
|
|
|
Type: smartcontract.SignatureType,
|
2020-03-27 07:14:40 +00:00
|
|
|
Value: random.Bytes(64),
|
2020-03-04 09:40:01 +00:00
|
|
|
}},
|
|
|
|
Signatures: map[string][]byte{
|
2020-03-27 07:14:40 +00:00
|
|
|
hex.EncodeToString(priv1.PublicKey().Bytes()): random.Bytes(64),
|
|
|
|
hex.EncodeToString(priv2.PublicKey().Bytes()): random.Bytes(64),
|
2020-03-04 09:40:01 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-03-26 14:43:24 +00:00
|
|
|
testserdes.MarshalUnmarshalJSON(t, expected, new(Item))
|
2020-03-04 09:40:01 +00:00
|
|
|
}
|