diff --git a/pkg/wallet/wallet_test.go b/pkg/wallet/wallet_test.go index dfdf58a56..fad790e04 100644 --- a/pkg/wallet/wallet_test.go +++ b/pkg/wallet/wallet_test.go @@ -24,37 +24,47 @@ func TestWallet(t *testing.T) { var w *Wallet sampleSalt := [16]byte{145, 114, 211, 33, 247, 163, 215, 171, 90, 186, 97, 47, 43, 252, 68, 170} sampleNonce := [12]byte{113, 122, 168, 123, 48, 187, 178, 12, 209, 91, 243, 63} + sampleAddressData := []byte{0x77, 0x13, 0x86, 0x8f, 0xe5, 0x5a, 0xd1, 0xdb, 0x9c, 0x8, 0x30, 0x7c, 0x61, 0x5e, 0xdf, 0xc0, 0xc8, 0x3b, 0x5b, 0xd9, 0x88, 0xec, 0x2e, 0x3c, 0xe9, 0xe4, 0x1c, 0xf1, 0xf9, 0x4d, 0xc5, 0xd1} + samplePrivateKeyData := []byte{2, 86, 133, 146, 82, 184, 193, 160, 120, 44, 198, 209, 69, 230, 83, 35, 36, 235, 18, 105, 74, 117, 228, 237, 112, 65, 32, 0, 250, 180, 199, 26, 40, 28, 76, 116, 162, 95, 0, 103, 172, 8, 41, 11, 240, 185, 188, 215, 56, 170, 246, 2, 14, 16, 27, 214, 137, 103, 89, 111, 85, 149, 191, 38, 2, 43, 8, 183, 149, 104, 64, 149, 10, 106, 102, 156, 242, 178, 254, 189, 135} + samplePublicKeyData := []byte{45, 150, 188, 218, 203, 190, 65, 56, 44, 162, 62, 82, 227, 210, 25, 108, 186, 101, 231, 161, 172, 210, 9, 223, 201, 92, 107, 50, 182, 161, 138, 147} sampleNickname := "bonjour" sampleNickname2 := "unit-test" sampleNickname3 := "version-0" - sampleAccount, err := account.New( - uint8(account.LastVersion), - sampleNickname, - &types.Address{ - Object: &object.Object{ - Kind: object.UserAddress, - Version: types.AddressLastVersion, - Data: []byte{0x77, 0x13, 0x86, 0x8f, 0xe5, 0x5a, 0xd1, 0xdb, 0x9c, 0x8, 0x30, 0x7c, 0x61, 0x5e, 0xdf, 0xc0, 0xc8, 0x3b, 0x5b, 0xd9, 0x88, 0xec, 0x2e, 0x3c, 0xe9, 0xe4, 0x1c, 0xf1, 0xf9, 0x4d, 0xc5, 0xd1}, + + createAccount := func(nickname string) *account.Account { + acc, err := account.New( + uint8(account.LastVersion), + nickname, + &types.Address{ + Object: &object.Object{ + Kind: object.UserAddress, + Version: types.AddressLastVersion, + Data: sampleAddressData, + }, }, - }, - sampleSalt, - sampleNonce, - &types.EncryptedPrivateKey{ - Object: &object.Object{ - Kind: object.EncryptedPrivateKey, - Version: types.EncryptedPrivateKeyLastVersion, - Data: []byte{2, 86, 133, 146, 82, 184, 193, 160, 120, 44, 198, 209, 69, 230, 83, 35, 36, 235, 18, 105, 74, 117, 228, 237, 112, 65, 32, 0, 250, 180, 199, 26, 40, 28, 76, 116, 162, 95, 0, 103, 172, 8, 41, 11, 240, 185, 188, 215, 56, 170, 246, 2, 14, 16, 27, 214, 137, 103, 89, 111, 85, 149, 191, 38, 2, 43, 8, 183, 149, 104, 64, 149, 10, 106, 102, 156, 242, 178, 254, 189, 135}, + sampleSalt, + sampleNonce, + &types.EncryptedPrivateKey{ + Object: &object.Object{ + Kind: object.EncryptedPrivateKey, + Version: types.EncryptedPrivateKeyLastVersion, + Data: samplePrivateKeyData, + }, }, - }, - &types.PublicKey{ - Object: &object.Object{ - Kind: object.PublicKey, - Version: types.PublicKeyLastVersion, - Data: []byte{45, 150, 188, 218, 203, 190, 65, 56, 44, 162, 62, 82, 227, 210, 25, 108, 186, 101, 231, 161, 172, 210, 9, 223, 201, 92, 107, 50, 182, 161, 138, 147}, + &types.PublicKey{ + Object: &object.Object{ + Kind: object.PublicKey, + Version: types.PublicKeyLastVersion, + Data: samplePublicKeyData, + }, }, - }, - ) - assert.NoError(t, err) + ) + assert.NoError(t, err) + + return acc + } + + sampleAccount := createAccount(sampleNickname) t.Run("Create Wallet", func(t *testing.T) { newWallet, err := New(walletPath) @@ -82,39 +92,11 @@ func TestWallet(t *testing.T) { }) t.Run("Add Account: address not unique", func(t *testing.T) { - sampleAccount, err := account.New( - uint8(account.LastVersion), - "bonjour3", - &types.Address{ - Object: &object.Object{ - Kind: object.UserAddress, - Version: types.AddressLastVersion, - Data: []byte{0x77, 0x13, 0x86, 0x8f, 0xe5, 0x5a, 0xd1, 0xdb, 0x9c, 0x8, 0x30, 0x7c, 0x61, 0x5e, 0xdf, 0xc0, 0xc8, 0x3b, 0x5b, 0xd9, 0x88, 0xec, 0x2e, 0x3c, 0xe9, 0xe4, 0x1c, 0xf1, 0xf9, 0x4d, 0xc5, 0xd1}, - }, - }, - sampleSalt, - sampleNonce, - &types.EncryptedPrivateKey{ - Object: &object.Object{ - Kind: object.EncryptedPrivateKey, - Version: types.EncryptedPrivateKeyLastVersion, - Data: []byte{2, 86, 133, 146, 82, 184, 193, 160, 120, 44, 198, 209, 69, 230, 83, 35, 36, 235, 18, 105, 74, 117, 228, 237, 112, 65, 32, 0, 250, 180, 199, 26, 40, 28, 76, 116, 162, 95, 0, 103, 172, 8, 41, 11, 240, 185, 188, 215, 56, 170, 246, 2, 14, 16, 27, 214, 137, 103, 89, 111, 85, 149, 191, 38, 2, 43, 8, 183, 149, 104, 64, 149, 10, 106, 102, 156, 242, 178, 254, 189, 135}, - }, - }, - &types.PublicKey{ - Object: &object.Object{ - Kind: object.PublicKey, - Version: types.PublicKeyLastVersion, - Data: []byte{45, 150, 188, 218, 203, 190, 65, 56, 44, 162, 62, 82, 227, 210, 25, 108, 186, 101, 231, 161, 172, 210, 9, 223, 201, 92, 107, 50, 182, 161, 138, 147}, - }, - }, - ) - assert.NoError(t, err) - + sampleAccount := createAccount("bonjour3") err = w.AddAccount(sampleAccount, true) assert.Error(t, err) assert.ErrorIs(t, err, ErrAddressNotUnique) - + assertAccountIsPresent(t, w, sampleNickname) assert.Equal(t, 1, w.GetAccountCount()) sampleAccount.Nickname = sampleNickname