github.com/gagliardetto/solana-go@v1.11.0/programs/tokenregistry/types_test.go (about) 1 // Copyright 2021 github.com/gagliardetto 2 // This file has been modified by github.com/gagliardetto 3 // 4 // Copyright 2020 dfuse Platform Inc. 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // 10 // http://www.apache.org/licenses/LICENSE-2.0 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 18 package tokenregistry 19 20 import ( 21 "testing" 22 23 "github.com/stretchr/testify/require" 24 ) 25 26 func TestAsciiBytes_String(t *testing.T) { 27 require.Equal(t, "ABC", AsciiString([]byte{65, 66, 67, 0, 0, 0, 0, 0})) 28 } 29 30 func TestLogoFromString(t *testing.T) { 31 l, err := LogoFromString("logo") 32 require.NoError(t, err) 33 34 require.Equal(t, "logo", l.String()) 35 require.Equal(t, Logo([64]byte{108, 111, 103, 111, 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, 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}), l) 36 } 37 38 func TestNameFromString(t *testing.T) { 39 l, err := NameFromString("name") 40 require.NoError(t, err) 41 42 require.Equal(t, "name", l.String()) 43 require.Equal(t, Name([32]byte{110, 97, 109, 101, 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}), l) 44 } 45 46 func TestSymbolFromString(t *testing.T) { 47 l, err := SymbolFromString("symb") 48 require.NoError(t, err) 49 50 require.Equal(t, "symb", l.String()) 51 require.Equal(t, Symbol([32]byte{115, 121, 109, 98, 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}), l) 52 } 53 54 func TestWebsiteFromString(t *testing.T) { 55 l, err := WebsiteFromString("webs") 56 require.NoError(t, err) 57 58 require.Equal(t, "webs", l.String()) 59 require.Equal(t, Website([32]byte{119, 101, 98, 115, 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}), l) 60 }