コード例 #1
0
        public void TestUxArrayCoinHours()
        {
            var uxa = new coin_UxOutArray();

            makeUxArray(uxa, 4);
            var count = new_GoUint64p();
            var uxo   = uxa.getAt(0);
            var err   = SKY_coin_UxArray_CoinHours(uxa, uxo.Head.Time, count);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(count), 400);
            // 1 hour later
            err = SKY_coin_UxArray_CoinHours(uxa, uxo.Head.Time + 3600, count);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(count), 404);
            // 1.5 hours later
            err = SKY_coin_UxArray_CoinHours(uxa, uxo.Head.Time + 3600 + 1800, count);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(count), 404);
            // 2 hours later
            err = SKY_coin_UxArray_CoinHours(uxa, uxo.Head.Time + 3600 + 4600, count);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(GoUint64p_value(count), 408);

            uxo            = uxa.getAt(2);
            uxo.Body.Hours = ulong.MaxValue - 100;
            uxa.setAt(2, uxo);
            uxo = uxa.getAt(0);
            err = SKY_coin_UxArray_CoinHours(uxa, uxo.Head.Time, count);
            Assert.AreEqual(err, SKY_ERROR);

            err = SKY_coin_UxArray_CoinHours(uxa, Convert.ToUInt64(uxo.Head.Time * 10e11), count);
            Assert.AreEqual(err, SKY_ErrAddEarnedCoinHoursAdditionOverflow);
        }
コード例 #2
0
        public bool manualUxArrayIsSorted(coin_UxOutArray uxa)
        {
            var sha_1  = new cipher_SHA256();
            var sha_2  = new cipher_SHA256();
            var isSort = true;

            for (int i = 0; i < uxa.count - 1; i++)
            {
                var err = SKY_coin_UxOut_Hash(uxa.getAt(i), sha_1);
                Assert.AreEqual(err, SKY_OK);
                err = SKY_coin_UxOut_Hash(uxa.getAt(i + 1), sha_2);
                Assert.AreEqual(err, SKY_OK);
                if (sha_1.isEqual(sha_2) == 0)
                {
                    isSort = false;
                }
            }
            return(isSort);
        }
コード例 #3
0
        public void TestAddressUxOutsKeys()
        {
            var uxa = new coin_UxOutArray();

            makeUxArray(uxa, 3);
            var uxH = new_AddressUxOuts__HandlePtr();
            var err = SKY_coin_NewAddressUxOuts(uxa, uxH);

            Assert.AreEqual(err, SKY_OK);
            var keys = new cipher_Addresses();

            err = SKY_coin_AddressUxOuts_Keys(uxH, keys);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(keys.count, 3);
            for (int i = 0; i < keys.count; i++)
            {
                var k   = keys.getAt(i);
                var res = uxa.getAt(0).Body.Address.isEqual(k) + uxa.getAt(1).Body.Address.isEqual(k) + uxa.getAt(2).Body.Address.isEqual(k);
                Assert.IsTrue(res > 0);
            }
        }
コード例 #4
0
        public void TestUxArraySwap()
        {
            var uxa = new coin_UxOutArray();

            uxa.allocate(2);
            var uxx = new coin__UxOut();
            var uxy = new coin__UxOut();

            makeUxOut(uxx);
            makeUxOut(uxy);
            uxa.setAt(0, uxx);
            uxa.setAt(1, uxy);
            var err = SKY_coin_UxArray_Swap(uxa, 0, 1);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(uxa.getAt(0).isEqual(uxy), 0);
            Assert.AreEqual(uxa.getAt(1).isEqual(uxx), 0);
            err = SKY_coin_UxArray_Swap(uxa, 0, 1);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(uxa.getAt(0).isEqual(uxx), 0);
            Assert.AreEqual(uxa.getAt(1).isEqual(uxy), 0);
            err = SKY_coin_UxArray_Swap(uxa, 1, 0);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(uxa.getAt(0).isEqual(uxx), 0);
            Assert.AreEqual(uxa.getAt(1).isEqual(uxy), 0);
        }
コード例 #5
0
        public void TestUxArrayHashArray()
        {
            var uxa = new coin_UxOutArray();

            makeUxArray(uxa, 4);
            var sha    = new cipher_SHA256();
            var hashes = new cipher_SHA256s();
            var err    = SKY_coin_UxArray_Hashes(uxa, hashes);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hashes.count, uxa.count);
            var uxo = uxa.getAt(0);

            err = SKY_coin_UxOut_Hash(uxo, sha);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(hashes.getAt(0).isEqual(sha), 1);
            for (int i = 0; i < hashes.count; i++)
            {
                err = SKY_coin_UxOut_Hash(uxa.getAt(i), sha);
                Assert.AreEqual(err, SKY_OK);
                Assert.AreEqual(sha.isEqual(hashes.getAt(i)), 1);
            }
        }
