From 8931c9a794ab053fbcea082c414030a59ea9154f Mon Sep 17 00:00:00 2001
From: Evgenii Stratonikov <evgeniy@nspcc.ru>
Date: Sat, 25 Jul 2020 12:16:56 +0300
Subject: [PATCH] core/interop: increase coverate for crypto interops

---
 pkg/core/interop/crypto/ecdsa_test.go | 18 ++++++++++++++----
 pkg/core/interop_neo_test.go          |  6 ++++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/pkg/core/interop/crypto/ecdsa_test.go b/pkg/core/interop/crypto/ecdsa_test.go
index 4261d0014..4dd735e87 100644
--- a/pkg/core/interop/crypto/ecdsa_test.go
+++ b/pkg/core/interop/crypto/ecdsa_test.go
@@ -97,16 +97,26 @@ func TestCHECKMULTISIGGood(t *testing.T) {
 	t.Run("12_9", func(t *testing.T) { testCHECKMULTISIGGood(t, 12, []int{0, 1, 4, 5, 6, 7, 8, 9}) })
 }
 
-func testCHECKMULTISIGBad(t *testing.T, n int, ik, is []int) {
+func testCHECKMULTISIGBad(t *testing.T, isErr bool, n int, ik, is []int) {
 	v := initCHECKMULTISIGVM(t, n, ik, is)
 
+	if isErr {
+		require.Error(t, v.Run())
+		return
+	}
 	require.NoError(t, v.Run())
 	assert.Equal(t, 1, v.Estack().Len())
 	assert.False(t, v.Estack().Pop().Bool())
 }
 
 func TestCHECKMULTISIGBad(t *testing.T) {
-	t.Run("1_1 wrong signature", func(t *testing.T) { testCHECKMULTISIGBad(t, 2, []int{0}, []int{1}) })
-	t.Run("3_2 wrong order", func(t *testing.T) { testCHECKMULTISIGBad(t, 3, []int{0, 2}, []int{2, 0}) })
-	t.Run("3_2 duplicate sig", func(t *testing.T) { testCHECKMULTISIGBad(t, 3, nil, []int{0, 0}) })
+	t.Run("1_1 wrong signature", func(t *testing.T) { testCHECKMULTISIGBad(t, false, 2, []int{0}, []int{1}) })
+	t.Run("3_2 wrong order", func(t *testing.T) { testCHECKMULTISIGBad(t, false, 3, []int{0, 2}, []int{2, 0}) })
+	t.Run("3_2 duplicate sig", func(t *testing.T) { testCHECKMULTISIGBad(t, false, 3, nil, []int{0, 0}) })
+	t.Run("1_2 too many signatures", func(t *testing.T) { testCHECKMULTISIGBad(t, true, 2, []int{0}, []int{0, 1}) })
+	t.Run("gas limit exceeded", func(t *testing.T) {
+		v := initCHECKMULTISIGVM(t, 1, []int{0}, []int{0})
+		v.GasLimit = ECDSAVerifyPrice - 1
+		require.Error(t, v.Run())
+	})
 }
diff --git a/pkg/core/interop_neo_test.go b/pkg/core/interop_neo_test.go
index 525b04942..92cd8fcf8 100644
--- a/pkg/core/interop_neo_test.go
+++ b/pkg/core/interop_neo_test.go
@@ -213,6 +213,12 @@ func TestECDSAVerify(t *testing.T) {
 		pub[0] = 0xFF // invalid prefix
 		runCase(t, true, false, sign, pub, msg)
 	})
+
+	t.Run("invalid message", func(t *testing.T) {
+		sign := priv.Sign(msg)
+		runCase(t, false, false, sign, priv.PublicKey().Bytes(),
+			stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(msg)}))
+	})
 }
 
 func TestRuntimeEncode(t *testing.T) {