Beispiel #1
0
        public void TestNativeAsset()
        {
            Asset asset = new Asset();

            Assert.Equal(Asset.AssetTypeEnum.ASSET_TYPE_NATIVE, asset.Type);

            StellarBase.Generated.Asset genAsset = asset.ToXDR();

            Assert.Equal(StellarBase.Generated.AssetType.AssetTypeEnum.ASSET_TYPE_NATIVE, genAsset.Discriminant.InnerValue);

            Asset resAsset = Asset.FromXDR(genAsset);

            Assert.Equal(Asset.AssetTypeEnum.ASSET_TYPE_NATIVE, resAsset.Type);
        }
Beispiel #2
0
        public void CustomAssetConversion()
        {
            StellarBase.Network.CurrentNetwork = "ProjectQ";
            var master = KeyPair.Master();

            var alphaNum4 = new StellarBase.Generated.Asset.AssetAlphaNum4
            {
                AssetCode = ASCIIEncoding.ASCII.GetBytes("USD\0"),
                Issuer    = master.AccountId
            };

            var asset = new StellarBase.Generated.Asset
            {
                AlphaNum4    = alphaNum4,
                Discriminant = StellarBase.Generated.AssetType.Create(StellarBase.Generated.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM4)
            };

            string sample64 = "AAAAAVVTRAAAAAAA/tG7Wc76HWgC/tUk/mL4tEHFqNnEFD6A604uGSyxgGY=";

            byte[] sample = Convert.FromBase64String(sample64);

            var reader      = new StellarBase.Generated.ByteReader(sample);
            var sampleAsset = StellarBase.Generated.Asset.Decode(reader);

            Assert.Equal(
                asset.Discriminant.InnerValue,
                sampleAsset.Discriminant.InnerValue);

            Assert.Equal(
                asset.AlphaNum4.AssetCode,
                sampleAsset.AlphaNum4.AssetCode);

            Assert.Equal(
                asset.AlphaNum4.Issuer.InnerValue.Ed25519.InnerValue,
                sampleAsset.AlphaNum4.Issuer.InnerValue.Ed25519.InnerValue);

            var writer = new StellarBase.Generated.ByteWriter();

            StellarBase.Generated.Asset.Encode(writer, asset);
            string native64 = Convert.ToBase64String(writer.ToArray());

            Assert.Equal(sample64, native64);
        }
Beispiel #3
0
        public void TestAlphaNum12Asset()
        {
            var    keyPair = KeyPair.Master();
            string code    = "TestTestTest";
            Asset  asset   = new Asset(code, keyPair);

            Assert.Equal(code, asset.Code);
            Assert.Equal(keyPair, asset.Issuer);
            Assert.Equal(Asset.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12, asset.Type);

            StellarBase.Generated.Asset genAsset = asset.ToXDR();

            Assert.Equal(Encoding.ASCII.GetBytes(code).ToString(), genAsset.AlphaNum12.AssetCode.ToString());
            Assert.Equal(keyPair.PublicKey.ToString(), genAsset.AlphaNum12.Issuer.InnerValue.Ed25519.InnerValue.ToString());
            Assert.Equal(StellarBase.Generated.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12, genAsset.Discriminant.InnerValue);

            Asset resAsset = Asset.FromXDR(genAsset);

            Assert.Equal(code, resAsset.Code);
            Assert.Equal(keyPair.Address, resAsset.Issuer.Address);
            Assert.Equal(keyPair.PublicKey.ToString(), resAsset.Issuer.PublicKey.ToString());
            Assert.Equal(Asset.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12, resAsset.Type);
        }