Пример #1
0
        public void TestTxSigner()
        {
            List <String> mnemonic = new List <String>(singleVector.Split(" ", StringSplitOptions.RemoveEmptyEntries));
            // Create the network info
            NetworkInfo networkInfo = new NetworkInfo(bech32Hrp: localbech32Hrp, lcdUrl: localTestUrl);

            // Build a transaction
            MsgSend msg = new MsgSend(
                fromAddress: "cosmos1hafptm4zxy5nw8rd2pxyg83c5ls2v62tstzuv2",
                toAddress: "cosmos12lla7fg3hjd2zj6uvf4pqj7atx273klc487c5k",
                amount: new List <StdCoin> {
                new StdCoin(denom: "uatom", amount: "100")
            }
                );
            // Fee
            StdFee fee = new StdFee(
                gas: "200000",
                amount: new List <StdCoin> {
                new StdCoin(denom: "uatom", amount: "250")
            }
                );
            StdTx tx = TxBuilder.buildStdTx(stdMsgs: new List <StdMsg> {
                msg
            }, fee: fee);
            // Create a wallet
            Wallet wallet = Wallet.derive(mnemonic, networkInfo);

            // Verify Wallet
            Assert.AreEqual(wallet.networkInfo.bech32Hrp, networkInfo.bech32Hrp);
            Assert.AreEqual(wallet.networkInfo.lcdUrl, networkInfo.lcdUrl);

            // Build the mockup server
            var _server = new MockHttpServer();
            //  I need this in order to get the correct data out of the mock server
            Dictionary <String, Object> accResponse  = JsonConvert.DeserializeObject <Dictionary <String, Object> >(TestResources.AccountDataResponse);
            Dictionary <String, Object> NodeResponse = JsonConvert.DeserializeObject <Dictionary <String, Object> >(TestResources.NodeInfoResponse);

            // Initialize Server Response
            _server
            .WithService(localTestUrl)
            .Api("auth/accounts/{wallettAddress}", accResponse)
            .Api("node_info", NodeResponse);

            // Link the client to the retrieval classes
            HttpClient client = new HttpClient(_server);

            AccountDataRetrieval.client = client;
            NodeInfoRetrieval.client    = client;

            // Call without await to avoid marking test class as async
            StdTx signedTx = TxSigner.signStdTx(wallet: wallet, stdTx: tx).Result;

            Assert.AreEqual(signedTx.signatures.Count, 1);

            StdSignature signature = (signedTx.signatures.ToArray())[0];

            Assert.AreEqual(signature.publicKey.type, "tendermint/PubKeySecp256k1");
            Assert.AreEqual(signature.publicKey.value, "ArMO2T5FNKkeF2aAZY012p/cpa9+PqKqw2GcQRPhAn3w");
            Assert.AreEqual(signature.value, "m2op4CCBa39fRZD91WiqtBLKbUQI+1OWsc1tJkpDg+8FYB4y51KahGn26MskVMpTJl5gToIC1pX26hLbW1Kxrg==");
        }
Пример #2
0
        /// Creates a transaction having the given [msgs] and [fee] inside,
        /// signs it with the given [Wallet] and sends it to the blockchain.
        /// Optional parameters can be [fee] and broadcasting [mode],
        /// that can be of type "sync", "async" or "block".
        public static async Task <TransactionResult> createSignAndSendTx(List <StdMsg> msgs, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC)
        {
            if (fee == null)
            {
                // Set the default value for fee
                int msgsNumber = msgs.Count > 0 ? msgs.Count : 1;
                fee = GenericUtils.calculateDefaultFee(msgsNumber: msgsNumber, fee: defaultAmount, denom: defaultDenom, gas: defaultGas);
            }

            String modeStr  = MyEnumExtensions.ToEnumMemberAttrValue(mode);
            StdTx  stdTx    = TxBuilder.buildStdTx(stdMsgs: msgs, fee: fee);
            StdTx  signedTx = await TxSigner.signStdTx(wallet : wallet, stdTx : stdTx);

            // return await TxSender.broadcastStdTx(wallet: wallet, stdTx: signedTx, mode: modeStr);
            TransactionResult res = await TxSender.broadcastStdTx(wallet : wallet, stdTx : signedTx, mode : modeStr);

            return(res);
        }
        public async Task test_broadcastStdTx()
        {
            //This is the comparison class
            CompareLogic compareLogic = new CompareLogic();

            NetworkInfo networkInfo = new NetworkInfo(bech32Hrp: "did:com:", lcdUrl: "http://localhost:1317");

            //primo mnemonic
            String        mnemonicString1 = "gorilla soldier device force cupboard transfer lake series cement another bachelor fatigue royal lens juice game sentence right invite trade perfect town heavy what";
            List <String> mnemonic        = new List <String>(mnemonicString1.Split(" ", StringSplitOptions.RemoveEmptyEntries));

            //secondo mnemonic
            String        mnemonicString2 = "daughter conduct slab puppy horn wrap bone road custom acoustic adjust target price trip unknown agent infant proof whip picnic exact hobby phone spin";
            List <String> mnemonic2       = new List <String>(mnemonicString2.Split(" ", StringSplitOptions.RemoveEmptyEntries));


            Wallet wallet          = Wallet.derive(mnemonic, networkInfo);
            Wallet recipientWallet = Wallet.derive(mnemonic2, networkInfo);


            List <StdCoin> depositAmount = new List <StdCoin> {
                new StdCoin(denom: "ucommercio", amount: "10000")
            };

            var dict = new Dictionary <string, object>();

            dict.Add("from_address", wallet.bech32Address);
            dict.Add("to_address", recipientWallet.bech32Address);
            dict.Add("amount", depositAmount);


            StdMsg        testmsg     = new StdMsg("cosmos-sdk/MsgSend", dict);
            List <StdMsg> Listtestmsg = new List <StdMsg>();

            Listtestmsg.Add(testmsg);

            StdFee fee = new StdFee(depositAmount, "200000");

            //Invio
            try
            {
                var stdTx = TxBuilder.buildStdTx(Listtestmsg, "", fee);

                var signedStdTx = await TxSigner.signStdTx(wallet : wallet, stdTx : stdTx);

                var result = await TxSender.broadcastStdTx(wallet : wallet, stdTx : signedStdTx);

                if (result.success)
                {
                    Console.WriteLine("Tx send successfully:\n$lcdUrl/txs/${result.hash}");
                }
                else
                {
                    Console.WriteLine("Tx error message:\n${result.error?.errorMessage}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while testing Sacco:\n$error");
            }
        }