예제 #1
0
        public void TestPaymentOperation()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");
            // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR
            var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII");

            Asset asset  = new AssetTypeNative();
            var   amount = "1000";

            var operation = new PaymentOperation.Builder(destination, asset, amount)
                            .SetSourceAccount(source)
                            .Build();

            var xdr             = operation.ToXdr();
            var parsedOperation = (PaymentOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(10000000000L, xdr.Body.PaymentOp.Amount.InnerValue);
            Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId);
            Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId);
            Assert.IsTrue(parsedOperation.Asset is AssetTypeNative);
            Assert.AreEqual(amount, parsedOperation.Amount);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAEAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAAAAAAAlQL5AA=",
                operation.ToXdrBase64());
        }
예제 #2
0
        public void TestSetOptionsOperationSignerSha256()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");

            var preimage = Encoding.UTF8.GetBytes("stellar.org");
            var hash     = Util.Hash(preimage);

            var operation = new SetOptionsOperation.Builder()
                            .SetSigner(Signer.Sha256Hash(hash), 10)
                            .SetSourceAccount(source)
                            .Build();

            var xdr             = operation.ToXdr();
            var parsedOperation = (SetOptionsOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(null, parsedOperation.InflationDestination);
            Assert.AreEqual(null, parsedOperation.ClearFlags);
            Assert.AreEqual(null, parsedOperation.SetFlags);
            Assert.AreEqual(null, parsedOperation.MasterKeyWeight);
            Assert.AreEqual(null, parsedOperation.LowThreshold);
            Assert.AreEqual(null, parsedOperation.MediumThreshold);
            Assert.AreEqual(null, parsedOperation.HighThreshold);
            Assert.AreEqual(null, parsedOperation.HomeDomain);
            Assert.IsTrue(hash.SequenceEqual(parsedOperation.Signer.HashX.InnerValue));
            Assert.AreEqual(10, parsedOperation.SignerWeight);
            Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAACbpRqMkaQAfCYSk/n3xIl4fCoHfKqxF34ht2iuvSYEJQAAAAK",
                operation.ToXdrBase64());
        }
예제 #3
0
        public void TestCreatePassiveOfferOperation()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");
            // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR
            var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ");

            Asset selling  = new AssetTypeNative();
            var   buying   = Asset.CreateNonNativeAsset("USD", issuer);
            var   amount   = "0.00001";
            var   price    = "2.93850088"; // n=36731261 d=12500000
            var   priceObj = Price.FromString(price);

            var operation = new CreatePassiveOfferOperation.Builder(selling, buying, amount, price)
                            .SetSourceAccount(source)
                            .Build();

            var xdr             = operation.ToXdr();
            var parsedOperation = (CreatePassiveOfferOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(100L, xdr.Body.CreatePassiveOfferOp.Amount.InnerValue);
            Assert.IsTrue(parsedOperation.Selling is AssetTypeNative);
            Assert.IsTrue(parsedOperation.Buying is AssetTypeCreditAlphaNum4);
            Assert.IsTrue(parsedOperation.Buying.Equals(buying));
            Assert.AreEqual(amount, parsedOperation.Amount);
            Assert.AreEqual(price, parsedOperation.Price);
            Assert.AreEqual(priceObj.Numerator, 36731261);
            Assert.AreEqual(priceObj.Denominator, 12500000);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAQAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZAIweX0Avrwg",
                operation.ToXdrBase64());
        }
예제 #4
0
        public void TestSetOptionsOperationSingleField()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");

            var homeDomain = "stellar.org";

            var operation = new SetOptionsOperation.Builder()
                            .SetHomeDomain(homeDomain)
                            .SetSourceAccount(source)
                            .Build();

            var xdr             = operation.ToXdr();
            var parsedOperation = (SetOptionsOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(null, parsedOperation.InflationDestination);
            Assert.AreEqual(null, parsedOperation.ClearFlags);
            Assert.AreEqual(null, parsedOperation.SetFlags);
            Assert.AreEqual(null, parsedOperation.MasterKeyWeight);
            Assert.AreEqual(null, parsedOperation.LowThreshold);
            Assert.AreEqual(null, parsedOperation.MediumThreshold);
            Assert.AreEqual(null, parsedOperation.HighThreshold);
            Assert.AreEqual(homeDomain, parsedOperation.HomeDomain);
            Assert.AreEqual(null, parsedOperation.Signer);
            Assert.AreEqual(null, parsedOperation.SignerWeight);
            Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAtzdGVsbGFyLm9yZwAAAAAA",
                operation.ToXdrBase64());
        }
