/** @param context */

        public void PostRevokeTx()
        {
            BaseKeyPair           keyPair      = new BaseKeyPair(TestConstants.BENEFICIARY_PRIVATE_KEY);
            string                nameId       = nativeClient.GetNameId(validDomain).Id;
            Account               account      = nativeClient.GetAccount(keyPair.PublicKey);
            ulong                 nonce        = account.Nonce + 1;
            ulong                 ttl          = 0;
            NameRevokeTransaction nameRevokeTx = nativeClient.CreateNameRevokeTransaction(keyPair.PublicKey, nameId, nonce, ttl);
            UnsignedTx            unsignedTx   = nameRevokeTx.CreateUnsignedTransaction();
            Tx signedTx = nativeClient.SignTransaction(unsignedTx, keyPair.PrivateKey);

            logger.LogInformation("Signed NameRevokeTx: " + signedTx.TX);
            PostTxResponse postTxResponse = nativeClient.PostTx(logger, signedTx);

            logger.LogInformation("NameRevokeTx hash: " + postTxResponse.TXHash);
            Assert.AreEqual(postTxResponse.TXHash, Encoding.ComputeTxHash(signedTx.TX));
            Assert.ThrowsException <ApiException <Error> >(() => nativeClient.GetNameIdAsync(validDomain).TimeoutAsync(TestConstants.NUM_TRIALS_DEFAULT).RunAndUnwrap(), "Name Not Found");
            logger.LogInformation("Validated, that namespace {validDomain} is revoked");
        }
示例#2
0
        internal async Task SignAndSendAsync <T>(Transaction <T> trans, CancellationToken token) where T : UnsignedTx
        {
            T tx = await trans.CreateUnsignedTransactionAsync(token).ConfigureAwait(false);

            if (trans.Fee > Account.Balance)
            {
                throw new InsufficientFundsException($"Required: {trans.Fee.FromAettos(Unit.AE)} {Unit.AE.Name} Actual: {Account.Balance.FromAettos(Unit.AE)} {Unit.AE.Name}");
            }
            Tx             signed = Account.Client.SignTransaction(tx, Account.KeyPair.PrivateKey);
            PostTxResponse resp   = await Account.Client.PostTransactionAsync(signed, token).ConfigureAwait(false);

            string comp = Encoding.ComputeTxHash(signed.TX);

            if (comp != resp.TXHash)
            {
                throw new TransactionHashMismatchException($"Response Transaction Hash Mismatch Expected: {comp} Resulted: {resp.TXHash}");
            }
            TxHash = resp.TXHash;
        }
        public void PostSpendTxTest()
        {
            // get the currents accounts nonce in case a transaction is already
            // created and increase it by one
            Account account = nativeClient.GetAccount(baseKeyPair.PublicKey);

            BaseKeyPair kp = BaseKeyPair.Generate();

            string           recipient        = kp.PublicKey;
            BigInteger       amount           = 1000000000000000000;
            string           payload          = "";
            ulong            ttl              = 0;
            ulong            nonce            = account.Nonce + 1;
            SpendTransaction spendTx          = nativeClient.CreateSpendTransaction(baseKeyPair.PublicKey, recipient, amount, payload, ttl, nonce);
            UnsignedTx       unsignedTxNative = spendTx.CreateUnsignedTransaction();
            Tx             signedTx           = nativeClient.SignTransaction(unsignedTxNative, baseKeyPair.PrivateKey);
            PostTxResponse txResponse         = nativeClient.PostTransaction(signedTx);

            logger.LogInformation("SpendTx hash: " + txResponse.TXHash);
            Assert.AreEqual(txResponse.TXHash, Encoding.ComputeTxHash(signedTx.TX));
        }
示例#4
0
        public void CallContractAfterDryRunOnLocalNode()
        {
            Account account = nativeClient.GetAccount(baseKeyPair.PublicKey);
            ulong   nonce   = account.Nonce + 1;

            // Compile the call contract
            Calldata calldata = nativeClient.EncodeCalldata(logger, TestConstants.TestContractSourceCode, TestConstants.TestContractFunction, TestConstants.TestContractFunctionParams);
            List <Dictionary <AccountParameter, object> > dict = new List <Dictionary <AccountParameter, object> >();

            dict.Add(new Dictionary <AccountParameter, object> {
                { AccountParameter.PUBLIC_KEY, baseKeyPair.PublicKey }
            });
            DryRunResults results = nativeClient.PerformDryRunTransactions(logger, dict, null, new List <UnsignedTx> {
                CreateUnsignedContractCallTx(nonce, calldata.CallData, null)
            });

            logger.LogInformation("callContractAfterDryRunOnLocalNode: " + JsonConvert.SerializeObject(results));
            foreach (DryRunResult result in results.Results)
            {
                Assert.AreEqual("ok", result.Result);
                var contractAfterDryRunTx = nativeClient.CreateContractCallTransaction(Constants.BaseConstants.ABI_VERSION, calldata.CallData, localDeployedContractId, result.CallObj.GasUsed, result.CallObj.GasPrice, nonce, baseKeyPair.PublicKey, 0);

                UnsignedTx unsignedTxNative = contractAfterDryRunTx.CreateUnsignedTransaction();
                Tx         signedTxNative   = nativeClient.SignTransaction(unsignedTxNative, baseKeyPair.PrivateKey);

                // post the signed contract call tx
                PostTxResponse postTxResponse = nativeClient.PostTx(logger, signedTxNative);
                Assert.AreEqual(postTxResponse.TXHash, Encoding.ComputeTxHash(signedTxNative.TX));
                logger.LogInformation("CreateContractTx hash: " + postTxResponse.TXHash);

                // get the tx info object to resolve the result
                TxInfoObject txInfoObject = nativeClient.WaitForTxInfoObject(logger, postTxResponse.TXHash);

                // decode the result to json
                JToken json = nativeClient.DecodeCallResult(TestConstants.TestContractSourceCode, TestConstants.TestContractFunction, txInfoObject.CallInfo.ReturnType, txInfoObject.CallInfo.ReturnValue, CompileOptsBackend.Fate);


                Assert.AreEqual(TestConstants.TestContractFunctionParam, json.Value <string>());
            }
        }