Exemplo n.º 1
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());
        }
        private static void TestAllowTrustOperationAuthorize(KeyPair source, KeyPair trustor, string assetCode)
        {
            AllowTrustOperation operation = null;

            stellar_dotnet_sdk.xdr.Operation xdr = null;
            AllowTrustOperation parsedOperation  = null;

            //Authorize: true, MaintainLiabilities: false -> true, false
            operation = new AllowTrustOperation.Builder(trustor, assetCode, true, false)
                        .SetSourceAccount(source)
                        .Build();

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

            Assert.AreEqual(true, parsedOperation.Authorize);
            Assert.AreEqual(false, parsedOperation.AuthorizeToMaintainLiabilities);

            //Authorize: false, MaintainLiabilities: true -> false, true
            operation = new AllowTrustOperation.Builder(trustor, assetCode, false, true)
                        .SetSourceAccount(source)
                        .Build();

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

            Assert.AreEqual(false, parsedOperation.Authorize);
            Assert.AreEqual(true, parsedOperation.AuthorizeToMaintainLiabilities);

            //Authorize: true, MaintainLiabilities: true -> true, false
            operation = new AllowTrustOperation.Builder(trustor, assetCode, true, true)
                        .SetSourceAccount(source)
                        .Build();

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

            Assert.AreEqual(true, parsedOperation.Authorize);
            Assert.AreEqual(false, parsedOperation.AuthorizeToMaintainLiabilities);

            //Authorize: false, MaintainLiabilities: false -> false, false
            operation = new AllowTrustOperation.Builder(trustor, assetCode, false, false)
                        .SetSourceAccount(source)
                        .Build();

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

            Assert.AreEqual(false, parsedOperation.Authorize);
            Assert.AreEqual(false, parsedOperation.AuthorizeToMaintainLiabilities);
        }