예제 #5
0
        public void TestAllowTrustOperation()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");
            // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR
            var trustor = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII");

            const string assetCode = "USDA";
            const bool   authorize = true;

            var operation = new AllowTrustOperation.Builder(trustor, assetCode, true)
                            .SetSourceAccount(source)
                            .Build();

            var xdr             = operation.ToXdr();
            var parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId);
            Assert.AreEqual(trustor.AccountId, parsedOperation.Trustor.AccountId);
            Assert.AreEqual(assetCode, parsedOperation.AssetCode);
            Assert.AreEqual(authorize, parsedOperation.Authorize);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAcAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEQQAAAAE=",
                operation.ToXdrBase64());
        }
예제 #6
0
        public void TestSetOptionsOperation()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");
            // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR
            var inflationDestination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII");
            // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR
            var signer = Signer.Ed25519PublicKey(KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"));

            var clearFlags      = 1;
            var setFlags        = 1;
            var masterKeyWeight = 1;
            var lowThreshold    = 2;
            var mediumThreshold = 3;
            var highThreshold   = 4;
            var homeDomain      = "stellar.org";
            var signerWeight    = 1;

            var operation = new SetOptionsOperation.Builder()
                            .SetInflationDestination(inflationDestination)
                            .SetClearFlags(clearFlags)
                            .SetSetFlags(setFlags)
                            .SetMasterKeyWeight(masterKeyWeight)
                            .SetLowThreshold(lowThreshold)
                            .SetMediumThreshold(mediumThreshold)
                            .SetHighThreshold(highThreshold)
                            .SetHomeDomain(homeDomain)
                            .SetSigner(signer, signerWeight)
                            .SetSourceAccount(source)
                            .Build();

            var xdr             = operation.ToXdr();
            var parsedOperation = (SetOptionsOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(inflationDestination.AccountId, parsedOperation.InflationDestination.AccountId);
            Assert.AreEqual(clearFlags, parsedOperation.ClearFlags);
            Assert.AreEqual(setFlags, parsedOperation.SetFlags);
            Assert.AreEqual(masterKeyWeight, parsedOperation.MasterKeyWeight);
            Assert.AreEqual(lowThreshold, parsedOperation.LowThreshold);
            Assert.AreEqual(mediumThreshold, parsedOperation.MediumThreshold);
            Assert.AreEqual(highThreshold, parsedOperation.HighThreshold);
            Assert.AreEqual(homeDomain, parsedOperation.HomeDomain);
            Assert.AreEqual(signer.Discriminant.InnerValue, parsedOperation.Signer.Discriminant.InnerValue);
            Assert.AreEqual(signer.Ed25519.InnerValue, parsedOperation.Signer.Ed25519.InnerValue);
            Assert.AreEqual(signerWeight, parsedOperation.SignerWeight);
            Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAABAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAIAAAABAAAAAwAAAAEAAAAEAAAAAQAAAAtzdGVsbGFyLm9yZwAAAAABAAAAAET+21WXwEtXRyxb/GBe1tc5V/WUzIOW4yJp+XQgNUUiAAAAAQ==",
                operation.ToXdrBase64());
        }
예제 #7
0
        public void TestManageDataOperationEmptyValue()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");

            var operation = new ManageDataOperation.Builder("test", null)
                            .SetSourceAccount(source)
                            .Build();

            var xdr = operation.ToXdr();

            var parsedOperation = (ManageDataOperation)Operation.FromXdr(xdr);

            Assert.AreEqual("test", parsedOperation.Name);
            Assert.AreEqual(null, parsedOperation.Value);

            Assert.AreEqual("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAA=",
                            operation.ToXdrBase64());
        }
