Example #1
0
        public void EvaluateTxs()
        {
            DumbAction MakeAction(Address address, char identifier, Address?transferTo = null)
            {
                return(new DumbAction(
                           targetAddress: address,
                           item: identifier.ToString(),
                           recordRehearsal: false,
                           recordRandom: true,
                           transfer: transferTo is Address to
                        ? Tuple.Create <Address, Address, BigInteger>(address, to, 5)
                        : null));
            }

            Address[] addresses =
            {
                _txFx.Address1,
                _txFx.Address2,
                _txFx.Address3,
                _txFx.Address4,
                _txFx.Address5,
            };
            HashAlgorithmType   hashAlgorithm  = HashAlgorithmType.Of <SHA256>();
            HashAlgorithmGetter hashAlgoGetter = _ => hashAlgorithm;
            Block <DumbAction>  genesis        = MineGenesisBlock <DumbAction>(
                hashAlgoGetter,
                TestUtils.GenesisMiner
                );
            ActionEvaluator <DumbAction> actionEvaluator = new ActionEvaluator <DumbAction>(
                hashAlgorithmGetter: _ => HashAlgorithmType.Of <SHA256>(),
                policyBlockAction: null,
                stateGetter: ActionEvaluator <DumbAction> .NullStateGetter,
                balanceGetter: ActionEvaluator <DumbAction> .NullBalanceGetter,
                trieGetter: null);
            IAccountStateDelta previousStates = genesis.ProtocolVersion > 0
                ? new AccountStateDeltaImpl(
                ActionEvaluator <DumbAction> .NullAccountStateGetter,
                ActionEvaluator <DumbAction> .NullAccountBalanceGetter,
                genesis.Miner)
                : new AccountStateDeltaImplV0(
                ActionEvaluator <DumbAction> .NullAccountStateGetter,
                ActionEvaluator <DumbAction> .NullAccountBalanceGetter,
                genesis.Miner);

            Assert.Empty(
                actionEvaluator.EvaluateTxs(
                    block: genesis,
                    previousStates: previousStates));

            Transaction <DumbAction>[] block1Txs =
            {
                Transaction <DumbAction> .Create(
                    nonce: 0,
                    privateKey: _txFx.PrivateKey1,
                    genesisHash: genesis.Hash,
                    actions: new[]
                {
                    MakeAction(addresses[0],                          'A',  addresses[1]),
                    MakeAction(addresses[1],                          'B',  addresses[2]),
                },
                    timestamp: DateTimeOffset.MinValue.AddSeconds(2)),
                Transaction <DumbAction> .Create(
                    nonce: 0,
                    privateKey: _txFx.PrivateKey2,
                    genesisHash: genesis.Hash,
                    actions: new[] { MakeAction(addresses[2],         'C',  addresses[3]) },
                    timestamp: DateTimeOffset.MinValue.AddSeconds(4)),
                Transaction <DumbAction> .Create(
                    nonce: 0,
                    privateKey: _txFx.PrivateKey3,
                    genesisHash: genesis.Hash,
                    actions: new DumbAction[0],
                    timestamp: DateTimeOffset.MinValue.AddSeconds(7)),
            };
            int i = 0;

            foreach (Transaction <DumbAction> tx in block1Txs)
            {
                _logger.Debug("{0}[{1}] = {2}", nameof(block1Txs), i, tx.Id);
            }

            Block <DumbAction> block1 = MineNextBlock(
                genesis,
                hashAlgoGetter,
                GenesisMiner,
                block1Txs,
                new byte[] { }
                );

            previousStates = block1.ProtocolVersion > 0
                ? new AccountStateDeltaImpl(
                ActionEvaluator <DumbAction> .NullAccountStateGetter,
                ActionEvaluator <DumbAction> .NullAccountBalanceGetter,
                block1.Miner)
                : new AccountStateDeltaImplV0(
                ActionEvaluator <DumbAction> .NullAccountStateGetter,
                ActionEvaluator <DumbAction> .NullAccountBalanceGetter,
                block1.Miner);
            var evals = actionEvaluator.EvaluateTxs(
                block1,
                previousStates).ToImmutableArray();
            int randomValue = 0;

            (int TxIdx, int ActionIdx, string[] UpdatedStates, Address Signer)[] expectations =