예제 #1
0
        public void TxExecution()
        {
            void AssertTxSuccessesEqual(TxSuccess expected, TxExecution actual)
            {
                Assert.IsType <TxSuccess>(actual);
                var success = (TxSuccess)actual;

                Assert.Equal(expected.TxId, success.TxId);
                Assert.Equal(expected.BlockHash, success.BlockHash);
                Assert.Equal(expected.UpdatedStates, success.UpdatedStates);
                Assert.Equal(expected.FungibleAssetsDelta, success.FungibleAssetsDelta);
                Assert.Equal(expected.UpdatedFungibleAssets, success.UpdatedFungibleAssets);
            }

            void AssertTxFailuresEqual(TxFailure expected, TxExecution actual)
            {
                Assert.IsType <TxFailure>(actual);
                var failure = (TxFailure)actual;

                Assert.Equal(expected.TxId, failure.TxId);
                Assert.Equal(expected.BlockHash, failure.BlockHash);
                Assert.Equal(expected.ExceptionName, failure.ExceptionName);
                Assert.Equal(expected.ExceptionMetadata, failure.ExceptionMetadata);
            }

            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash1, Fx.TxId1));
            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash1, Fx.TxId2));
            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash2, Fx.TxId1));
            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash2, Fx.TxId2));

            var random = new System.Random();
            var inputA = new TxSuccess(
                Fx.Hash1,
                Fx.TxId1,
                ImmutableDictionary <Address, IValue> .Empty.Add(
                    random.NextAddress(),
                    (Text)"state value"
                    ),
                ImmutableDictionary <Address, IImmutableDictionary <Currency, FAV> > .Empty
                .Add(
                    random.NextAddress(),
                    ImmutableDictionary <Currency, FAV> .Empty.Add(
                        DumbAction.DumbCurrency,
                        DumbAction.DumbCurrency * 5
                        )
                    ),
                ImmutableDictionary <Address, IImmutableDictionary <Currency, FAV> > .Empty
                .Add(
                    random.NextAddress(),
                    ImmutableDictionary <Currency, FAV> .Empty.Add(
                        DumbAction.DumbCurrency,
                        DumbAction.DumbCurrency * 10
                        )
                    )
                );

            Fx.Store.PutTxExecution(inputA);

            AssertTxSuccessesEqual(inputA, Fx.Store.GetTxExecution(Fx.Hash1, Fx.TxId1));
            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash1, Fx.TxId2));
            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash2, Fx.TxId1));
            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash2, Fx.TxId2));

            var inputB = new TxFailure(
                Fx.Hash1,
                Fx.TxId2,
                "AnExceptionName",
                Dictionary.Empty.Add("foo", 1).Add("bar", "baz")
                );

            Fx.Store.PutTxExecution(inputB);

            AssertTxSuccessesEqual(inputA, Fx.Store.GetTxExecution(Fx.Hash1, Fx.TxId1));
            AssertTxFailuresEqual(inputB, Fx.Store.GetTxExecution(Fx.Hash1, Fx.TxId2));
            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash2, Fx.TxId1));
            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash2, Fx.TxId2));

            var inputC = new TxFailure(
                Fx.Hash2,
                Fx.TxId1,
                "AnotherExceptionName",
                null
                );

            Fx.Store.PutTxExecution(inputC);

            AssertTxSuccessesEqual(inputA, Fx.Store.GetTxExecution(Fx.Hash1, Fx.TxId1));
            AssertTxFailuresEqual(inputB, Fx.Store.GetTxExecution(Fx.Hash1, Fx.TxId2));
            AssertTxFailuresEqual(inputC, Fx.Store.GetTxExecution(Fx.Hash2, Fx.TxId1));
            Assert.Null(Fx.Store.GetTxExecution(Fx.Hash2, Fx.TxId2));
        }
예제 #2
0
 public ActionContextTest()
 {
     _random  = new System.Random();
     _address = _random.NextAddress();
     _txid    = _random.NextTxId();
 }
        public void UpdateTxExecutions(bool getTxExecutionViaStore)
        {
            void AssertTxSuccessesEqual(TxSuccess expected, TxExecution actual)
            {
                Assert.IsType <TxSuccess>(actual);
                var success = (TxSuccess)actual;

                Assert.Equal(expected.TxId, success.TxId);
                Assert.Equal(expected.BlockHash, success.BlockHash);
                Assert.Equal(expected.UpdatedStates, success.UpdatedStates);
                Assert.Equal(expected.FungibleAssetsDelta, success.FungibleAssetsDelta);
                Assert.Equal(expected.UpdatedFungibleAssets, success.UpdatedFungibleAssets);
            }

            void AssertTxFailuresEqual(TxFailure expected, TxExecution actual)
            {
                Assert.IsType <TxFailure>(actual);
                var failure = (TxFailure)actual;

                Assert.Equal(expected.TxId, failure.TxId);
                Assert.Equal(expected.BlockHash, failure.BlockHash);
                Assert.Equal(expected.ExceptionName, failure.ExceptionName);
                Assert.Equal(expected.ExceptionMetadata, failure.ExceptionMetadata);
            }

            Func <BlockHash, TxId, TxExecution> getTxExecution
                = getTxExecutionViaStore
                ? (Func <BlockHash, TxId, TxExecution>)_blockChain.Store.GetTxExecution
                : _blockChain.GetTxExecution;

            Assert.Null(getTxExecution(_fx.Hash1, _fx.TxId1));
            Assert.Null(getTxExecution(_fx.Hash1, _fx.TxId2));
            Assert.Null(getTxExecution(_fx.Hash2, _fx.TxId1));
            Assert.Null(getTxExecution(_fx.Hash2, _fx.TxId2));

            var random = new System.Random();
            var inputA = new TxSuccess(
                _fx.Hash1,
                _fx.TxId1,
                ImmutableDictionary <Address, IValue> .Empty.Add(
                    random.NextAddress(),
                    (Text)"state value"
                    ),
                ImmutableDictionary <Address, IImmutableDictionary <Currency, FAV> > .Empty
                .Add(
                    random.NextAddress(),
                    ImmutableDictionary <Currency, FAV> .Empty.Add(
                        DumbAction.DumbCurrency,
                        DumbAction.DumbCurrency * 5
                        )
                    ),
                ImmutableDictionary <Address, IImmutableDictionary <Currency, FAV> > .Empty
                .Add(
                    random.NextAddress(),
                    ImmutableDictionary <Currency, FAV> .Empty.Add(
                        DumbAction.DumbCurrency,
                        DumbAction.DumbCurrency * 10
                        )
                    )
                );
            var inputB = new TxFailure(
                _fx.Hash1,
                _fx.TxId2,
                "AnExceptionName",
                Dictionary.Empty.Add("foo", 1).Add("bar", "baz")
                );
            var inputC = new TxFailure(
                _fx.Hash2,
                _fx.TxId1,
                "AnotherExceptionName",
                null
                );

            _blockChain.UpdateTxExecutions(new TxExecution[] { inputA, inputB, inputC });

            AssertTxSuccessesEqual(inputA, getTxExecution(_fx.Hash1, _fx.TxId1));
            AssertTxFailuresEqual(inputB, getTxExecution(_fx.Hash1, _fx.TxId2));
            AssertTxFailuresEqual(inputC, getTxExecution(_fx.Hash2, _fx.TxId1));
            Assert.Null(getTxExecution(_fx.Hash2, _fx.TxId2));
        }