Пример #1
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);
        }
Пример #2
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);
            }
        }
Пример #3
0
        public void TestVerifyTransactionHoursSpending()
        {
            FullCases2();

            for (int i = 0; i < cases.Length; i++)
            {
                var tc    = cases[i];
                var uxIn  = new coin_UxOutArray();
                var uxOut = new coin_UxOutArray();

                uxIn.allocate(tc.inUxs.Length);
                uxOut.allocate(tc.outUxs.Length);
                for (int j = 0; j < tc.inUxs.Length; j++)
                {
                    var ch    = tc.inUxs[j];
                    var puxIn = new coin__UxOut();
                    puxIn.Body.Coins = ch.coins;
                    puxIn.Body.Hours = ch.hours;
                    uxIn.setAt(j, puxIn);
                }
                for (int j = 0; j < tc.outUxs.Length; j++)
                {
                    var ch     = tc.outUxs[j];
                    var puxOut = new coin__UxOut();
                    puxOut.Body.Coins = ch.coins;
                    puxOut.Body.Hours = ch.hours;
                    uxOut.setAt(j, puxOut);
                }
                Assert.AreEqual(tc.inUxs.Length, uxIn.count);
                Assert.AreEqual(tc.outUxs.Length, uxOut.count);
                var err = SKY_coin_VerifyTransactionHoursSpending(tc.headTime, uxIn, uxOut);
                Assert.AreEqual(err, tc.err);
            }
        }
Пример #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 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);
        }
Пример #6
0
        public void TestTransactionVerifyInput()
        {
            // Valid
            var uxOut  = new coin__UxOut();
            var seckey = new cipher_SecKey();
            var result = (uint)makeUxOutWithSecret(uxOut, seckey);

            Assert.AreEqual(result, SKY_OK);
            var handle = new_Transaction__Handlep();

            makeEmptyTransaction(handle);
            var ptx = makeTransactionFromUxOut(uxOut, seckey, handle);

            Assert.AreEqual(result, SKY_OK);
            var ux = new coin_UxOutArray();

            ux.allocate(0);
            ux.append(uxOut);
            result = SKY_coin_VerifyInputSignatures(handle, ux);
            Assert.AreEqual(result, SKY_OK);
        }
Пример #7
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);
        }