Beispiel #1
0
        public void TestOp1()
        {
            BigInteger i1 = 1;
            BigInteger i2 = 12102159;
            bool       b1 = true;
            bool       b2 = false;
            string     s1 = "";
            string     s2 = "adfeav";

            byte[] bi1 = Op.BigInt2Bytes(i1);
            byte[] bi2 = Op.BigInt2Bytes(i2);
            byte[] bb1 = Op.Bool2Bytes(b1);
            byte[] bb2 = Op.Bool2Bytes(b2);
            byte[] bs1 = Op.String2Bytes(s1);
            byte[] bs2 = Op.String2Bytes(s2);

            Assert.AreNotEqual(bi1, bi2);
        }
Beispiel #2
0
        public static byte[] IsWinner(BigInteger gameId, BigInteger entryId)
        {
            Game game = GetGame(gameId);

            if (game == null)
            {
                return(NuTP.RespDataWithCode(NuTP.SysDom, NuTP.Code.BadRequest));
            }
            else
            {
                BigInteger height = Blockchain.GetHeight();
                if (height < game.heightStage2)
                {
                    return(NuTP.RespDataWithCode(NuTP.SysDom, NuTP.Code.Forbidden));
                }
                else
                {
                    Entry entry = GetEntry(gameId, entryId);
                    bool  ret   = entry.pick == game.winnerPick;
                    return(NuTP.RespDataSucWithBody(Op.Bool2Bytes(ret)));
                }
            }
        }
Beispiel #3
0
        public void TestOpNull()
        {
            /**
             *  Default Values:
             *  For the type BigInteger and String, if the value is empty (zero byte), the logic should convert them to the default value.
             *  Specifically,
             *  -   the default value of bool is false
             *  -   the default value of BigInteger is 0
             *  -   the default value of String is "\0"
             *
             *  To convert the default value back to byte[], the result would be "0x00" rather than null.
             */
            byte[] nullBA = new byte[0];
            byte[] zBA    = new byte[1] {
                0x00
            };
            //----- Bool -------
            bool b1 = false;

            Assert.AreEqual(b1, Op.Bytes2Bool(nullBA));
            Assert.AreEqual(Op.Bool2Bytes(b1), zBA);

            //----- BigInt -------
            BigInteger big = Op.Bytes2BigInt(nullBA);
            BigInteger bp1 = big + 1;

            Assert.AreEqual(big, new BigInteger(0));
            Assert.AreEqual(bp1, new BigInteger(1));
            Assert.AreEqual(Op.BigInt2Bytes(big), zBA);

            //----- String -------
            String str = Op.Bytes2String(nullBA);

            Assert.AreEqual(str, "\0");
            Assert.AreEqual(Op.String2Bytes(str), zBA);
        }
Beispiel #4
0
 public static byte[] SegBool(bool body) => Seg(Op.Bool2Bytes(body));