コード例 #1
0
        public void Equals_SameHash()
        {
            Block   newBlock = new Block();
            UInt256 prevHash = new UInt256(TestUtils.GetByteArray(32, 0x42));
            UInt256 merkRoot;
            UInt160 val160;
            uint    timestampVal, indexVal;
            ulong   consensusDataVal;
            Witness scriptVal;

            Transaction[] transactionsVal;
            TestUtils.SetupBlockWithValues(newBlock, prevHash, out merkRoot, out val160, out timestampVal, out indexVal, out consensusDataVal, out scriptVal, out transactionsVal, 1);
            TestUtils.SetupBlockWithValues(uut, prevHash, out merkRoot, out val160, out timestampVal, out indexVal, out consensusDataVal, out scriptVal, out transactionsVal, 1);

            uut.Equals(newBlock).Should().BeTrue();
        }
コード例 #2
0
        public void CalculateNetFee_SystemFee()
        {
            UInt256 val256 = UInt256.Zero;
            UInt256 merkRootVal;
            UInt160 val160;
            uint    timestampVal, indexVal;
            ulong   consensusDataVal;
            Witness scriptVal;

            Transaction[] transactionsVal;
            TestUtils.SetupBlockWithValues(uut, val256, out merkRootVal, out val160, out timestampVal, out indexVal, out consensusDataVal, out scriptVal, out transactionsVal, 0);

            uut.Transactions = new Transaction[1] {
                TestUtils.GetIssueTransaction(true, 0, new UInt256(TestUtils.GetByteArray(32, 0x42)))
            };

            Block.CalculateNetFee(uut.Transactions).Should().Be(Fixed8.FromDecimal(-500));
        }
コード例 #3
0
        public void Size_Get_5_Votes_5_Balance()
        {
            UInt160 val = new UInt160();

            ECPoint[] array = new ECPoint[] { new ECPoint(), new ECPoint(), new ECPoint(), new ECPoint(), new ECPoint() };
            Dictionary <UInt256, Fixed8> dict = new Dictionary <UInt256, Fixed8>();

            dict.Add(new UInt256(), new Fixed8());
            dict.Add(new UInt256(TestUtils.GetByteArray(32, 0x20)), new Fixed8());
            dict.Add(new UInt256(TestUtils.GetByteArray(32, 0x21)), new Fixed8());
            dict.Add(new UInt256(TestUtils.GetByteArray(32, 0x22)), new Fixed8());
            dict.Add(new UInt256(TestUtils.GetByteArray(32, 0x23)), new Fixed8());

            uut.ScriptHash = val;
            uut.Votes      = array;
            uut.Balances   = dict;

            uut.Size.Should().Be(229); // 1 + 20 + 1 + 6 + 1 + 5 * (32 + 8)
        }
コード例 #4
0
        private void setupAssetStateWithValues(AssetState assetState, out UInt256 assetId, out AssetType assetType, out string name, out Fixed8 amount, out Fixed8 available, out byte precision, out Fixed8 fee, out UInt160 feeAddress, out ECPoint owner, out UInt160 admin, out UInt160 issuer, out uint expiration, out bool isFrozen)
        {
            assetId              = new UInt256(TestUtils.GetByteArray(32, 0x20));
            assetState.AssetId   = assetId;
            assetType            = AssetType.Token;
            assetState.AssetType = assetType;

            name            = "BHP";
            assetState.Name = name;

            amount            = new Fixed8(42);
            assetState.Amount = amount;

            available            = new Fixed8(43);
            assetState.Available = available;

            precision            = 0x42;
            assetState.Precision = precision;

            fee            = new Fixed8(44);
            assetState.Fee = fee;

            feeAddress            = new UInt160(TestUtils.GetByteArray(20, 0x21));
            assetState.FeeAddress = feeAddress;

            owner            = ECPoint.DecodePoint(TestUtils.GetByteArray(1, 0x00), ECCurve.Secp256r1);
            assetState.Owner = owner;

            admin            = new UInt160(TestUtils.GetByteArray(20, 0x22));
            assetState.Admin = admin;

            issuer            = new UInt160(TestUtils.GetByteArray(20, 0x23));
            assetState.Issuer = issuer;

            expiration            = 42u;
            assetState.Expiration = expiration;

            isFrozen            = true;
            assetState.IsFrozen = isFrozen;
        }