예제 #8
0
        public void TestSetOptionsOperationPreAuthTxSigner()
        {
            Network.UseTestNetwork();

            // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4
            var source      = KeyPair.FromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS");
            var destination = KeyPair.FromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR");

            var sequenceNumber = 2908908335136768L;
            var account        = new Account(source, sequenceNumber);
            var transaction    = new Transaction.Builder(account)
                                 .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build())
                                 .Build();

            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var opSource = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");

            var operation = new SetOptionsOperation.Builder()
                            .SetSigner(Signer.PreAuthTx(transaction), 10)
                            .SetSourceAccount(opSource)
                            .Build();

            var xdr             = operation.ToXdr();
            var parsedOperation = (SetOptionsOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(null, parsedOperation.InflationDestination);
            Assert.AreEqual(null, parsedOperation.ClearFlags);
            Assert.AreEqual(null, parsedOperation.SetFlags);
            Assert.AreEqual(null, parsedOperation.MasterKeyWeight);
            Assert.AreEqual(null, parsedOperation.LowThreshold);
            Assert.AreEqual(null, parsedOperation.MediumThreshold);
            Assert.AreEqual(null, parsedOperation.HighThreshold);
            Assert.AreEqual(null, parsedOperation.HomeDomain);
            Assert.IsTrue(transaction.Hash().SequenceEqual(parsedOperation.Signer.PreAuthTx.InnerValue));
            Assert.AreEqual(10, parsedOperation.SignerWeight);
            Assert.AreEqual(opSource.AccountId, parsedOperation.SourceAccount.AccountId);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAB1vRBIRC3w7ZH5rQa17hIBKUwZTvBP4kNmSP7jVyw1fQAAAAK",
                operation.ToXdrBase64());
        }
예제 #9
0
        public void TestAccountMergeOperation()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");
            // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR
            var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII");

            var operation = new AccountMergeOperation.Builder(destination)
                            .SetSourceAccount(source)
                            .Build();

            var xdr = operation.ToXdr();

            var parsedOperation = (AccountMergeOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAgAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxA=",
                operation.ToXdrBase64());
        }
예제 #10
0
        public void TestToXdrAmount()
        {
            Assert.AreEqual(0L, Operation.ToXdrAmount("0"));
            Assert.AreEqual(1L, Operation.ToXdrAmount("0.0000001"));
            Assert.AreEqual(10000000L, Operation.ToXdrAmount("1"));
            Assert.AreEqual(11234567L, Operation.ToXdrAmount("1.1234567"));
            Assert.AreEqual(729912843007381L, Operation.ToXdrAmount("72991284.3007381"));
            Assert.AreEqual(729912843007381L, Operation.ToXdrAmount("72991284.30073810"));
            Assert.AreEqual(1014016711446800155L, Operation.ToXdrAmount("101401671144.6800155"));
            Assert.AreEqual(9223372036854775807L, Operation.ToXdrAmount("922337203685.4775807"));

            try
            {
                Operation.ToXdrAmount("0.00000001");
                Assert.Fail();
            }
            catch (ArithmeticException)
            {
            }
            catch (Exception)
            {
                Assert.Fail();
            }

            try
            {
                Operation.ToXdrAmount("72991284.30073811");
                Assert.Fail();
            }
            catch (ArithmeticException)
            {
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
예제 #11
0
        public void TestChangeTrustOperation()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");

            Asset asset = new AssetTypeNative();
            var   limit = "922337203685.4775807";

            var operation = new ChangeTrustOperation.Builder(asset, limit)
                            .SetSourceAccount(source)
                            .Build();

            var xdr             = operation.ToXdr();
            var parsedOperation = (ChangeTrustOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(9223372036854775807L, xdr.Body.ChangeTrustOp.Limit.InnerValue);
            Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId);
            Assert.IsTrue(parsedOperation.Asset is AssetTypeNative);
            Assert.AreEqual(limit, parsedOperation.Limit);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAYAAAAAf/////////8=",
                operation.ToXdrBase64());
        }