Merge pull request #124 from gavofyork/transaction_tests_fixes
executive error on not enoguh base gas
This commit is contained in:
commit
123c991c2e
@ -19,16 +19,19 @@ pub struct OutOfBounds<T: fmt::Debug> {
|
|||||||
/// Result of executing the transaction.
|
/// Result of executing the transaction.
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum ExecutionError {
|
pub enum ExecutionError {
|
||||||
|
/// Returned when there gas paid for transaction execution is
|
||||||
|
/// lower than base gas required.
|
||||||
|
NotEnoughBaseGas { required: U256, got: U256 },
|
||||||
/// Returned when block (gas_used + gas) > gas_limit.
|
/// Returned when block (gas_used + gas) > gas_limit.
|
||||||
///
|
///
|
||||||
/// If gas =< gas_limit, upstream may try to execute the transaction
|
/// If gas =< gas_limit, upstream may try to execute the transaction
|
||||||
/// in next block.
|
/// in next block.
|
||||||
BlockGasLimitReached { gas_limit: U256, gas_used: U256, gas: U256 },
|
BlockGasLimitReached { gas_limit: U256, gas_used: U256, gas: U256 },
|
||||||
/// Returned when transaction nonce does not match state nonce.
|
/// Returned when transaction nonce does not match state nonce.
|
||||||
InvalidNonce { expected: U256, is: U256 },
|
InvalidNonce { expected: U256, got: U256 },
|
||||||
/// Returned when cost of transaction (value + gas_price * gas) exceeds
|
/// Returned when cost of transaction (value + gas_price * gas) exceeds
|
||||||
/// current sender balance.
|
/// current sender balance.
|
||||||
NotEnoughCash { required: U512, is: U512 },
|
NotEnoughCash { required: U512, got: U512 },
|
||||||
/// Returned when internal evm error occurs.
|
/// Returned when internal evm error occurs.
|
||||||
Internal
|
Internal
|
||||||
}
|
}
|
||||||
|
@ -109,11 +109,18 @@ impl<'a> Executive<'a> {
|
|||||||
let sender = try!(t.sender());
|
let sender = try!(t.sender());
|
||||||
let nonce = self.state.nonce(&sender);
|
let nonce = self.state.nonce(&sender);
|
||||||
|
|
||||||
// TODO: error on base gas required
|
let schedule = self.engine.schedule(self.info);
|
||||||
|
let base_gas_required = U256::from(t.gas_required(&schedule));
|
||||||
|
|
||||||
|
if t.gas < base_gas_required {
|
||||||
|
return Err(From::from(ExecutionError::NotEnoughBaseGas { required: base_gas_required, got: t.gas }));
|
||||||
|
}
|
||||||
|
|
||||||
|
let init_gas = t.gas - base_gas_required;
|
||||||
|
|
||||||
// validate transaction nonce
|
// validate transaction nonce
|
||||||
if t.nonce != nonce {
|
if t.nonce != nonce {
|
||||||
return Err(From::from(ExecutionError::InvalidNonce { expected: nonce, is: t.nonce }));
|
return Err(From::from(ExecutionError::InvalidNonce { expected: nonce, got: t.nonce }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate if transaction fits into given block
|
// validate if transaction fits into given block
|
||||||
@ -132,7 +139,7 @@ impl<'a> Executive<'a> {
|
|||||||
|
|
||||||
// avoid unaffordable transactions
|
// avoid unaffordable transactions
|
||||||
if U512::from(balance) < total_cost {
|
if U512::from(balance) < total_cost {
|
||||||
return Err(From::from(ExecutionError::NotEnoughCash { required: total_cost, is: U512::from(balance) }));
|
return Err(From::from(ExecutionError::NotEnoughCash { required: total_cost, got: U512::from(balance) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: there can be no invalid transactions from this point.
|
// NOTE: there can be no invalid transactions from this point.
|
||||||
@ -141,9 +148,6 @@ impl<'a> Executive<'a> {
|
|||||||
|
|
||||||
let mut substate = Substate::new();
|
let mut substate = Substate::new();
|
||||||
|
|
||||||
let schedule = self.engine.schedule(self.info);
|
|
||||||
let init_gas = t.gas - U256::from(t.gas_required(&schedule));
|
|
||||||
|
|
||||||
let res = match t.action() {
|
let res = match t.action() {
|
||||||
&Action::Create => {
|
&Action::Create => {
|
||||||
let params = ActionParams {
|
let params = ActionParams {
|
||||||
@ -937,8 +941,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Err(Error::Execution(ExecutionError::InvalidNonce { expected, is }))
|
Err(Error::Execution(ExecutionError::InvalidNonce { expected, got }))
|
||||||
if expected == U256::zero() && is == U256::one() => (),
|
if expected == U256::zero() && got == U256::one() => (),
|
||||||
_ => assert!(false, "Expected invalid nonce error.")
|
_ => assert!(false, "Expected invalid nonce error.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -988,8 +992,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Err(Error::Execution(ExecutionError::NotEnoughCash { required , is }))
|
Err(Error::Execution(ExecutionError::NotEnoughCash { required , got }))
|
||||||
if required == U512::from(100_018) && is == U512::from(100_017) => (),
|
if required == U512::from(100_018) && got == U512::from(100_017) => (),
|
||||||
_ => assert!(false, "Expected not enough cash error. {:?}", res)
|
_ => assert!(false, "Expected not enough cash error. {:?}", res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user