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

     1  package subkey
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestDecodeHex(t *testing.T) {
    11  	tests := []struct {
    12  		hex   string
    13  		bytes []byte
    14  		valid bool
    15  	}{
    16  		{
    17  			hex:   "0xb69355deefa7a8f33e9297f5af22e680f03597a99d4f4b1c44be47e7a2275802",
    18  			bytes: []byte{0xb6, 0x93, 0x55, 0xde, 0xef, 0xa7, 0xa8, 0xf3, 0x3e, 0x92, 0x97, 0xf5, 0xaf, 0x22, 0xe6, 0x80, 0xf0, 0x35, 0x97, 0xa9, 0x9d, 0x4f, 0x4b, 0x1c, 0x44, 0xbe, 0x47, 0xe7, 0xa2, 0x27, 0x58, 0x2},
    19  			valid: true,
    20  		},
    21  		{
    22  			hex:   "46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a",
    23  			bytes: []byte{0x46, 0xeb, 0xdd, 0xef, 0x8c, 0xd9, 0xbb, 0x16, 0x7d, 0xc3, 0x8, 0x78, 0xd7, 0x11, 0x3b, 0x7e, 0x16, 0x8e, 0x6f, 0x6, 0x46, 0xbe, 0xff, 0xd7, 0x7d, 0x69, 0xd3, 0x9b, 0xad, 0x76, 0xb4, 0x7a},
    24  			valid: true,
    25  		},
    26  		{
    27  			hex:   "invalidhex",
    28  			valid: false,
    29  		},
    30  	}
    31  
    32  	for _, c := range tests {
    33  		t.Run(c.hex, func(t *testing.T) {
    34  			res, valid := DecodeHex(c.hex)
    35  			assert.Equal(t, c.valid, valid)
    36  			assert.True(t, bytes.Equal(c.bytes, res))
    37  		})
    38  	}
    39  }