github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/types/bool_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 TestBool_EncodeDecode(t *testing.T) { 26 assertRoundtrip(t, NewBool(true)) 27 assertRoundtrip(t, NewBool(false)) 28 } 29 30 func TestBool_EncodedLength(t *testing.T) { 31 assertEncodedLength(t, []encodedLengthAssert{ 32 {NewBool(true), 1}, 33 {NewBool(false), 1}, 34 }) 35 } 36 37 func TestBool_Encode(t *testing.T) { 38 assertEncode(t, []encodingAssert{ 39 {NewBool(true), []byte{0x01}}, 40 {NewBool(false), []byte{0x00}}, 41 }) 42 } 43 44 func TestBool_Decode(t *testing.T) { 45 assertDecode(t, []decodingAssert{ 46 {[]byte{0x01}, NewBool(true)}, 47 {[]byte{0x00}, NewBool(false)}, 48 }) 49 } 50 51 func TestBool_Hash(t *testing.T) { 52 assertHash(t, []hashAssert{ 53 {NewBool(true), MustHexDecodeString("0xee155ace9c40292074cb6aff8c9ccdd273c81648ff1149ef36bcea6ebb8a3e25")}, 54 {NewBool(false), MustHexDecodeString("0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314")}, 55 }) 56 } 57 58 func TestBool_Hex(t *testing.T) { 59 assertEncodeToHex(t, []encodeToHexAssert{ 60 {NewBool(true), "0x01"}, 61 {NewBool(false), "0x00"}, 62 }) 63 } 64 65 func TestBool_String(t *testing.T) { 66 assertString(t, []stringAssert{ 67 {NewBool(true), "true"}, 68 {NewBool(false), "false"}, 69 }) 70 } 71 72 func TestBool_Eq(t *testing.T) { 73 assertEq(t, []eqAssert{ 74 {NewBool(true), NewBool(true), true}, 75 {NewBool(false), NewBool(true), false}, 76 {NewBool(false), NewBool(false), true}, 77 {NewBool(true), NewBytes([]byte{0, 1, 2}), false}, 78 {NewBool(true), NewBytes([]byte{1}), false}, 79 {NewBool(false), NewBytes([]byte{0}), false}, 80 }) 81 }