Exemplo n.º 1
0
        public void TestDelegate()
        {
            var delegatedBody = new Body
            {
                ChainTag     = 74,
                BlockRef     = "0x005d64da8e7321bd",
                Expiration   = 18,
                GasPriceCoef = 0,
                Gas          = 21000,
                DependsOn    = "",
                Nonce        = "0xd6846cde87878603",
                Reserved     = new Reserved {
                    Features = 1
                }
            };

            delegatedBody.Clauses.Add(new Clause("0xa4aDAfAef9Ec07BC4Dc6De146934C7119341eE25", new BigInteger(100000), "0x2398479812734981"));
            delegatedBody.Clauses.Add(new Clause("0xa4aDAfAef9Ec07BC4Dc6De146934C7119341eE25", new BigInteger(100000), "0x2398479812734981"));
            delegatedBody.Clauses.Add(new Clause("0xa4aDAfAef9Ec07BC4Dc6De146934C7119341eE25", new BigInteger(100000), "0x2398479812734981"));

            var transaction = new Transaction.Transaction(delegatedBody);

            Assert.True(transaction.IsDelegated);

            var senderPrikey = "0xdce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65";
            var senderAddr   = "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed";

            var gasPayerPrikey = "0x321d6443bc6177273b5abf54210fe806d451d6b7973bccc2384ef78bbcd0bf51";
            var geaPayerAddr   = "0xd3ae78222beadb038203be21ed5ce7c9b1bff602";

            Assert.True(transaction.SigningHash().SequenceEqual("0xb07661afea87bf07d3a76742950b1607174090bc2241a32e40f8d35e3747e0ad".ToBytes()));

            var senderSigningHash   = transaction.SigningHash();
            var gasPayerSigningHash = transaction.SigningHash(senderAddr);

            var senderSignature   = Cry.Secp256k1.Sign(senderSigningHash, senderPrikey.ToBytes());
            var gasPayerSignature = Cry.Secp256k1.Sign(gasPayerSigningHash, gasPayerPrikey.ToBytes());

            transaction.AddVIP191Signature(senderSignature, gasPayerSignature);

            Assert.True(transaction.Id == "0xf6a2eab557187af50e4a3abb8a65894eb3be4d58a557b31e8f878ca91c0d9f4e");
            Assert.True(transaction.Origin == senderAddr);
            Assert.True(transaction.Delegator == geaPayerAddr);
        }