github.com/deroproject/derosuite@v2.1.6-1.0.20200307070847-0f2e589c7a2b+incompatible/walletapi/wallet_test.go (about)

     1  // Copyright 2017-2018 DERO Project. All rights reserved.
     2  // Use of this source code in any form is governed by RESEARCH license.
     3  // license can be found in the LICENSE file.
     4  // GPG: 0F39 E425 8C65 3947 702A  8234 08B2 0360 A03A 9DE8
     5  //
     6  //
     7  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
     8  // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     9  // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    10  // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    11  // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    12  // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    13  // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    14  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
    15  // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    16  
    17  package walletapi
    18  
    19  import "fmt"
    20  import "testing"
    21  import "strings"
    22  
    23  // we are covering atleast one test case each for all supported languages
    24  
    25  func Test_Wallet_Generation_and_Recovery(t *testing.T) {
    26  
    27  	tests := []struct {
    28  		name             string
    29  		seed             string
    30  		spend_key_secret string
    31  		spend_key_public string
    32  		view_key_secret  string
    33  		view_key_public  string
    34  		Address          string
    35  	}{
    36  		{
    37  			name:             "English",
    38  			seed:             "sequence atlas unveil summon pebbles tuesday beer rudely snake rockets different fuselage woven tagged bested dented vegan hover rapid fawns obvious muppet randomly seasons randomly",
    39  			spend_key_secret: "b0ef6bd527b9b23b9ceef70dc8b4cd1ee83ca14541964e764ad23f5151204f0f",
    40  			spend_key_public: "7d996b0f2db6dbb5f2a086211f2399a4a7479b2c911af307fdc3f7f61a88cb0e",
    41  			view_key_secret:  "42ba20adb337e5eca797565be11c9adb0a8bef8c830bccc2df712535d3b8f608",
    42  			view_key_public:  "1c06bcac7082f73af10460b5f2849aded79374b2fbdaae5d9384b9b6514fddcb",
    43  			Address:          "dETocsF4EuzXaxLNbDLLWi6xNEzzBJ2He5WSf7He8peuPt4nTyakAFyNuXqrHAGQt1PBSBonCRRj8daUtF7TPXFW42YQkxUQzg",
    44  		},
    45  
    46  		{
    47  			name:             "Deutsch",
    48  			seed:             "Dekade Spagat Bereich Radclub Yeti Dialekt Unimog Nomade Anlage Hirte Besitz Märzluft Krabbe Nabel Halsader Chefarzt Hering tauchen Neuerung Reifen Umgang Hürde Alchimie Amnesie Reifen",
    49  			spend_key_secret: "a00b3c431e0037426f12b255aaca918863c8bbc690ff3765564bcc1de7fbb303",
    50  			spend_key_public: "6f6d202f715d23ff4034a42298fd7b36431dbbfe8559df642911a9c3143ab802",
    51  			view_key_secret:  "eb2e288ac34e8d4f51cf73b8fda5240c2f3a25f72f4e7b4ac33f33fdc6602300",
    52  			view_key_public:  "ec9769a6fc9a10a474ba27bb62a58cb55e51aca4107b3daa613c054e4a104d75",
    53  			Address:          "dETobGVx1rYGaagDmPbfGjjQ5zeVkHXDeG2ssGnyrWgbApeTgRHhPJBSmdAj76XJFKUh3FtNv7fjMMcbGsLnms8V1cqG9Euc5i",
    54  		},
    55  
    56  		{
    57  			name:             "Español",
    58  			seed:             "perfil lujo faja puma favor pedir detalle doble carbón neón paella cuarto ánimo cuento conga correr dental moneda león donar entero logro realidad acceso doble",
    59  			spend_key_secret: "4f1101c4cc6adc6e6a63acde4e71fd76dc4471fa54769866d5e80a0a3d53d00c",
    60  			spend_key_public: "7f28c0b9c5e59fb57a6c4171f6b19faa369bd50c53b792fcdf2402369ded26a7",
    61  			view_key_secret:  "2de547b9fa3be9db08871d3964027a8f0d8d9c36755257841ba838cfff9fd60a",
    62  			view_key_public:  "caf4787a2eb8aa94e11a5a7ac912daa820a8148ea175b03a13d4322adab0c33f",
    63  			Address:          "dETod3T65GgfQe4xkLfu2mWiAzdR6ZRPgXhuAdJqKRUpgffP7dP3C5BXtVhPTwLJZE49uhjBDBkLxLgj3835HxiM7hWoS7trc1",
    64  		},
    65  
    66  		{
    67  			name:             "Français",
    68  			seed:             "lisser onctueux pierre trace flair riche machine ordre soir nougat talon balle biceps crier trame tenu gorge cuisine taverne presque laque argent roche secte ordre",
    69  			spend_key_secret: "340ed50ef73ba172e2fef23dc9f60e314f609bb7692d22d59f3938c391570b0a",
    70  			spend_key_public: "1b2e329fb7fbf1e3d93a30d66e72f13e19addc49ece84839bf2772d685b1bf20",
    71  			view_key_secret:  "415068b05bfe34ee250b1b0fb0847a7cef7bc1e99ab407dedcf779348097210b",
    72  			view_key_public:  "a7d037f5f73677c4d1ba32559238886c9011d682121946cf06f9bb59efe75862",
    73  			Address:          "dEToRmE1GKxj9BVmA46whoLE5vKNnBH6BfrRoaoGLig4WjN9WHF3FCJA7QZwkkGP1KATSXC7cLB9s5EDT5Xfczdk9mV1pUkkUg",
    74  		},
    75  
    76  		{
    77  			name:             "Italiano",
    78  			seed:             "sospiro uomo sommario orecchio muscolo testa avido sponda mutande levare lamento frumento volpe zainetto ammirare stufa convegno patente salto venire pianeta marinaio minuto moneta moneta",
    79  			spend_key_secret: "21cb90e631866952954cdcba042a3ae90407c40c052cc067226df0b454933502",
    80  			spend_key_public: "540850fa07de29317467980349436266652e1a0d4ba9b758568428a5881a6e4a",
    81  			view_key_secret:  "a106482cc83587c3b39f152ddfa0a447a7647b7977deb400e56166fa7fcc9c0a",
    82  			view_key_public:  "e076d540a85fb63fdb417304effa0541de65b80883b7b773b5d736a7face10dc",
    83  			Address:          "dEToYBF9F58eAEsRFgQjaYCGiM1ngwjiSVPTfH6c1A5D5RQuWLjg7cBH1XUaQnY9v6ipWigbhHQN6XjHK6yXdUws8ovPF3F19g",
    84  		},
    85  
    86  		{
    87  			name:             "Nederlands",
    88  			seed:             "veto hobo tolvrij cricket somber omaans lourdes kokhals ionisch lipman freon neptunus zimmerman rijbaan wisgerhof oudachtig nerd walraven ruis gevecht foolen onheilig rugnummer russchen cricket",
    89  			spend_key_secret: "921cbd7640df5fd12effb8f4269c5a47bac0ef3f75a0c25aa9f174f589801102",
    90  			spend_key_public: "f136d2467e0e1826218b83d148374cd215358d1fe6951eab0b6046e632170072",
    91  			view_key_secret:  "ff10ba6ee19a563b60ac8ab5d94916993a1ff05c644c3f73056c91edd1423b06",
    92  			view_key_public:  "7506289e53bcfaee88ce5ff5a83d2818d066db2b8d776a15808e5c3fd9a49cde",
    93  			Address:          "dEToqunYRNu3MjViW649P5AFUquDmjZW5RwedfYZ6xbT4r9TKMQVk34YcLzXmSx4CPBEJARk23ZKzLyUDJMAzJdN7EovWv3GRd",
    94  		},
    95  
    96  		{
    97  			name:             "Português",
    98  			seed:             "guloso caatinga enunciar newtoniano aprumo ilogismo vazio gibi imovel mixuruca bauxita paludismo unanimidade zumbi vozes roer anzol leonardo roer ucraniano elmo paete susto taco imovel",
    99  			spend_key_secret: "92da2722c7138e65559973131fd2c69b4a0ae4faf0e12b7abe096d5870d6a700",
   100  			spend_key_public: "f2daf0540863ae830c6f994fc467900f77dfac153f36e84e9e0eaa074333a3e9",
   101  			view_key_secret:  "2de03327764d8d8fdb210560ce3e78b6698023ea9993a104afccf34495a82506",
   102  			view_key_public:  "2e0db07e7ea17fd49a2a92d7ca5071445033c0107f7d4f5adb9cb063b7aab7ea",
   103  			Address:          "dERopX3LiCoHg3AFLgZB5dJKgvLESnnqLABfvPAM4u869dya9oocJGVU1kG8wQjC25ETPmRyMKw98MxfVwqxbmdY7UEGsR2czw",
   104  		},
   105  
   106  		{
   107  			name:             "русский язык",
   108  			seed:             "шорох рента увлекать пешеход гонка сеять пчела ваза апатия пишущий готовый вибрация юбка здоровье машина штука охрана доза рынок клоун рецепт отпуск шестерка эволюция вибрация",
   109  			spend_key_secret: "3d0fb729be695b865c073eed68ee91f06d429a27f8eaaaa6a99f954edbef8406",
   110  			spend_key_public: "c564b0e4d2992b534f796d70d38d283e3fb53cee717ecd1aad1156e2b79abc85",
   111  			view_key_secret:  "7c048a8c4f9b1aaba092f5cbc07bded9bfe35fcad7ce46634639d042011b8b04",
   112  			view_key_public:  "8d9f057765ab73b2ae890c5073737ba009539c8b4746a5e58e74a6cb7150a8c2",
   113  			Address:          "dERojPZ7WjBScw9H8PS6oCQcQJBXJaQdNND8ZYbYBr2SSt8wzG8HFg8VgJKcsDonhYLKL5Q71UNWACpNiaESzsJx44HUmJzaWW",
   114  		},
   115  
   116  		{
   117  			name:             "日本語",
   118  			seed:             "かわく ねまき けもの せいげん ためる にんめい てあみ にりんしゃ さわやか えらい うちき けいかく あたる せっきゃく ずっしり かいよう おおや てらす くれる ばかり なこうど たいうん そまつ たいえき せいげん",
   119  			spend_key_secret: "e12da07065554a32ac798396f74dbb35557164f9f39291a3f95705e62e0d7703",
   120  			spend_key_public: "09cc0d2adecd40f1118dffce60d1f5d6876ed898ef9360e867bc1e52df36b6fb",
   121  			view_key_secret:  "90346fc93565c41686eb23fe4fae22a89e59f2ea14d0ba8ad3b16a99ebd80e0b",
   122  			view_key_public:  "982046c49edc082df0e44a739b831a7c0a325766f9c4fa09fbf8c984a8c6bc06",
   123  			Address:          "dERoNDzRBZfbLDdeoKD8Zdc7svU36AKPtReksucYRpy4A9oWVcc5dFsdoaxnS7ddmtNvsL5w1eWkYZwvQqApAg8X8XomwZSLws",
   124  		},
   125  
   126  		{
   127  			name:             "简体中文 (中国)",
   128  			seed:             "启 写 输 苯 加 担 乳 代 集 预 懂 均 倒 革 熟 载 隆 台 幸 谋 轮 抚 扩 急 输",
   129  			spend_key_secret: "3bfd99190f28bd7830b3631cfa514176fc24e88281fe056ce447a5a7fcdc9a02",
   130  			spend_key_public: "f27221193c3ab0709009e2225578ff93d86efc178ebc0b482e8d9ec7e741df40",
   131  			view_key_secret:  "1786f5656bc093a06d5064a80bb891e2e1873699da5e3b63bb16af2bc5563b0c",
   132  			view_key_public:  "976d8c38f15220a3ee33724c3eb5315589b41e7b2f4b0ee2be04e92edae94418",
   133  			Address:          "dERopUMxPjhApMpS4vt2B6MEqTpvQbZo3YTGFr7MoabYC23RE7DvTQCEjju9jXHfwBXJoBfHaCVupDZAAgZpLaY99qhsXcCFmg",
   134  		},
   135  
   136  		{
   137  			name:             "Esperanto",
   138  			seed:             "amrakonto facila vibri obtuza gondolo membro alkoholo oferti ciumi reinspekti azteka kupro gombo keglo dugongo diino hemisfero sume servilo bambuo sekretario alta diurno duloka hemisfero",
   139  			spend_key_secret: "61abd2a5625a95371882117d8652e0735779b7b535008c73d65735b9477b1105",
   140  			spend_key_public: "74484fccc824cecdb0a9e69a163938f5d075fcf4d649444e86187cde130b2f04",
   141  			view_key_secret:  "ba6202a8b877b6c58eb7239d9a23166202ae454a9c98de74d29ba593782ce20c",
   142  			view_key_public:  "22437d58b154e9b5f35526dbfd6d6e71769103536de248eea98df7209de9759b",
   143  			Address:          "dERoaEnz1jm7A5kv9xFxgdAa8Y7SCqepmDFnEo4Rkwe22sVjoBThDweFCmBjkJMLSQKJd4soX6wBierFKbDTh1SL9r8XY829pb",
   144  		},
   145  	}
   146  
   147  	for _, test := range tests {
   148  
   149  		account, err := Generate_Account_From_Recovery_Words(test.seed)
   150  		if err != nil || account.SeedLanguage != test.name {
   151  			t.Fatalf("%s Mnemonics testing failed err %s", test.name, err)
   152  		}
   153  
   154  		// test spend_key_secret and public
   155  
   156  		if test.spend_key_secret != fmt.Sprintf("%s", account.Keys.Spendkey_Secret) {
   157  			t.Fatalf("%s Wallet testing failed  expected secret key %s  actual %s", test.name, account.Keys.Spendkey_Secret,
   158  				test.spend_key_secret)
   159  
   160  		}
   161  
   162  		if test.spend_key_public != fmt.Sprintf("%s", account.Keys.Spendkey_Public) {
   163  			t.Fatalf("%s Wallet testing failed  expected public spend key %s  actual %s", test.name, account.Keys.Spendkey_Public,
   164  				test.spend_key_public)
   165  
   166  		}
   167  
   168  		if test.view_key_secret != fmt.Sprintf("%s", account.Keys.Viewkey_Secret) {
   169  			t.Fatalf("%s Wallet testing failed  expected secret key %s  actual %s", test.name, account.Keys.Viewkey_Secret,
   170  				test.view_key_secret)
   171  
   172  		}
   173  
   174  		if test.view_key_public != fmt.Sprintf("%s", account.Keys.Viewkey_Public) {
   175  			t.Fatalf("%s Wallet testing failed  expected secret key %s  actual %s", test.name, account.Keys.Viewkey_Public,
   176  				test.view_key_public)
   177  
   178  		}
   179  
   180  		// check addrees only if mainnet address
   181  		if strings.Contains(test.Address, "dERo") {
   182  
   183  			if account.GetAddress().String() != test.Address {
   184  				t.Fatalf("%s Wallet testing failed  expected address %s  actual %s", test.name, test.Address,
   185  					account.GetAddress().String())
   186  			}
   187  		}
   188  
   189  		account2, err := Generate_Account_View_Only(account.Keys.Spendkey_Public, account.Keys.Viewkey_Secret)
   190  		if test.view_key_public != fmt.Sprintf("%s", account2.Keys.Viewkey_Public) {
   191  			t.Fatalf("%s Wallet testing failed  expected secret key %s  actual %s", test.name, account2.Keys.Viewkey_Public,
   192  				test.view_key_public)
   193  
   194  		}
   195  
   196  		// test checksum failure
   197  		test := tests[0]
   198  		seed := "sequence atlas unveil summon pebbles tuesday beer rudely snake rockets different fuselage woven tagged bested dented vegan hover rapid fawns obvious muppet randomly seasons seasons"
   199  		account, err = Generate_Account_From_Recovery_Words(seed)
   200  		if err == nil {
   201  			t.Errorf("%s Account recovery failed err %s", test.name, err)
   202  		}
   203  
   204  	}
   205  
   206  }