github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/types/balance_status_test.go (about)

     1  package types
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/stafiprotocol/go-substrate-rpc-client/pkg/scale"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestBalanceStatusEncodeDecode(t *testing.T) {
    12  	// encode
    13  	bs := Reserved
    14  	var buf bytes.Buffer
    15  	encoder := scale.NewEncoder(&buf)
    16  	assert.NoError(t, encoder.Encode(bs))
    17  	assert.Equal(t, buf.Len(), 1)
    18  	assert.Equal(t, buf.Bytes(), []byte{1})
    19  
    20  	//decode
    21  	decoder := scale.NewDecoder(bytes.NewReader(buf.Bytes()))
    22  	bs0 := BalanceStatus(0)
    23  	err := decoder.Decode(&bs0)
    24  	assert.NoError(t, err)
    25  	assert.Equal(t, bs0, Reserved)
    26  
    27  	//decode error
    28  	decoder = scale.NewDecoder(bytes.NewReader([]byte{5}))
    29  	bs0 = BalanceStatus(0)
    30  	err = decoder.Decode(&bs0)
    31  	assert.Error(t, err)
    32  }