github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/amino/byteslice_test.go (about)

     1  package amino
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  )
     7  
     8  func TestReadByteSliceEquality(t *testing.T) {
     9  	t.Parallel()
    10  
    11  	var encoded []byte
    12  	var err error
    13  	cdc := NewCodec()
    14  	type byteWrapper struct {
    15  		Val []byte
    16  	}
    17  	// Write a byteslice
    18  	testBytes := byteWrapper{[]byte("ThisIsSomeTestArrayEmbeddedInAStruct")}
    19  	encoded, err = cdc.MarshalSized(testBytes)
    20  	if err != nil {
    21  		t.Error(err.Error())
    22  	}
    23  
    24  	// Read the byteslice, should return the same byteslice
    25  	var testBytes2 byteWrapper
    26  	err = cdc.UnmarshalSized(encoded, &testBytes2)
    27  	if err != nil {
    28  		t.Error(err.Error())
    29  	}
    30  
    31  	if !bytes.Equal(testBytes.Val, testBytes2.Val) {
    32  		t.Error("Returned the wrong bytes")
    33  	}
    34  }