Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change address version #1299

Merged
merged 6 commits into from
Dec 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/neo/ProtocolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>()).ToArray();
Expand Down
6 changes: 4 additions & 2 deletions src/neo/Wallets/NEP6/NEP6Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UInt160, NEP6Account>();
this.extra = JObject.Null;
Expand All @@ -53,8 +53,10 @@ public NEP6Wallet(JObject wallet)

private void LoadFromJson(JObject wallet, out ScryptParameters scrypt, out Dictionary<UInt160, NEP6Account> 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"];
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/Network/P2P/Payloads/UT_Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/neo.UnitTests/UT_ProtocolSettings.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ 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;
json["lock"] = false;
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();
Expand Down
22 changes: 11 additions & 11 deletions tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -76,26 +76,26 @@ 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]
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]
Expand All @@ -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]
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/Wallets/UT_WalletAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/Wallets/UT_Wallets_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FormatException>();
Expand Down