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

     1  // Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls
     2  //
     3  // Copyright 2020 Stafi Protocol
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package types_test
    18  
    19  import (
    20  	"testing"
    21  
    22  	. "github.com/stafiprotocol/go-substrate-rpc-client/types"
    23  )
    24  
    25  func TestAccountID_EncodeDecode(t *testing.T) {
    26  	assertRoundtrip(t, NewAccountID([]byte{}))
    27  	assertRoundtrip(t, NewAccountID([]byte{0, 1, 2, 3, 4, 5, 6, 7}))
    28  }
    29  
    30  func TestAccountID_EncodedLength(t *testing.T) {
    31  	assertEncodedLength(t, []encodedLengthAssert{
    32  		{NewAccountID([]byte{}), 32},
    33  		{NewAccountID([]byte{7, 6, 5, 4, 3, 2, 1, 0}), 32},
    34  	})
    35  }
    36  
    37  func TestAccountID_Encode(t *testing.T) {
    38  	assertEncode(t, []encodingAssert{
    39  		{NewAccountID([]byte{0, 0, 0}), MustHexDecodeString("0x0000000000000000000000000000000000000000000000000000000000000000")},     //nolint:lll
    40  		{NewAccountID([]byte{171, 18, 52}), MustHexDecodeString("0xab12340000000000000000000000000000000000000000000000000000000000")}, //nolint:lll
    41  	})
    42  }
    43  
    44  func TestAccountID_Hash(t *testing.T) {
    45  	assertHash(t, []hashAssert{
    46  		{NewAccountID([]byte{0, 42, 254}), MustHexDecodeString(
    47  			"0x7834db8eb04aefe8272c32d8160ce4fa3cb31fc95882e5bd53860715731c8198")},
    48  		{NewAccountID([]byte{0, 0}), MustHexDecodeString(
    49  			"0x89eb0d6a8a691dae2cd15ed0369931ce0a949ecafa5c3f93f8121833646e15c3")},
    50  	})
    51  }
    52  
    53  func TestAccountID_Hex(t *testing.T) {
    54  	assertEncodeToHex(t, []encodeToHexAssert{
    55  		{NewAccountID([]byte{0, 0, 0}), "0x0000000000000000000000000000000000000000000000000000000000000000"},
    56  		{NewAccountID([]byte{171, 18, 52}), "0xab12340000000000000000000000000000000000000000000000000000000000"},
    57  	})
    58  }
    59  
    60  func TestAccountID_String(t *testing.T) {
    61  	assertString(t, []stringAssert{
    62  		{NewAccountID([]byte{0, 0, 0}), "[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]"},
    63  		{NewAccountID([]byte{171, 18, 52}), "[171 18 52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]"},
    64  	})
    65  }
    66  
    67  func TestAccountID_Eq(t *testing.T) {
    68  	assertEq(t, []eqAssert{
    69  		{NewAccountID([]byte{1, 0, 0}), NewAccountID([]byte{1, 0}), true},
    70  		{NewAccountID([]byte{0, 0, 1}), NewAccountID([]byte{0, 1}), false},
    71  		{NewAccountID([]byte{0, 0, 0}), NewAccountID([]byte{0, 0}), true},
    72  		{NewAccountID([]byte{12, 48, 255}), NewAccountID([]byte{12, 48, 255}), true},
    73  		{NewAccountID([]byte{0}), NewAccountID([]byte{0}), true},
    74  		{NewAccountID([]byte{1}), NewBool(true), false},
    75  		{NewAccountID([]byte{0}), NewBool(false), false},
    76  	})
    77  }