public void GenerateSomeCityMainNetAddressAndVerifyPrefix() { Network network = new CityMain(); for (int i = 0; i < 10; i++) { var privateKey = new Key(); BitcoinPubKeyAddress address = privateKey.PubKey.GetAddress(network); Assert.StartsWith("C", address.ToString()); var witnessAddress = privateKey.PubKey.WitHash.ToString(); var test = address.ScriptPubKey.ToString(); BitcoinSecret secret = privateKey.GetWif(network); var wif = secret.ToWif(); Assert.StartsWith("c", wif.ToString()); } for (int i = 0; i < 10; i++) { var privateKey = new Key(false); BitcoinPubKeyAddress address = privateKey.PubKey.GetAddress(network); Assert.StartsWith("C", address.ToString()); var witnessAddress = privateKey.PubKey.WitHash.ToString(); var test = address.ScriptPubKey.ToString(); BitcoinSecret secret = privateKey.GetWif(network); var wif = secret.ToWif(); Assert.StartsWith("8", wif.ToString()); } }
public void ShouldProduceCorrectExtPubKey() { // This test is a replicate of 'should produce correct extpubkey' test in Angular (City Hub). var passphrase = ""; var recoveryPhrase = "mystery problem faith negative member bottom concert bundle asthma female process twelve"; var walletPassword = "******"; var network = new CityMain(); var chainCode = new byte[] { 166, 209, 155, 88, 182, 124, 193, 127, 139, 220, 152, 1, 213, 145, 245, 80, 118, 188, 53, 211, 33, 37, 158, 40, 118, 207, 42, 83, 219, 233, 188, 161 }; // Intentionally blank lines to be // line-compatible with JavaScript unit test. // The master node is made without network information, always same no matter network. ExtKey masterNode = HdOperations.GetExtendedKey(recoveryPhrase, passphrase); ExtPubKey extPubKey = masterNode.Neuter(); // masterNode in C# and JavaScript should both have the same chaincode at this step, verify: Assert.Equal(chainCode, masterNode.ChainCode); Assert.Equal(chainCode, extPubKey.ChainCode); // Get the private key in WIF format and verify. var xprv = masterNode.GetWif(network).ToWif(); Assert.Equal("xprv9s21ZrQH143K3ignAgXxaBbyVbrCTuUJSHNrMwdTa7n4i1zpFsiWdRCerTWrKaZXVehZFbXcFtwnmndrzC1AVs1BueiycVSxXjMyhXHpBqx", xprv); // Get the public key in WIF format and verify. var xpub = extPubKey.GetWif(network).ToWif(); Assert.Equal("xpub661MyMwAqRbcGCmFGi4xwKYi3dggsNC9oWJTAL358TK3apKxoR2mBDX8hkD1cUePJyzkkNWffsfZEzkExFXN1sNfJoVw161LfQyCuNVDadK", xpub); // Get the "root" address. var address = masterNode.PrivateKey.PubKey.GetAddress(network); // Ensure that the generated address is a City Chain address and not Bitcoin. Assert.Equal("CQtq75vu4bAceku6FmenWBh35i1Y4oskdu", address.ToString()); var publicNode = masterNode.Derive(new KeyPath("m/44'/1926'/0'/0/0")); var changeNode = masterNode.Derive(new KeyPath("m/44'/1926'/0'/1/0")); Assert.Equal("CPtzM2XwLCVS3L6BFK1xYsCcGqgrgsxHrP", publicNode.PrivateKey.PubKey.GetAddress(network).ToString()); Assert.Equal("CY35ZGxzZBYHKyNV4KWKunYLHsTWejVSdR", changeNode.PrivateKey.PubKey.GetAddress(network).ToString()); // Get the first account in the HD wallet, this is same as the level stored in the wallet files. var accountNode = masterNode.Derive(new KeyPath("m/44'/1926'/0'")); var accountExtPubKey = accountNode.Neuter().GetWif(network).ToWif(); Assert.Equal("xpub6BwCLtuvjt6TZ495sJruY1UWPXg6ME9HA92ro75YDHvGpPKY6kQ6ifp6DEszRpJGMtdBvWBaSn4gQDTz4Ctm5m1BMLeFUh3F19mTXA4s3bE", accountExtPubKey); // Create a wallet file. string encryptedSeed = masterNode.PrivateKey.GetEncryptedBitcoinSecret(walletPassword, network).ToWif(); Assert.Equal("6PYW8DRnFZSu3CVC3NfghKFSozZE8gmf76GmsGrrA9ciWbv6F6HhVSKkEQ", encryptedSeed); }
public void ReadMagicByteWithFirstByteDuplicated() { var network = new CityMain(); List <byte> bytes = network.MagicBytes.ToList(); bytes.Insert(0, bytes.First()); using (var memstrema = new MemoryStream(bytes.ToArray())) { bool found = network.ReadMagic(memstrema, new CancellationToken()); Assert.True(found); } }
public void CityMainIsInitializedCorrectly() { Network network = new CityMain(); Assert.Equal(16, network.Checkpoints.Count); Assert.Equal(4, network.DNSSeeds.Count); Assert.Equal(4, network.SeedNodes.Count); Assert.Equal("CityMain", network.Name); Assert.Equal(CityMain.CityRootFolderName, network.RootFolderName); Assert.Equal(CityMain.CityDefaultConfigFilename, network.DefaultConfigFilename); Assert.Equal(0x43545901.ToString(), network.Magic.ToString()); Assert.Equal(4333, network.DefaultPort); Assert.Equal(4334, network.DefaultRPCPort); Assert.Equal(4335, network.DefaultAPIPort); Assert.Equal(CityMain.CityMaxTimeOffsetSeconds, network.MaxTimeOffsetSeconds); Assert.Equal(CityMain.CityDefaultMaxTipAgeInSeconds, network.MaxTipAge); Assert.Equal(10000, network.MinTxFee); Assert.Equal(10000, network.FallbackFee); Assert.Equal(10000, network.MinRelayTxFee); Assert.Equal("CITY", network.CoinTicker); Assert.Equal(2, network.Bech32Encoders.Length); //Assert.Equal(new Bech32Encoder("bc").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS].ToString()); //Assert.Equal(new Bech32Encoder("bc").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS].ToString()); Assert.Equal(12, network.Base58Prefixes.Length); Assert.Equal(new byte[] { (28) }, network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS]); Assert.Equal(new byte[] { (88) }, network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS]); Assert.Equal(new byte[] { (237) }, network.Base58Prefixes[(int)Base58Type.SECRET_KEY]); Assert.Equal(new byte[] { 0x01, 0x42 }, network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC]); Assert.Equal(new byte[] { 0x01, 0x43 }, network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC]); Assert.Equal(new byte[] { (0x04), (0x88), (0xB2), (0x1E) }, network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY]); Assert.Equal(new byte[] { (0x04), (0x88), (0xAD), (0xE4) }, network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY]); Assert.Equal(new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 }, network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE]); Assert.Equal(new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A }, network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE]); Assert.Equal(new byte[] { 0x2a }, network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS]); Assert.Equal(new byte[] { 23 }, network.Base58Prefixes[(int)Base58Type.ASSET_ID]); Assert.Equal(new byte[] { 0x13 }, network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS]); Assert.Equal(210000, network.Consensus.SubsidyHalvingInterval); Assert.Equal(750, network.Consensus.MajorityEnforceBlockUpgrade); Assert.Equal(950, network.Consensus.MajorityRejectBlockOutdated); Assert.Equal(1000, network.Consensus.MajorityWindow); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP34]); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP65]); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP66]); //Assert.Equal(new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8"), network.Consensus.BIP34Hash); Assert.Equal(new Target(new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), network.Consensus.PowLimit); Assert.Null(network.Consensus.MinimumChainWork); Assert.Equal(TimeSpan.FromSeconds(14 * 24 * 60 * 60), network.Consensus.PowTargetTimespan); Assert.Equal(TimeSpan.FromSeconds(10 * 60), network.Consensus.PowTargetSpacing); Assert.False(network.Consensus.PowAllowMinDifficultyBlocks); Assert.False(network.Consensus.PowNoRetargeting); Assert.Equal(2016, network.Consensus.MinerConfirmationWindow); Assert.Equal(2500, network.Consensus.LastPOWBlock); Assert.True(network.Consensus.IsProofOfStake); Assert.Equal(1926, network.Consensus.CoinType); Assert.Equal(new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)), network.Consensus.ProofOfStakeLimit); Assert.Equal(new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)), network.Consensus.ProofOfStakeLimitV2); Assert.Equal(new uint256("0x00000b0517068e602ed5279c20168cfa1e69884ee4e784909652da34c361bff2"), network.Consensus.DefaultAssumeValid); Assert.Equal(50, network.Consensus.CoinbaseMaturity); Assert.Equal(Money.Coins(13736000000), network.Consensus.PremineReward); Assert.Equal(2, network.Consensus.PremineHeight); Assert.Equal(Money.Coins(2), network.Consensus.ProofOfWorkReward); Assert.Equal(Money.Coins(20), network.Consensus.ProofOfStakeReward); Assert.Equal((uint)500, network.Consensus.MaxReorgLength); Assert.Equal(long.MaxValue, network.Consensus.MaxMoney); Block genesis = network.GetGenesis(); Assert.Equal(uint256.Parse("0x00000b0517068e602ed5279c20168cfa1e69884ee4e784909652da34c361bff2"), genesis.GetHash()); Assert.Equal(uint256.Parse("0xb3425d46594a954b141898c7eebe369c6e6a35d2dab393c1f495504d2147883b"), genesis.Header.HashMerkleRoot); }
public void CityMainIsInitializedCorrectly() { Network network = new CityMain(); Assert.Equal(0, network.Checkpoints.Count); Assert.Equal(4, network.DNSSeeds.Count); Assert.Equal(3, network.SeedNodes.Count); Assert.Equal("CityMain", network.Name); Assert.Equal(CityMain.CityRootFolderName, network.RootFolderName); Assert.Equal(CityMain.CityDefaultConfigFilename, network.DefaultConfigFilename); Assert.Equal(0x23898467.ToString(), network.Magic.ToString()); Assert.Equal(4333, network.DefaultPort); Assert.Equal(4334, network.RPCPort); Assert.Equal(CityMain.CityMaxTimeOffsetSeconds, network.MaxTimeOffsetSeconds); Assert.Equal(CityMain.CityDefaultMaxTipAgeInSeconds, network.MaxTipAge); Assert.Equal(10000, network.MinTxFee); Assert.Equal(60000, network.FallbackFee); Assert.Equal(10000, network.MinRelayTxFee); Assert.Equal("CITY", network.CoinTicker); Assert.Equal(2, network.Bech32Encoders.Length); //Assert.Equal(new Bech32Encoder("bc").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS].ToString()); //Assert.Equal(new Bech32Encoder("bc").ToString(), network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS].ToString()); Assert.Equal(12, network.Base58Prefixes.Length); Assert.Equal(new byte[] { (28) }, network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS]); Assert.Equal(new byte[] { (88) }, network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS]); Assert.Equal(new byte[] { (237) }, network.Base58Prefixes[(int)Base58Type.SECRET_KEY]); Assert.Equal(new byte[] { 0x01, 0x42 }, network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC]); Assert.Equal(new byte[] { 0x01, 0x43 }, network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC]); Assert.Equal(new byte[] { (0x04), (0x88), (0xB2), (0x1E) }, network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY]); Assert.Equal(new byte[] { (0x04), (0x88), (0xAD), (0xE4) }, network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY]); Assert.Equal(new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 }, network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE]); Assert.Equal(new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A }, network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE]); Assert.Equal(new byte[] { 0x2a }, network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS]); Assert.Equal(new byte[] { 23 }, network.Base58Prefixes[(int)Base58Type.ASSET_ID]); Assert.Equal(new byte[] { 0x13 }, network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS]); Assert.Equal(210000, network.Consensus.SubsidyHalvingInterval); Assert.Equal(750, network.Consensus.MajorityEnforceBlockUpgrade); Assert.Equal(950, network.Consensus.MajorityRejectBlockOutdated); Assert.Equal(1000, network.Consensus.MajorityWindow); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP34]); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP65]); Assert.Equal(0, network.Consensus.BuriedDeployments[BuriedDeployments.BIP66]); //Assert.Equal(new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8"), network.Consensus.BIP34Hash); Assert.Equal(new Target(new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), network.Consensus.PowLimit); Assert.Null(network.Consensus.MinimumChainWork); Assert.Equal(TimeSpan.FromSeconds(14 * 24 * 60 * 60), network.Consensus.PowTargetTimespan); Assert.Equal(TimeSpan.FromSeconds(10 * 60), network.Consensus.PowTargetSpacing); Assert.False(network.Consensus.PowAllowMinDifficultyBlocks); Assert.False(network.Consensus.PowNoRetargeting); Assert.Equal(1916, network.Consensus.RuleChangeActivationThreshold); Assert.Equal(2016, network.Consensus.MinerConfirmationWindow); Assert.Null(network.Consensus.BIP9Deployments[BIP9Deployments.TestDummy]); Assert.Null(network.Consensus.BIP9Deployments[BIP9Deployments.CSV]); Assert.Null(network.Consensus.BIP9Deployments[BIP9Deployments.Segwit]); Assert.Equal(125000, network.Consensus.LastPOWBlock); Assert.True(network.Consensus.IsProofOfStake); Assert.Equal(4535, network.Consensus.CoinType); Assert.Equal(new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)), network.Consensus.ProofOfStakeLimit); Assert.Equal(new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)), network.Consensus.ProofOfStakeLimitV2); Assert.Equal(new uint256("0x000007e4aff2b770e876ac1bc2d5317f15c2505b1f8e58423febf0913bd0cc34"), network.Consensus.DefaultAssumeValid); Assert.Equal(50, network.Consensus.CoinbaseMaturity); Assert.Equal(Money.Coins(13736000000), network.Consensus.PremineReward); Assert.Equal(2, network.Consensus.PremineHeight); Assert.Equal(Money.Coins(1), network.Consensus.ProofOfWorkReward); Assert.Equal(Money.Coins(100), network.Consensus.ProofOfStakeReward); Assert.Equal((uint)500, network.Consensus.MaxReorgLength); Assert.Equal(long.MaxValue, network.Consensus.MaxMoney); Block genesis = network.GetGenesis(); Assert.Equal(uint256.Parse("0x000007e4aff2b770e876ac1bc2d5317f15c2505b1f8e58423febf0913bd0cc34"), genesis.GetHash()); Assert.Equal(uint256.Parse("0x40ba87eb3e03731abe7f2c7643c493b6383020513d5352334c6e0ff343e2f82d"), genesis.Header.HashMerkleRoot); }