github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/neorpc/result/mpt_test.go (about)

     1  package result
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/nspcc-dev/neo-go/internal/random"
     8  	"github.com/nspcc-dev/neo-go/internal/testserdes"
     9  	"github.com/nspcc-dev/neo-go/pkg/core/mpt"
    10  	"github.com/nspcc-dev/neo-go/pkg/io"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func testProofWithKey() *ProofWithKey {
    15  	return &ProofWithKey{
    16  		Key: random.Bytes(10),
    17  		Proof: [][]byte{
    18  			random.Bytes(12),
    19  			random.Bytes(0),
    20  			random.Bytes(34),
    21  		},
    22  	}
    23  }
    24  
    25  func TestGetProof_MarshalJSON(t *testing.T) {
    26  	t.Run("Good", func(t *testing.T) {
    27  		p := testProofWithKey()
    28  		testserdes.MarshalUnmarshalJSON(t, p, new(ProofWithKey))
    29  	})
    30  	t.Run("Compatibility", func(t *testing.T) {
    31  		js := []byte(`"Bfn///8SBiQBAQ8D6yfHa4wV24kQ9eXarzY5Bw55VFzysUbkJjrz5FipqkjSAAQEBAQEBAMcbFvhto6QJgYoJs/uzqTrZNrPxpkgNiF5Z/ME98copwPQ4q6ZqLA8S7XUXNCrJNF68vMu8Gx3W8Ooo3qwMomm0gQDiT6zHh/siCZ0c2bfBEymPmRNTiXSAKFIammjmnnBnJYD+CNwgcEzBJqYfnc7RMhr8cPhffKN0281w0M7XLQ9BO4D7W+t3cleDNdiNc6tqWR8jyIP+bolh5QnZIyKXPwGHjsEBAQDcpxkuWYJr6g3ilENTh1sztlZsXZvt6Eedmyy6kI2gQoEKQEGDw8PDw8PA33qzf1Q5ILAwmYxBnM2N80A8JtFHKR7UHhVEqo5nQ0eUgADbChDXdc7hSDZpD9xbhYGuJxVxRWqhsVRTR2dE+18gd4DG5gRFexXofB0aNb6G2kzQUSTD+aWVsfmnKGf4HHivzAEBAQEBAQEBAQEBAQEBARSAAQEA2IMPmRKP0b2BqhMB6IgtfpPeuXKJMdMze7Cr1TeJqbmA1vvqQgR5DN9ew+Zp/nc5SBQbjV5gEq7F/tIipWaQJ1hBAQEBAQEBAQEBAQEBAMCAR4="`)
    32  
    33  		var p ProofWithKey
    34  		require.NoError(t, json.Unmarshal(js, &p))
    35  		require.Equal(t, 6, len(p.Proof))
    36  		for i := range p.Proof { // smoke test that every chunk is correctly encoded node
    37  			r := io.NewBinReaderFromBuf(p.Proof[i])
    38  			var n mpt.NodeObject
    39  			n.DecodeBinary(r)
    40  			require.NoError(t, r.Err)
    41  			require.NotNil(t, n.Node)
    42  		}
    43  	})
    44  }
    45  
    46  func TestProofWithKey_EncodeString(t *testing.T) {
    47  	expected := testProofWithKey()
    48  	var actual ProofWithKey
    49  	require.NoError(t, actual.FromString(expected.String()))
    50  	require.Equal(t, expected, &actual)
    51  }
    52  
    53  func TestVerifyProof_MarshalJSON(t *testing.T) {
    54  	t.Run("Good", func(t *testing.T) {
    55  		vp := &VerifyProof{random.Bytes(100)}
    56  		testserdes.MarshalUnmarshalJSON(t, vp, new(VerifyProof))
    57  	})
    58  	t.Run("NoValue", func(t *testing.T) {
    59  		vp := new(VerifyProof)
    60  		testserdes.MarshalUnmarshalJSON(t, vp, &VerifyProof{[]byte{1, 2, 3}})
    61  	})
    62  }