public void Transfer_GasRemaining_Error() { ulong amount = 100UL; var to = new Address("Sj2p6ZRHdLvywyi43HYoE4bu2TF1nvavjR"); var fixture = new InternalExecutorTestFixture(); fixture.SetGasMeterLimitBelow((Gas)InternalExecutor.DefaultGasLimit); var internalExecutor = new InternalExecutor( fixture.LoggerFactory, fixture.Network, fixture.State.Object, fixture.StateProcessor.Object); ITransferResult result = internalExecutor.Transfer(fixture.SmartContractState, to, amount); fixture.State.Verify(s => s.Snapshot(), Times.Never); fixture.StateProcessor.Verify(sp => sp.Apply(fixture.Snapshot, It.IsAny <ContractTransferMessage>()), Times.Never); fixture.State.Verify(s => s.TransitionTo(fixture.Snapshot), Times.Never); fixture.GasMeter.Verify(g => g.Spend(It.IsAny <Gas>()), Times.Never); Assert.False(result.Success); Assert.Null(result.ReturnValue); }
public void Transfer_GasRemaining_Error() { var fixture = new InternalExecutorTestFixture(); fixture.SetGasMeterLimitBelow((Gas)GasPriceList.TransferCost); ulong amount = 100UL; var to = "0x95D34980095380851902ccd9A1Fb4C813C2cb639".HexToAddress(); var internalExecutor = new InternalExecutor( fixture.LoggerFactory, fixture.State.Object, fixture.StateProcessor.Object); ITransferResult result = internalExecutor.Transfer(fixture.SmartContractState, to, amount); fixture.State.Verify(s => s.Snapshot(), Times.Never); fixture.StateProcessor.Verify(sp => sp.Apply(fixture.Snapshot, It.IsAny <ContractTransferMessage>()), Times.Never); fixture.State.Verify(s => s.TransitionTo(fixture.Snapshot), Times.Never); fixture.GasMeter.Verify(g => g.Spend(It.IsAny <Gas>()), Times.Never); Assert.False(result.Success); Assert.Null(result.ReturnValue); }
public void Transfer_StateTransition_Error() { ulong amount = 100UL; var to = new Address("Sj2p6ZRHdLvywyi43HYoE4bu2TF1nvavjR"); var fixture = new InternalExecutorTestFixture(); fixture.SetGasMeterLimitAbove((Gas)InternalExecutor.DefaultGasLimit); StateTransitionResult stateTransitionResult = StateTransitionResult.Fail((Gas)1000, new ContractErrorMessage("Error")); fixture.StateProcessor .Setup(sp => sp.Apply(It.IsAny <IState>(), It.IsAny <ContractTransferMessage>())) .Returns(stateTransitionResult); var internalExecutor = new InternalExecutor( fixture.LoggerFactory, fixture.Network, fixture.State.Object, fixture.StateProcessor.Object); ITransferResult result = internalExecutor.Transfer(fixture.SmartContractState, to, amount); fixture.State.Verify(s => s.Snapshot(), Times.Once); fixture.StateProcessor.Verify(sp => sp.Apply(fixture.Snapshot, It.Is <ContractTransferMessage>(m => m.Amount == amount && m.GasLimit == InternalExecutor.DefaultGasLimit && m.From == fixture.FromAddress && m.To == to.ToUint160(fixture.Network) ))); fixture.State.Verify(s => s.TransitionTo(fixture.Snapshot), Times.Never); fixture.GasMeter.Verify(g => g.Spend(stateTransitionResult.GasConsumed), Times.Once); Assert.False(result.Success); Assert.Null(result.ReturnValue); }
public void Transfer_StateTransition_Error() { var fixture = new InternalExecutorTestFixture(); ulong amount = 100UL; var to = "0x95D34980095380851902ccd9A1Fb4C813C2cb639".HexToAddress(); fixture.SetGasMeterLimitAbove((Gas)InternalExecutor.DefaultGasLimit); StateTransitionResult stateTransitionResult = StateTransitionResult.Fail((Gas)1000, StateTransitionErrorKind.VmError); fixture.StateProcessor .Setup(sp => sp.Apply(It.IsAny <IState>(), It.IsAny <ContractTransferMessage>())) .Returns(stateTransitionResult); var internalExecutor = new InternalExecutor( fixture.LoggerFactory, fixture.State.Object, fixture.StateProcessor.Object); ITransferResult result = internalExecutor.Transfer(fixture.SmartContractState, to, amount); fixture.State.Verify(s => s.Snapshot(), Times.Once); fixture.StateProcessor.Verify(sp => sp.Apply(fixture.Snapshot, It.Is <ContractTransferMessage>(m => m.Amount == amount && m.GasLimit == InternalExecutor.DefaultGasLimit && m.From == fixture.FromAddress && m.To == to.ToUint160() ))); fixture.State.Verify(s => s.TransitionTo(fixture.Snapshot), Times.Never); fixture.GasMeter.Verify(g => g.Spend(stateTransitionResult.GasConsumed), Times.Once); Assert.False(result.Success); Assert.Null(result.ReturnValue); }