コード例 #6
0
        public ulong ux_Array_CoinsHours(coin_UxOutArray uxa, ulong now = 0, ulong slic = 0)
        {
            ulong result = 0;

            for (var i = slic; i < (ulong)uxa.count; i++)
            {
                var x    = uxa.getAt((int)i);
                var time = new_GoUint64p();
                var err  = SKY_coin_UxOut_CoinHours(x, now, time);
                result += GoUint64p_value(time);
                Assert.AreEqual(err, SKY_OK);
            }
            return(result);
        }
コード例 #7
0
        public void TestAddressUxOutsFlatten()
        {
            var empty = new coin_UxOutArray();

            makeUxArray(empty, 0);
            var up  = new_AddressUxOuts__HandlePtr();
            var err = SKY_coin_NewAddressUxOuts(empty, up);

            Assert.AreEqual(err, SKY_OK);
            var uxs = new coin_UxOutArray();

            makeUxArray(uxs, 3);
            var uxo = uxs.getAt(2);

            uxo.Body.Address = uxs.getAt(1).Body.Address;
            uxs.setAt(0, uxo);
            var emptyAddr = new cipher__Address();

            makeAddress(emptyAddr);

            // An empty array
            err = SKY_coin_AddressUxOuts_Set(up, emptyAddr, empty);
            Assert.AreEqual(err, SKY_OK);
            // 1 element array
            var arg = new coin_UxOutArray();

            arg.release();
            arg.allocate(1);
            arg.setAt(0, uxs.getAt(0));
            err = SKY_coin_AddressUxOuts_Set(up, uxs.getAt(0).Body.Address, arg);
            Assert.AreEqual(err, SKY_OK);
            arg.release();
            arg.allocate(2);
            arg.setAt(0, uxs.getAt(1));
            arg.setAt(1, uxs.getAt(2));
            err = SKY_coin_AddressUxOuts_Set(up, uxs.getAt(1).Body.Address, arg);
            Assert.AreEqual(err, SKY_OK);

            var flat = new coin_UxOutArray();

            err = SKY_coin_AddressUxOuts_Flatten(up, flat);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(flat.count, 2);

            for (int i = 0; i < flat.count; i++)
            {
                var ux = flat.getAt(i);
                Assert.AreNotEqual(ux.Body.Address.isEqual(emptyAddr), 1, "Is equal " + i.ToString());
            }
            if (flat.getAt(0).Body.Address.isEqual(uxs.getAt(0).Body.Address) == 1)
            {
                Assert.AreEqual(flat.getAt(0).isEqual(uxs.getAt(0)), 0);
                Assert.AreEqual(flat.getAt(0).Body.Address.isEqual(uxs.getAt(0).Body.Address), 1);
                Assert.AreEqual(flat.getAt(0 + 1).Body.Address.isEqual(uxs.getAt(0 + 1).Body.Address), 1);
                Assert.AreEqual(flat.getAt(0 + 1).isEqual(uxs.getAt(1)), 0);
            }
        }
コード例 #8
0
        public void TestUxArrayHasDupes()
        {
            var uxa = new coin_UxOutArray();

            makeUxArray(uxa, 4);
            var hasDupes = new_CharPtr();
            var err      = SKY_coin_UxArray_HasDupes(uxa, hasDupes);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(CharPtr_value(hasDupes), 0);
            uxa.setAt(0, uxa.getAt(1));
            err = SKY_coin_UxArray_HasDupes(uxa, hasDupes);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(CharPtr_value(hasDupes), 1);
        }
コード例 #9
0
        public void TestUxArraySub()
        {
            var uxa = new coin_UxOutArray();
            var uxb = new coin_UxOutArray();
            var uxc = new coin_UxOutArray();
            var uxd = new coin_UxOutArray();

            makeUxArray(uxa, 4);
            makeUxArray(uxb, 4);
            uxc.allocate(6);
            uxc.setAt(0, uxa.getAt(0));
            uxc.setAt(1, uxa.getAt(1));
            for (int i = 0; i < uxb.count; i++)
            {
                uxc.setAt(i + 2, uxb.getAt(i));
            }
            uxc.setAt(6, uxa.getAt(1));
            uxc.setAt(7, uxa.getAt(2));

            var err = SKY_coin_UxArray_Sub(uxc, uxa, uxd);

            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(uxd.count, uxb.count);
            Assert.AreEqual(uxd.isEqual(uxb), 1);
            err = SKY_coin_UxArray_Sub(uxc, uxb, uxd);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(uxd.count, 2);
            var test = new coin_UxOutArray();

            test.allocate(2);
            test.setAt(0, uxa.getAt(0));
            test.setAt(1, uxa.getAt(1));
            Assert.AreEqual(test.isEqual(uxd), 1);
            // No intersection
            err = SKY_coin_UxArray_Sub(uxa, uxb, uxd);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(uxd.isEqual(uxa), 1);
            err = SKY_coin_UxArray_Sub(uxb, uxa, uxd);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(uxd.isEqual(uxb), 1);
        }
