Пример #1
0
        public async Task ShouldPassCyprusTransactionTest(string from, string to)
        {
            PrivateKey sender = from, receiver = to;
            string     error, txid;
            bool?      mining;
            ulong?     balance;
            JObject    receipt, tx;
            JArray     history;

            // sender should has at leat 1 brc for transaction test
            (balance, error) = await cyprus.GetBalanceAsync(sender.Address);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(balance);
            Assert.True(balance >= Coin.ToBeryl(1));

            // should mining
            (mining, error) = await cyprus.GetMiningAsync();

            Assert.True(string.IsNullOrEmpty(error));
            Assert.True(mining);

            // send transfer
            (txid, error) = await cyprus.SendTransferAsync(sender, receiver.Address, Coin.ToBeryl(0.0001m));

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(string.IsNullOrEmpty(txid));

            // get transaction receipt
            (receipt, error) = await cyprus.WaitTransactionReceiptAsync(txid);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(receipt is null);
            Assert.True(receipt.Value <string>("hash") == txid);

            // get transaction
            (tx, error) = await cyprus.GetTransactionByHashAsync(txid);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(tx is null);
            Assert.True(tx.Value <string>("hash") == txid);

            // get transaction by block hash and index
            (var tx1, string err1) = await cyprus.GetTransactionByBlockHashAndIndexAsync(tx.Value <string>("blockHash"), Hex.ToNumber <int>(tx.Value <string>("blockIndex")));

            Assert.True(string.IsNullOrEmpty(err1));
            Assert.False(tx1 is null);
            Assert.True(tx1.Value <string>("hash") == txid);

            // get transaction by block number and index
            (var tx2, string err2) = await cyprus.GetTransactionByBlockNumberAndIndexAsync(Hex.ToNumber <long>(tx.Value <string>("blockNumber")), Hex.ToNumber <int>(tx.Value <string>("blockIndex")));

            Assert.True(string.IsNullOrEmpty(err2));
            Assert.False(tx2 is null);
            Assert.True(tx2.Value <string>("hash") == txid);

            // get transaction history of sender
            (history, error) = await cyprus.GetTransactionsByAddressAsync(sender.Address, Hex.ToNumber <long>(tx.Value <string>("blockNumber")), true, 20);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(history is null);
            Assert.True(history.ToObject <IEnumerable <JObject> >().Where(t => t.Value <string>("hash") == txid).Count() > 0);

            // get transaction history of receiver
            (history, error) = await cyprus.GetTransactionsByAddressAsync(receiver.Address, Hex.ToNumber <long>(tx.Value <string>("blockNumber")), false, 20);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(history is null);
            Assert.True(history.ToObject <IEnumerable <JObject> >().Where(t => t.Value <string>("hash") == txid).Count() > 0);

            // send withdraw
            (txid, error) = await cyprus.SendWithdrawAsync(sender, sender.Address, Coin.ToBeryl(0.1m));

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(string.IsNullOrEmpty(txid));

            // wait for withdraw confirm
            (receipt, error) = await cyprus.WaitTransactionReceiptAsync(txid);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(receipt is null);
            Assert.Equal(receipt.Value <string>("hash"), txid);
        }