2020-04-30 13:00:33 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-11-23 11:09:00 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
2022-04-27 09:46:43 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-04-30 13:00:33 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2022-04-27 09:46:43 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-04-30 13:00:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCosignerEncodeDecode(t *testing.T) {
|
2022-04-27 09:46:43 +00:00
|
|
|
pk, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
2020-07-29 16:57:38 +00:00
|
|
|
expected := &Signer{
|
2020-04-30 13:00:33 +00:00
|
|
|
Account: util.Uint160{1, 2, 3, 4, 5},
|
2022-04-27 09:46:43 +00:00
|
|
|
Scopes: CustomContracts | CustomGroups | Rules,
|
2020-04-30 13:00:33 +00:00
|
|
|
AllowedContracts: []util.Uint160{{1, 2, 3, 4}, {6, 7, 8, 9}},
|
2022-04-27 09:46:43 +00:00
|
|
|
AllowedGroups: []*keys.PublicKey{pk.PublicKey()},
|
|
|
|
Rules: []WitnessRule{{Action: WitnessAllow, Condition: ConditionCalledByEntry{}}},
|
2020-04-30 13:00:33 +00:00
|
|
|
}
|
2020-07-29 16:57:38 +00:00
|
|
|
actual := &Signer{}
|
2020-04-30 13:00:33 +00:00
|
|
|
testserdes.EncodeDecodeBinary(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCosignerMarshallUnmarshallJSON(t *testing.T) {
|
2020-07-29 16:57:38 +00:00
|
|
|
expected := &Signer{
|
2020-04-30 13:00:33 +00:00
|
|
|
Account: util.Uint160{1, 2, 3, 4, 5},
|
|
|
|
Scopes: CustomContracts,
|
|
|
|
AllowedContracts: []util.Uint160{{1, 2, 3, 4}, {6, 7, 8, 9}},
|
|
|
|
}
|
2020-07-29 16:57:38 +00:00
|
|
|
actual := &Signer{}
|
2020-04-30 13:00:33 +00:00
|
|
|
testserdes.MarshalUnmarshalJSON(t, expected, actual)
|
|
|
|
}
|
2024-04-27 17:16:05 +00:00
|
|
|
|
|
|
|
func TestSignerCopy(t *testing.T) {
|
|
|
|
pk, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, (*Signer)(nil).Copy())
|
|
|
|
|
|
|
|
original := &Signer{
|
|
|
|
Account: util.Uint160{1, 2, 3, 4, 5},
|
|
|
|
Scopes: CustomContracts | CustomGroups | Rules,
|
|
|
|
AllowedContracts: []util.Uint160{{1, 2, 3, 4}, {6, 7, 8, 9}},
|
|
|
|
AllowedGroups: keys.PublicKeys{pk.PublicKey()},
|
|
|
|
Rules: []WitnessRule{{Action: WitnessAllow, Condition: ConditionCalledByEntry{}}},
|
|
|
|
}
|
|
|
|
|
|
|
|
cp := original.Copy()
|
|
|
|
require.NotNil(t, cp, "Copied Signer should not be nil")
|
|
|
|
|
|
|
|
require.Equal(t, original.Account, cp.Account)
|
|
|
|
require.Equal(t, original.Scopes, cp.Scopes)
|
|
|
|
|
|
|
|
require.NotSame(t, original.AllowedContracts, cp.AllowedContracts)
|
|
|
|
require.Equal(t, original.AllowedContracts, cp.AllowedContracts)
|
|
|
|
|
|
|
|
require.NotSame(t, original.AllowedGroups, cp.AllowedGroups)
|
|
|
|
require.Equal(t, original.AllowedGroups, cp.AllowedGroups)
|
|
|
|
|
|
|
|
require.NotSame(t, original.Rules, cp.Rules)
|
|
|
|
require.Equal(t, original.Rules, cp.Rules)
|
|
|
|
|
|
|
|
original.AllowedContracts[0][0] = 255
|
|
|
|
original.AllowedGroups[0] = nil
|
|
|
|
original.Rules[0].Action = WitnessDeny
|
|
|
|
|
|
|
|
require.NotEqual(t, original.AllowedContracts[0][0], cp.AllowedContracts[0][0])
|
|
|
|
require.NotEqual(t, original.AllowedGroups[0], cp.AllowedGroups[0])
|
|
|
|
require.NotEqual(t, original.Rules[0].Action, cp.Rules[0].Action)
|
|
|
|
}
|