コード例 #10
0
        public void TestNewAddressUxOuts()
        {
            var uxs = new coin_UxOutArray();

            makeUxArray(uxs, 6);
            var ux = uxs.getAt(1);

            ux.Body.Address = uxs.getAt(0).Body.Address;
            uxs.setAt(1, ux);
            ux = uxs.getAt(3);
            ux.Body.Address = uxs.getAt(2).Body.Address;
            uxs.setAt(3, ux);
            ux = uxs.getAt(4);
            ux.Body.Address = uxs.getAt(2).Body.Address;
            uxs.setAt(4, ux);

            var uxo = new_AddressUxOuts__HandlePtr();
            var err = SKY_coin_NewAddressUxOuts(uxs, uxo);

            Assert.AreEqual(err, SKY_OK);
            var len = new_Gointp();

            err = SKY_coin_AddressUxOuts_Length(uxo, len);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(Gointp_value(len), 3);
            var uxa1 = new coin_UxOutArray();
            var uxa2 = new coin_UxOutArray();

            SKY_coin_AddressUxOuts_Get(uxo, uxs.getAt(0).Body.Address, uxa1);
            Assert.AreEqual(err, SKY_OK);
            uxa2.allocate(2);
            uxa2.setAt(1, uxs.getAt(4));
            uxa2.setAt(0, uxs.getAt(0));
            uxa2.setAt(1, uxs.getAt(4));
            uxa2.setAt(1, uxs.getAt(1));
            uxa2.setAt(1, uxs.getAt(4));
            Assert.AreEqual(uxa1.isEqual(uxa2), 0);

            uxa2.setAt(1, uxs.getAt(4));
            uxa1.release();
            SKY_coin_AddressUxOuts_Get(uxo, uxs.getAt(3).Body.Address, uxa1);
            Assert.AreEqual(err, SKY_OK);
            uxa2.release();
            uxa2.allocate(3);
            uxa2.setAt(0, uxs.getAt(2));
            uxa2.setAt(1, uxs.getAt(3));
            uxa2.setAt(1, uxs.getAt(4));
            Assert.AreEqual(uxa1.isEqual(uxa2), 0);

            uxa1.release();
            SKY_coin_AddressUxOuts_Get(uxo, uxs.getAt(5).Body.Address, uxa1);
            Assert.AreEqual(err, SKY_OK);
            uxa2.release();
            uxa2.allocate(1);
            uxa2.setAt(0, uxs.getAt(5));
            Assert.AreEqual(uxa1.isEqual(uxa2), 1);
        }
コード例 #11
0
        public void TestAddressUxOutsSub()
        {
            var uxs   = new coin_UxOutArray();
            var empty = new coin_UxOutArray();

            makeUxArray(uxs, 4);
            makeUxArray(empty, 0);

            var up  = new_AddressUxOuts__HandlePtr();
            var err = SKY_coin_NewAddressUxOuts(empty, up);

            Assert.AreEqual(err, SKY_OK);
            var up2 = new_AddressUxOuts__HandlePtr();

            err = SKY_coin_NewAddressUxOuts(empty, up2);
            Assert.AreEqual(err, SKY_OK);

            var uxo = uxs.getAt(1);

            uxo.Body.Address = uxs.getAt(0).Body.Address;
            uxs.setAt(1, uxo);

            var arg = new coin_UxOutArray();

            arg.release();
            arg.allocate(1);
            arg.setAt(0, uxs.getAt(0));
            err = SKY_coin_AddressUxOuts_Set(up, uxs.getAt(0).Body.Address, arg);
            Assert.AreEqual(err, SKY_OK);
            arg.release();
            arg.allocate(1);
            arg.setAt(0, uxs.getAt(2));
            err = SKY_coin_AddressUxOuts_Set(up, uxs.getAt(2).Body.Address, arg);
            Assert.AreEqual(err, SKY_OK);
            arg.release();
            arg.allocate(1);
            arg.setAt(0, uxs.getAt(3));
            err = SKY_coin_AddressUxOuts_Set(up, uxs.getAt(3).Body.Address, arg);
            Assert.AreEqual(err, SKY_OK);

            arg.release();
            arg.allocate(1);
            arg.setAt(0, uxs.getAt(1));
            err = SKY_coin_AddressUxOuts_Set(up2, uxs.getAt(1).Body.Address, arg);
            Assert.AreEqual(err, SKY_OK);
            arg.release();
            arg.allocate(1);
            arg.setAt(0, uxs.getAt(2));
            err = SKY_coin_AddressUxOuts_Set(up2, uxs.getAt(2).Body.Address, arg);
            Assert.AreEqual(err, SKY_OK);

            var up3 = new_AddressUxOuts__HandlePtr();

            err = SKY_coin_AddressUxOuts_Add(up, up2, up3);
            Assert.AreEqual(err, SKY_OK);
            var len = new_Gointp();

            err = SKY_coin_AddressUxOuts_Length(up3, len);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(Gointp_value(len), 3);
            err = SKY_coin_AddressUxOuts_Length(up2, len);
            Assert.AreEqual(err, SKY_OK);
            Assert.AreEqual(Gointp_value(len), 2);
        }