github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/app/types/address_test.go (about) 1 package types 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 8 "github.com/stretchr/testify/require" 9 ) 10 11 // test compate 0x address to send and query 12 func TestAccAddressFromBech32(t *testing.T) { 13 config := types.GetConfig() 14 SetBech32Prefixes(config) 15 16 //make data 17 tests := []struct { 18 addrStr string 19 expectPass bool 20 }{ 21 {"fb1e34x06m7hqwt4n98yuaxuxljr0juumktxdav63", true}, 22 {"0x0073F2E28ef8F117e53d858094086Defaf1837D5", true}, 23 {"2CF4ea7dF75b513509d95946B43062E26bD88035", true}, 24 {strings.ToLower("2CF4ea7dF75b513509d95946B43062E26bD88035"), true}, 25 {strings.ToUpper("2CF4ea7dF75b513509d95946B43062E26bD88035"), true}, 26 {"fb1e34x06m7hqwt4n98yuaxuxljr0juumktxdav63_", false}, 27 {"0x0073F2E28ef8F117e53d858094086Defaf1837D5_", false}, 28 {"0073F2E28ef8F117e53d858094086Defaf1837D5_", false}, 29 } 30 31 //test run 32 for _, tc := range tests { 33 addr, err := types.AccAddressFromBech32(tc.addrStr) 34 if tc.expectPass { 35 require.NotNil(t, addr, "test: %v", tc.addrStr) 36 require.Nil(t, err, "test: %v", tc.addrStr) 37 } else { 38 require.Nil(t, addr, "test: %v", tc.addrStr) 39 require.NotNil(t, err, "test: %v", tc.addrStr) 40 } 41 } 42 43 }