github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/subkey/derive_test.go (about) 1 package subkey 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 //nolint:funlen 10 func TestSplitURI(t *testing.T) { 11 tests := []struct { 12 suri, phrase, path, password string 13 err bool 14 }{ 15 { 16 suri: "bottom drive obey lake curtain smoke basket hold race lonely fit walk///password", 17 phrase: "bottom drive obey lake curtain smoke basket hold race lonely fit walk", 18 path: "", 19 password: "password", 20 }, 21 { 22 suri: "bottom drive obey lake curtain smoke basket hold race lonely fit walk", 23 phrase: "bottom drive obey lake curtain smoke basket hold race lonely fit walk", 24 path: "", 25 password: "", 26 }, 27 { 28 suri: "bottom drive obey lake curtain smoke basket hold race lonely fit walk/foo", 29 phrase: "bottom drive obey lake curtain smoke basket hold race lonely fit walk", 30 path: "/foo", 31 password: "", 32 }, 33 { 34 suri: "bottom drive obey lake curtain smoke basket hold race lonely fit walk//foo", 35 phrase: "bottom drive obey lake curtain smoke basket hold race lonely fit walk", 36 path: "//foo", 37 password: "", 38 }, 39 { 40 suri: "bottom drive obey lake curtain smoke basket hold race lonely fit walk//foo/bar", 41 phrase: "bottom drive obey lake curtain smoke basket hold race lonely fit walk", 42 path: "//foo/bar", 43 password: "", 44 }, 45 { 46 suri: "bottom drive obey lake curtain smoke basket hold race lonely fit walk/foo//bar", 47 phrase: "bottom drive obey lake curtain smoke basket hold race lonely fit walk", 48 path: "/foo//bar", 49 password: "", 50 }, 51 { 52 suri: "bottom drive obey lake curtain smoke basket hold race lonely fit walk//foo/bar//42/69", 53 phrase: "bottom drive obey lake curtain smoke basket hold race lonely fit walk", 54 path: "//foo/bar//42/69", 55 password: "", 56 }, 57 { 58 suri: "bottom drive obey lake curtain smoke basket hold race lonely fit walk//foo/bar//42/69///password", 59 phrase: "bottom drive obey lake curtain smoke basket hold race lonely fit walk", 60 path: "//foo/bar//42/69", 61 password: "password", 62 }, 63 64 { 65 suri: "/Alice", 66 phrase: DevPhrase, 67 path: "/Alice", 68 password: "", 69 }, 70 71 { 72 suri: "/Alice///password", 73 phrase: DevPhrase, 74 path: "/Alice", 75 password: "password", 76 }, 77 78 { 79 suri: "//Alice///password", 80 phrase: DevPhrase, 81 path: "//Alice", 82 password: "password", 83 }, 84 85 { 86 suri: "//Alice", 87 phrase: DevPhrase, 88 path: "//Alice", 89 password: "", 90 }, 91 } 92 93 for _, c := range tests { 94 t.Run(c.suri, func(t *testing.T) { 95 phrase, path, password, err := splitURI(c.suri) 96 if err != nil { 97 assert.True(t, c.err) 98 return 99 } 100 101 assert.Equal(t, c.phrase, phrase) 102 assert.Equal(t, c.path, path) 103 assert.Equal(t, c.password, password) 104 }) 105 } 106 }