コード例 #5
0
        public void Serialize()
        {
            uut.Value = TestUtils.GetByteArray(10, 0x42);

            byte[] data;
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(stream, Encoding.ASCII, true))
                {
                    uut.Serialize(writer);
                    data = stream.ToArray();
                }
            }

            byte[] requiredData = new byte[] { 0, 10, 66, 32, 32, 32, 32, 32, 32, 32, 32, 32 };

            data.Length.Should().Be(12);
            for (int i = 0; i < 12; i++)
            {
                data[i].Should().Be(requiredData[i]);
            }
        }
コード例 #6
0
 public void GetScriptHashesForVerifying_Ordered()
 {
     TestUtils.SetupTestBlockchain(UInt256.Zero);
     uut = new IssueTransaction
     {
         Attributes = new TransactionAttribute[0],
         Inputs     = new CoinReference[0],
         Outputs    = new[]
         {
             new TransactionOutput
             {
                 AssetId    = Blockchain.UtilityToken.Hash,
                 Value      = Fixed8.FromDecimal(10),
                 ScriptHash = Contract.CreateMultiSigRedeemScript(1, TestUtils.StandbyValidators).ToScriptHash()
             },
             new TransactionOutput
             {
                 AssetId    = Blockchain.GoverningToken.Hash,
                 Value      = Fixed8.FromDecimal(10),
                 ScriptHash = Contract.CreateMultiSigRedeemScript(1, TestUtils.StandbyValidators).ToScriptHash()
             },
         },
         Scripts = new[]
         {
             new Witness
             {
                 InvocationScript   = new byte[0],
                 VerificationScript = new[] { (byte)OpCode.PUSHT }
             }
         }
     };
     UInt160[] res = uut.GetScriptHashesForVerifying();
     res.Length.Should().Be(2);
     res[0].Should().Be(new UInt160(TestUtils.GetByteArray(20, 0x9b)));
     res[1].Should().Be(new UInt160(TestUtils.GetByteArray(20, 0xe7)));
 }
コード例 #7
0
 public void Size_Get_Larger()
 {
     uut.Value = TestUtils.GetByteArray(88, 0x42);
     uut.Size.Should().Be(90); // 2 + 88
 }
コード例 #8
0
 public void Size_Get()
 {
     uut.Value = TestUtils.GetByteArray(10, 0x42);
     uut.Size.Should().Be(12); // 2 + 10
 }
コード例 #9
0
ファイル: UT_StorageKey.cs プロジェクト: BhpDevGroup/BhpAll
 public void GetHashCode_Get()
 {
     uut.ScriptHash = new UInt160(TestUtils.GetByteArray(20, 0x42));
     uut.Key        = TestUtils.GetByteArray(10, 0x42);
     uut.GetHashCode().Should().Be(806209853);
 }
コード例 #10
0
 public void Size()
 {
     uut.PrevHash = new UInt256(TestUtils.GetByteArray(32, 0x42));
     uut.Size.Should().Be(34);
 }
コード例 #11
0
        public void GetScriptHashesForVerifying_2_Claim()
        {
            CoinReference[] refs = new[] { TestUtils.GetCoinReference(new UInt256(TestUtils.GetByteArray(32, 0x42))), TestUtils.GetCoinReference(new UInt256(TestUtils.GetByteArray(32, 0x48))) };
            uut.Claims     = refs;
            uut.Attributes = new TransactionAttribute[0];
            uut.Inputs     = new CoinReference[0];
            uut.Outputs    = new TransactionOutput[0];
            uut.Scripts    = new Witness[0];

            TestUtils.SetupTestBlockchain(UInt256.Zero);

            UInt160[] res = uut.GetScriptHashesForVerifying();
            res.Length.Should().Be(2);
        }
コード例 #12
0
 public void Size_Get_DescriptionUrl()
 {
     uut.Usage = TransactionAttributeUsage.DescriptionUrl;
     uut.Data  = TestUtils.GetByteArray(10, 0x42);
     uut.Size.Should().Be(12); // 1 + 1 + 10
 }
コード例 #13
0
 public void Size_Get_OtherAttribute()
 {
     uut.Usage = TransactionAttributeUsage.Remark;
     uut.Data  = TestUtils.GetByteArray(10, 0x42);
     uut.Size.Should().Be(12); // 1 + 11
 }
コード例 #14
0
 public override Transaction GetTransaction(UInt256 hash, out int height)
 {
     height = 0;
     // take part of the trans hash and use that for the scripthash of the testtransaction
     return(new TestTransaction(_assetId, TransactionType.ClaimTransaction, new UInt160(TestUtils.GetByteArray(20, hash.ToArray()[0]))));
 }