From 5009915e54fbb83469c30dd8b2b3d641a206fa47 Mon Sep 17 00:00:00 2001 From: belane Date: Sun, 1 Dec 2019 10:52:29 +0100 Subject: [PATCH] Change address version (#1299) --- src/neo/ProtocolSettings.cs | 2 +- src/neo/Wallets/NEP6/NEP6Wallet.cs | 6 +++-- .../Network/P2P/Payloads/UT_Block.cs | 2 +- tests/neo.UnitTests/TestUtils.cs | 4 ++-- tests/neo.UnitTests/UT_ProtocolSettings.cs | 10 +++++++++ .../Wallets/NEP6/UT_NEP6Account.cs | 4 ++-- .../Wallets/NEP6/UT_NEP6Wallet.cs | 22 +++++++++---------- .../neo.UnitTests/Wallets/UT_WalletAccount.cs | 2 +- .../Wallets/UT_Wallets_Helper.cs | 2 +- 9 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/neo/ProtocolSettings.cs b/src/neo/ProtocolSettings.cs index f1483c5341..8f0a48101e 100644 --- a/src/neo/ProtocolSettings.cs +++ b/src/neo/ProtocolSettings.cs @@ -44,7 +44,7 @@ public static ProtocolSettings Default private ProtocolSettings(IConfigurationSection section) { this.Magic = section.GetValue("Magic", 0x4F454Eu); - this.AddressVersion = section.GetValue("AddressVersion", (byte)0x17); + this.AddressVersion = section.GetValue("AddressVersion", (byte)0x35); IConfigurationSection section_sv = section.GetSection("StandbyValidators"); if (section_sv.Exists()) this.StandbyValidators = section_sv.GetChildren().Select(p => p.Get()).ToArray(); diff --git a/src/neo/Wallets/NEP6/NEP6Wallet.cs b/src/neo/Wallets/NEP6/NEP6Wallet.cs index f76640e886..3668287b3e 100644 --- a/src/neo/Wallets/NEP6/NEP6Wallet.cs +++ b/src/neo/Wallets/NEP6/NEP6Wallet.cs @@ -38,7 +38,7 @@ public NEP6Wallet(string path, string name = null) else { this.name = name; - this.version = Version.Parse("1.0"); + this.version = Version.Parse("3.0"); this.Scrypt = ScryptParameters.Default; this.accounts = new Dictionary(); this.extra = JObject.Null; @@ -53,8 +53,10 @@ public NEP6Wallet(JObject wallet) private void LoadFromJson(JObject wallet, out ScryptParameters scrypt, out Dictionary accounts, out JObject extra) { - this.name = wallet["name"]?.AsString(); this.version = Version.Parse(wallet["version"].AsString()); + if (this.version.Major < 3) throw new FormatException(); + + this.name = wallet["name"]?.AsString(); scrypt = ScryptParameters.FromJson(wallet["scrypt"]); accounts = ((JArray)wallet["accounts"]).Select(p => NEP6Account.FromJson(p, this)).ToDictionary(p => p.ScriptHash); extra = wallet["extra"]; diff --git a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs index a26741c732..fd8f821c6a 100644 --- a/tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs +++ b/tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs @@ -206,7 +206,7 @@ public void ToJson() jObj["merkleroot"].AsString().Should().Be("0xd841af3d6bd7adb4bca24306725f9aec363edb10de3cafc5f8cca948d7b0290f"); jObj["time"].AsNumber().Should().Be(328665601001); jObj["index"].AsNumber().Should().Be(0); - jObj["nextconsensus"].AsString().Should().Be("AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM"); + jObj["nextconsensus"].AsString().Should().Be("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf"); JObject scObj = ((JArray)jObj["witnesses"])[0]; scObj["invocation"].AsString().Should().Be(""); diff --git a/tests/neo.UnitTests/TestUtils.cs b/tests/neo.UnitTests/TestUtils.cs index 554b492d4b..83f3d6515e 100644 --- a/tests/neo.UnitTests/TestUtils.cs +++ b/tests/neo.UnitTests/TestUtils.cs @@ -30,11 +30,11 @@ public static NEP6Wallet GenerateTestWallet() { JObject wallet = new JObject(); wallet["name"] = "noname"; - wallet["version"] = new System.Version().ToString(); + wallet["version"] = new System.Version("3.0").ToString(); wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = null; - wallet.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"0.0\",\"scrypt\":{\"n\":0,\"r\":0,\"p\":0},\"accounts\":[],\"extra\":null}"); + wallet.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"3.0\",\"scrypt\":{\"n\":0,\"r\":0,\"p\":0},\"accounts\":[],\"extra\":null}"); return new NEP6Wallet(wallet); } diff --git a/tests/neo.UnitTests/UT_ProtocolSettings.cs b/tests/neo.UnitTests/UT_ProtocolSettings.cs index a989be7f6f..e1a9e91cbb 100644 --- a/tests/neo.UnitTests/UT_ProtocolSettings.cs +++ b/tests/neo.UnitTests/UT_ProtocolSettings.cs @@ -1,6 +1,7 @@ using FluentAssertions; using Microsoft.Extensions.Configuration; using Microsoft.VisualStudio.TestTools.UnitTesting; +using Neo.Wallets; using System.Collections.Generic; using System.Reflection; @@ -30,6 +31,15 @@ public void Cleanup() ResetProtocolSettings(); } + [TestMethod] + public void CheckFirstLetterOfAddresses() + { + UInt160 min = UInt160.Parse("0x0000000000000000000000000000000000000000"); + min.ToAddress()[0].Should().Be('N'); + UInt160 max = UInt160.Parse("0xffffffffffffffffffffffffffffffffffffffff"); + max.ToAddress()[0].Should().Be('N'); + } + [TestMethod] public void Default_Magic_should_be_mainnet_Magic_value() { diff --git a/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs b/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs index b43ab41a16..f1c719c853 100644 --- a/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs +++ b/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs @@ -60,7 +60,7 @@ public void TestConstructorWithKeyPair() public void TestFromJson() { JObject json = new JObject(); - json["address"] = "ARxgjcH2K1yeW5f5ryuRQNaBzSa9TZzmVS"; + json["address"] = "NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf"; json["key"] = null; json["label"] = null; json["isDefault"] = true; @@ -68,7 +68,7 @@ public void TestFromJson() json["contract"] = null; json["extra"] = null; NEP6Account account = NEP6Account.FromJson(json, _wallet); - account.ScriptHash.Should().Be("ARxgjcH2K1yeW5f5ryuRQNaBzSa9TZzmVS".ToScriptHash()); + account.ScriptHash.Should().Be("NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf".ToScriptHash()); account.Label.Should().BeNull(); account.IsDefault.Should().BeTrue(); account.Lock.Should().BeFalse(); diff --git a/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs b/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs index de902a115e..dcf436e993 100644 --- a/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs +++ b/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs @@ -52,7 +52,7 @@ private string CreateWalletFile() rootPath = GetRandomPath(); if (!Directory.Exists(rootPath)) Directory.CreateDirectory(rootPath); string path = Path.Combine(rootPath, "wallet.json"); - File.WriteAllText(path, "{\"name\":\"name\",\"version\":\"0.0\",\"scrypt\":{\"n\":0,\"r\":0,\"p\":0},\"accounts\":[],\"extra\":{}}"); + File.WriteAllText(path, "{\"name\":\"name\",\"version\":\"3.0\",\"scrypt\":{\"n\":0,\"r\":0,\"p\":0},\"accounts\":[],\"extra\":{}}"); return path; } @@ -76,11 +76,11 @@ public void TestConstructorWithPathAndName() NEP6Wallet wallet = new NEP6Wallet(wPath); Assert.AreEqual("name", wallet.Name); Assert.AreEqual(new ScryptParameters(0, 0, 0).ToJson().ToString(), wallet.Scrypt.ToJson().ToString()); - Assert.AreEqual(new Version().ToString(), wallet.Version.ToString()); + Assert.AreEqual(new Version("3.0").ToString(), wallet.Version.ToString()); wallet = new NEP6Wallet("", "test"); Assert.AreEqual("test", wallet.Name); Assert.AreEqual(ScryptParameters.Default.ToJson().ToString(), wallet.Scrypt.ToJson().ToString()); - Assert.AreEqual(Version.Parse("1.0"), wallet.Version); + Assert.AreEqual(Version.Parse("3.0"), wallet.Version); } [TestMethod] @@ -88,14 +88,14 @@ public void TestConstructorWithJObject() { JObject wallet = new JObject(); wallet["name"] = "test"; - wallet["version"] = Version.Parse("1.0").ToString(); + wallet["version"] = Version.Parse("3.0").ToString(); wallet["scrypt"] = ScryptParameters.Default.ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); - wallet.ToString().Should().Be("{\"name\":\"test\",\"version\":\"1.0\",\"scrypt\":{\"n\":16384,\"r\":8,\"p\":8},\"accounts\":[],\"extra\":{}}"); + wallet.ToString().Should().Be("{\"name\":\"test\",\"version\":\"3.0\",\"scrypt\":{\"n\":16384,\"r\":8,\"p\":8},\"accounts\":[],\"extra\":{}}"); NEP6Wallet w = new NEP6Wallet(wallet); Assert.AreEqual("test", w.Name); - Assert.AreEqual(Version.Parse("1.0").ToString(), w.Version.ToString()); + Assert.AreEqual(Version.Parse("3.0").ToString(), w.Version.ToString()); } [TestMethod] @@ -107,7 +107,7 @@ public void TestGetName() [TestMethod] public void TestGetVersion() { - Assert.AreEqual(new System.Version().ToString(), uut.Version.ToString()); + Assert.AreEqual(new System.Version("3.0").ToString(), uut.Version.ToString()); } [TestMethod] @@ -295,7 +295,7 @@ public void TestImportNep2() Assert.AreEqual(false, result); JObject wallet = new JObject(); wallet["name"] = "name"; - wallet["version"] = new Version().ToString(); + wallet["version"] = new Version("3.0").ToString(); wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); @@ -339,7 +339,7 @@ public void TestSave() { JObject wallet = new JObject(); wallet["name"] = "name"; - wallet["version"] = new System.Version().ToString(); + wallet["version"] = new System.Version("3.0").ToString(); wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); @@ -381,7 +381,7 @@ public void TestVerifyPassword() Assert.AreEqual(false, uut.Contains(testScriptHash)); JObject wallet = new JObject(); wallet["name"] = "name"; - wallet["version"] = new Version().ToString(); + wallet["version"] = new Version("3.0").ToString(); wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); @@ -396,7 +396,7 @@ public void TestVerifyPassword() public void Test_NEP6Wallet_Json() { uut.Name.Should().Be("noname"); - uut.Version.Should().Be(new Version()); + uut.Version.Should().Be(new Version("3.0")); uut.Scrypt.Should().NotBeNull(); uut.Scrypt.N.Should().Be(new ScryptParameters(0, 0, 0).N); } diff --git a/tests/neo.UnitTests/Wallets/UT_WalletAccount.cs b/tests/neo.UnitTests/Wallets/UT_WalletAccount.cs index 413caf6880..42ebf6bb63 100644 --- a/tests/neo.UnitTests/Wallets/UT_WalletAccount.cs +++ b/tests/neo.UnitTests/Wallets/UT_WalletAccount.cs @@ -33,7 +33,7 @@ public class UT_WalletAccount public void TestGetAddress() { MyWalletAccount walletAccount = new MyWalletAccount(UInt160.Zero); - walletAccount.Address.Should().Be("AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM"); + walletAccount.Address.Should().Be("NKuyBkoGdZZSLyPbJEetheRhMjeznFZszf"); } [TestMethod] diff --git a/tests/neo.UnitTests/Wallets/UT_Wallets_Helper.cs b/tests/neo.UnitTests/Wallets/UT_Wallets_Helper.cs index df3c353a3f..9f0167c55a 100644 --- a/tests/neo.UnitTests/Wallets/UT_Wallets_Helper.cs +++ b/tests/neo.UnitTests/Wallets/UT_Wallets_Helper.cs @@ -15,7 +15,7 @@ public void TestToScriptHash() { byte[] array = { 0x01 }; UInt160 scriptHash = new UInt160(Crypto.Hash160(array)); - "AZk5bAanTtD6AvpeesmYgL8CLRYUt5JQsX".ToScriptHash().Should().Be(scriptHash); + "NdtB8RXRmJ7Nhw1FPTm7E6HoDZGnDw37nf".ToScriptHash().Should().Be(scriptHash); Action action = () => "3vQB7B6MrGQZaxCuFg4oh".ToScriptHash(); action.Should().Throw();