コード例 #1
0
ファイル: BlockTest.cs プロジェクト: longfin/libplanet.net
        public void Constructor()
        {
            var contents      = new BlockContentFixture();
            var random        = new System.Random();
            var stateRootHash = random.NextHashDigest <SHA256>();
            PreEvaluationBlock <Arithmetic> preEval = contents.Genesis.Mine(_fx.GetHashAlgorithm(0));
            ImmutableArray <byte>           sig     = preEval.MakeSignature(contents.GenesisKey, stateRootHash);
            var block = new Block <Arithmetic>(preEval, stateRootHash, sig);

            AssertPreEvaluationBlocksEqual(preEval, block);
            AssertBytesEqual(stateRootHash, block.StateRootHash);
            AssertBytesEqual(sig, block.Signature);
        }
コード例 #2
0
        public BlockMarshalerTest(
            BlockFixture fixture,
            BlockContentFixture contentFixture,
            ITestOutputHelper output
            )
        {
            _output  = output;
            _fx      = fixture;
            _content = contentFixture;

            _marshaledGenesisMetadata = Dictionary.Empty
                                        .Add(ProtocolVersionKey, _fx.Genesis.ProtocolVersion)
                                        .Add(IndexKey, _fx.Genesis.Index)
                                        .Add(
                TimestampKey,
                _fx.Genesis.Timestamp.ToString(TimestampFormat, CultureInfo.InvariantCulture))
                                        .Add(DifficultyKey, _fx.Genesis.Difficulty)
                                        .Add(TotalDifficultyKey, (IValue)(Integer)_fx.Genesis.TotalDifficulty)
                                        .Add(PublicKeyKey, _fx.Genesis.PublicKey.Format(compress: true));
            var expectedGenesisHeader = _marshaledGenesisMetadata
                                        .Add(NonceKey, _fx.Genesis.Nonce.ByteArray)
                                        .Add(PreEvaluationHashKey, _fx.Genesis.PreEvaluationHash)
                                        .Add(StateRootHashKey, _fx.Genesis.StateRootHash.ByteArray)
                                        .Add(SignatureKey, _fx.Genesis.Signature ?? default)
                                        .Add(HashKey, _fx.Genesis.Hash.ByteArray);

            _marshaledGenesis = Dictionary.Empty
                                .Add(HeaderKey, expectedGenesisHeader);

            _marshaledNextMetadata = Dictionary.Empty
                                     .Add(ProtocolVersionKey, _fx.Next.ProtocolVersion)
                                     .Add(IndexKey, _fx.Next.Index)
                                     .Add(PreviousHashKey, _fx.Next.PreviousHash.Value.ByteArray)
                                     .Add(
                TimestampKey,
                _fx.Next.Timestamp.ToString(TimestampFormat, CultureInfo.InvariantCulture))
                                     .Add(DifficultyKey, _fx.Next.Difficulty)
                                     .Add(TotalDifficultyKey, (IValue)(Integer)_fx.Next.TotalDifficulty)
                                     .Add(PublicKeyKey, _fx.Next.PublicKey.Format(compress: true));
            var expectedNextHeader = _marshaledNextMetadata
                                     .Add(NonceKey, _fx.Next.Nonce.ByteArray)
                                     .Add(PreEvaluationHashKey, _fx.Next.PreEvaluationHash)
                                     .Add(StateRootHashKey, _fx.Next.StateRootHash.ByteArray)
                                     .Add(SignatureKey, _fx.Next.Signature ?? default)
                                     .Add(HashKey, _fx.Next.Hash.ByteArray);

            _marshaledNext = Dictionary.Empty
                             .Add(HeaderKey, expectedNextHeader);

            _marshaledHasTxMetadata = Dictionary.Empty
                                      .Add(ProtocolVersionKey, _fx.HasTx.ProtocolVersion)
                                      .Add(IndexKey, _fx.HasTx.Index)
                                      .Add(PreviousHashKey, _fx.HasTx.PreviousHash.Value.ByteArray)
                                      .Add(
                TimestampKey,
                _fx.HasTx.Timestamp.ToString(TimestampFormat, CultureInfo.InvariantCulture))
                                      .Add(DifficultyKey, _fx.HasTx.Difficulty)
                                      .Add(TotalDifficultyKey, (IValue)(Integer)_fx.HasTx.TotalDifficulty)
                                      .Add(PublicKeyKey, _fx.HasTx.PublicKey.Format(true))
                                      .Add(TxHashKey, _fx.HasTx.TxHash.Value.ByteArray);
            var expectedHasTxHeader = _marshaledHasTxMetadata
                                      .Add(NonceKey, _fx.HasTx.Nonce.ByteArray)
                                      .Add(PreEvaluationHashKey, _fx.HasTx.PreEvaluationHash)
                                      .Add(StateRootHashKey, _fx.HasTx.StateRootHash.ByteArray)
                                      .Add(SignatureKey, _fx.HasTx.Signature ?? default)
                                      .Add(HashKey, _fx.HasTx.Hash.ByteArray);
            IValue expectedHasTxTxs = new List(
                _fx.HasTx.Transactions.Select(tx => (Binary)tx.Serialize(true)).Cast <IValue>()
                );

            _marshaledHasTx = Dictionary.Empty
                              .Add(HeaderKey, expectedHasTxHeader)
                              .Add(TransactionsKey, expectedHasTxTxs);
        }