public void Create_StateTransition_Error()
        {
            ulong amount     = 100UL;
            var   parameters = new object[] { };
            var   gasLimit   = (Gas)100_000;

            var fixture = new InternalExecutorTestFixture();

            fixture.SetGasMeterLimitAbove(gasLimit);

            StateTransitionResult stateTransitionResult = StateTransitionResult.Fail((Gas)1000, StateTransitionErrorKind.VmError);

            fixture.StateProcessor
            .Setup(sp => sp.Apply(It.IsAny <IState>(), It.IsAny <InternalCreateMessage>()))
            .Returns(stateTransitionResult);

            var internalExecutor = new InternalExecutor(
                fixture.LoggerFactory,
                fixture.State.Object,
                fixture.StateProcessor.Object);

            ICreateResult result = internalExecutor.Create <string>(fixture.SmartContractState, amount, parameters, gasLimit);

            fixture.State.Verify(s => s.Snapshot(), Times.Once);

            fixture.StateProcessor.Verify(sp =>
                                          sp.Apply(fixture.Snapshot, It.Is <InternalCreateMessage>(m =>
                                                                                                   m.Amount == amount &&
                                                                                                   m.Parameters == parameters &&
                                                                                                   m.GasLimit == gasLimit &&
                                                                                                   m.From == fixture.FromAddress &&
                                                                                                   m.Type == typeof(string).Name
                                                                                                   )));

            fixture.State.Verify(s => s.TransitionTo(fixture.Snapshot), Times.Never);

            fixture.GasMeter.Verify(g => g.Spend(stateTransitionResult.GasConsumed));

            Assert.False(result.Success);
            Assert.Equal(default(Address), result.NewContractAddress);
        }
Example #2
0
        public void Create_StateTransition_Success()
        {
            ulong amount     = 100UL;
            var   parameters = new object[] { };
            var   gasLimit   = (RuntimeObserver.Gas)SmartContractFormatLogic.GasLimitMaximum;

            var fixture = new InternalExecutorTestFixture();

            fixture.SetGasMeterLimitAbove(gasLimit);

            StateTransitionResult stateTransitionResult = StateTransitionResult.Ok((RuntimeObserver.Gas) 1000, uint160.One, new object());

            fixture.StateProcessor
            .Setup(sp => sp.Apply(It.IsAny <IState>(), It.IsAny <InternalCreateMessage>()))
            .Returns(stateTransitionResult);

            var internalExecutor = new InternalExecutor(
                fixture.GasMeter.Object,
                fixture.State.Object,
                fixture.StateProcessor.Object);

            ICreateResult result = internalExecutor.Create <string>(fixture.SmartContractState, amount, parameters, gasLimit);

            fixture.State.Verify(s => s.Snapshot(), Times.Once);

            fixture.StateProcessor.Verify(sp =>
                                          sp.Apply(fixture.Snapshot, It.Is <InternalCreateMessage>(m =>
                                                                                                   m.Amount == amount &&
                                                                                                   m.Parameters == parameters &&
                                                                                                   m.GasLimit == gasLimit &&
                                                                                                   m.From == fixture.FromAddress &&
                                                                                                   m.Type == typeof(string).Name
                                                                                                   )));

            fixture.State.Verify(s => s.TransitionTo(fixture.Snapshot));

            fixture.GasMeter.Verify(g => g.Spend(stateTransitionResult.GasConsumed));

            Assert.True(result.Success);
            Assert.Equal(stateTransitionResult.Success.ContractAddress.ToAddress(), result.NewContractAddress);
        }