Exemplo n.º 1
0
        public void FullburnFactor2verifyTxFeeTestCase()
        {
            verifyTxFeeTestCase cases = new verifyTxFeeTestCase();

            cases.inputHours = 0;
            cases.ouputHours = 0;
            cases.err        = SKY_ErrTxnNoFee;
            burnFactor2verifyTxFeeTestCase[0] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 1;
            cases.ouputHours = 0;
            cases.err        = SKY_OK;
            burnFactor2verifyTxFeeTestCase[1] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 1;
            cases.ouputHours = 1;
            cases.err        = SKY_ErrTxnNoFee;
            burnFactor2verifyTxFeeTestCase[2] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 2;
            cases.ouputHours = 0;
            cases.err        = SKY_OK;
            burnFactor2verifyTxFeeTestCase[3] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 2;
            cases.ouputHours = 1;
            cases.err        = SKY_OK;
            burnFactor2verifyTxFeeTestCase[4] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 2;
            cases.ouputHours = 2;
            cases.err        = SKY_ErrTxnNoFee;
            burnFactor2verifyTxFeeTestCase[5] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 3;
            cases.ouputHours = 0;
            cases.err        = SKY_OK;
            burnFactor2verifyTxFeeTestCase[6] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 3;
            cases.ouputHours = 1;
            cases.err        = SKY_OK;
            burnFactor2verifyTxFeeTestCase[7] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 3;
            cases.ouputHours = 2;
            cases.err        = SKY_ErrTxnInsufficientFee;
            burnFactor2verifyTxFeeTestCase[8] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 3;
            cases.ouputHours = 3;
            cases.err        = SKY_ErrTxnNoFee;
            burnFactor2verifyTxFeeTestCase[9] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 4;
            cases.ouputHours = 0;
            cases.err        = SKY_OK;
            burnFactor2verifyTxFeeTestCase[10] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 4;
            cases.ouputHours = 1;
            cases.err        = SKY_OK;
            burnFactor2verifyTxFeeTestCase[11] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 4;
            cases.ouputHours = 2;
            cases.err        = SKY_OK;
            burnFactor2verifyTxFeeTestCase[12] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 4;
            cases.ouputHours = 3;
            cases.err        = SKY_ErrTxnInsufficientFee;
            burnFactor2verifyTxFeeTestCase[13] = cases;

            cases            = new verifyTxFeeTestCase();
            cases.inputHours = 4;
            cases.ouputHours = 4;
            cases.err        = SKY_ErrTxnNoFee;
            burnFactor2verifyTxFeeTestCase[14] = cases;
        }
Exemplo n.º 2
0
        public void TestVerifyTransactionFee()
        {
            FullburnFactor2verifyTxFeeTestCase();
            var empty = transutils.makeEmptyTransaction();
            var hours = new_GoUint64p();
            var err   = SKY_coin_Transaction_OutputHours(empty, hours);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), 0);

            // A txn with no outputs hours and no coinhours burn fee is valid
            err = SKY_fee_VerifyTransactionFee(empty, 0, 2);
            Assert.AreEqual(err, SKY_ErrTxnNoFee);

            // A txn with no outputs hours but with a coinhours burn fee is valid
            err = SKY_fee_VerifyTransactionFee(empty, 100, 2);
            Assert.AreEqual(err, SKY_OK);
            var txn  = transutils.makeEmptyTransaction();
            var addr = new cipher__Address();

            addr = transutils.makeAddress();
            Assert.AreEqual(err, 0);
            err = SKY_coin_Transaction_PushOutput(txn, addr, 0, 1000000);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_PushOutput(txn, addr, 0, 3000000);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_OutputHours(txn, hours);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(hours), 4000000);

            // A txn with insufficient net coinhours burn fee is invalid
            err = SKY_fee_VerifyTransactionFee(txn, 0, 2);
            Assert.AreEqual(err, SKY_ErrTxnNoFee);
            err = SKY_fee_VerifyTransactionFee(txn, 1, 2);
            Assert.AreEqual(err, SKY_ErrTxnInsufficientFee);

            // A txn with sufficient net coinhours burn fee is valid
            err = SKY_coin_Transaction_OutputHours(txn, hours);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_fee_VerifyTransactionFee(txn, GoUint64p_value(hours), 2);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_coin_Transaction_OutputHours(txn, hours);
            Assert.AreEqual(err, SKY_OK);
            err = SKY_fee_VerifyTransactionFee(txn, ((ulong)(GoUint64p_value(hours) * 10)), 2);
            Assert.AreEqual(err, SKY_OK);

            // fee + hours overflows
            err = SKY_fee_VerifyTransactionFee(txn, ((ulong.MaxValue - 3000000)), 2);
            Assert.AreEqual(err, SKY_ERROR);

            // txn has overflowing output hours
            err = SKY_coin_Transaction_PushOutput(txn, addr, 0,
                                                  (ulong.MaxValue - 1000000 - 3000000 + 1));
            Assert.AreEqual(err, SKY_OK, "txn has overflowing output hours");
            err = SKY_fee_VerifyTransactionFee(txn, 10, 2);
            Assert.AreEqual(err, SKY_ERROR, "SKY_fee_VerifyTransactionFee failed");

            int len = burnFactor2verifyTxFeeTestCase.Length;

            for (int i = 0; i < len; i++)
            {
                txn = new_Transaction__Handlep();
                txn = transutils.makeEmptyTransaction();
                verifyTxFeeTestCase tc = burnFactor2verifyTxFeeTestCase[i];
                err = SKY_coin_Transaction_PushOutput(txn, addr, 0, tc.ouputHours);
                Assert.AreEqual(err, SKY_OK);
                Assert.IsTrue(tc.inputHours >= tc.ouputHours);
                err = SKY_fee_VerifyTransactionFee(txn, (ulong)(tc.inputHours - tc.ouputHours), 2);
                Assert.AreEqual(tc.err, err, "Iter " + i.ToString() + " is " + tc.err.ToString() + " != " + err.ToString());;
            }
        }