Skip to content

Commit

Permalink
Fix the broken ts test, very tricky
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Dec 12, 2023
1 parent 65e2be6 commit 6a84b88
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ where
number_or_hash: Option<BlockNumberOrHash>,
state_overrides: Option<BTreeMap<H160, CallStateOverride>>,
) -> RpcResult<Bytes> {
log::info!(target: "rpc", "bear: --- Call request: {:?}", request);
let CallRequest {
from,
to,
Expand Down Expand Up @@ -175,6 +176,7 @@ where
};

let data = data.map(|d| d.0).unwrap_or_default();
log::debug!(target: "rpc", "bear: --- Call request: to {:?}", to);
match to {
Some(to) => {
if api_version == 1 {
Expand Down Expand Up @@ -270,6 +272,7 @@ where
error_on_execution_failure(&info.exit_reason, &info.value)?;
info.value
} else if api_version == 5 {
log::info!(target: "rpc", "bear: --- Ready for call api 5");
let info = self
.client
.call_api_at(params)
Expand All @@ -285,6 +288,7 @@ where
.map_err(|err| internal_err(format!("runtime error: {err}")))?
.map_err(|err| internal_err(format!("execution fatal: {err:?}")))?;

log::debug!(target: "rpc", "bear: --- Call request: result {:?}", info);
error_on_execution_failure(&info.exit_reason, &info.value)?;
info.value
} else {
Expand Down Expand Up @@ -373,6 +377,7 @@ where
.map_err(|err| internal_err(format!("runtime error: {err}")))?;
Ok(Bytes(code))
} else if api_version == 5 {
log::info!(target: "rpc", "bear: --- Ready for call api 5");
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
let info = api
Expand All @@ -396,6 +401,7 @@ where
.map_err(|err| internal_err(format!("runtime error: {err}")))?
.map_err(|err| internal_err(format!("execution fatal: {err:?}")))?;

log::debug!(target: "rpc", "bear: --- Call request: result {:?}", info);
error_on_execution_failure(&info.exit_reason, &[])?;

let code = api
Expand Down
14 changes: 10 additions & 4 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ where
});
}

log::info!(target: "rpc", "bear: --- Before withdraw, max_fee_per_gas: {:?}, max_priority_fee_per_gas: {:?}, is_transactional: {:?}", max_fee_per_gas, max_priority_fee_per_gas, is_transactional);
let (total_fee_per_gas, _actual_priority_fee_per_gas) =
match (max_fee_per_gas, max_priority_fee_per_gas, is_transactional) {
// Zero max_fee_per_gas for validated transactional calls exist in XCM -> EVM
Expand All @@ -202,7 +203,7 @@ where
(Some(_), None, _) => (base_fee, U256::zero()),
// With tip, we include as much of the tip on top of base_fee that we can, never
// exceeding max_fee_per_gas
(Some(max_fee_per_gas), Some(max_priority_fee_per_gas), _) => {
(Some(max_fee_per_gas), Some(max_priority_fee_per_gas), true) => {
let actual_priority_fee_per_gas = max_fee_per_gas
.saturating_sub(base_fee)
.min(max_priority_fee_per_gas);
Expand All @@ -211,9 +212,8 @@ where
actual_priority_fee_per_gas,
)
}
// Gas price check is skipped for non-transactional calls that don't
// define a `max_fee_per_gas` input.
(None, _, false) => (Default::default(), U256::zero()),
// Gas price check is skipped for non-transactional calls or creates
(_, _, false) => (Default::default(), U256::zero()),
// Unreachable, previously validated. Handle gracefully.
_ => {
return Err(RunnerError {
Expand All @@ -233,8 +233,10 @@ where
})?;

// Deduct fee from the `source` account. Returns `None` if `total_fee` is Zero.
log::info!(target: "rpc", "bear: --- Before withdraw, total_fee: {:?}", total_fee);
let fee = T::OnChargeTransaction::withdraw_fee(&source, total_fee)
.map_err(|e| RunnerError { error: e, weight })?;
log::info!(target: "rpc", "bear: --- After withdraw");

// Execute the EVM call.
let vicinity = Vicinity {
Expand Down Expand Up @@ -424,6 +426,7 @@ where
config: &evm::Config,
) -> Result<CallInfo, RunnerError<Self::Error>> {
if validate {
log::info!(target: "rpc", "bear: --- Ready to validate");
Self::validate(
source,
Some(target),
Expand All @@ -440,6 +443,7 @@ where
config,
)?;
}
log::info!(target: "rpc", "bear: --- Pass validation");
let precompiles = T::PrecompilesValue::get();
Self::execute(
source,
Expand Down Expand Up @@ -472,6 +476,7 @@ where
config: &evm::Config,
) -> Result<CreateInfo, RunnerError<Self::Error>> {
if validate {
log::info!(target: "rpc", "bear: --- Ready to validate");
Self::validate(
source,
None,
Expand All @@ -487,6 +492,7 @@ where
proof_size_base_cost,
config,
)?;
log::info!(target: "rpc", "bear: --- Pass validation");
}
let precompiles = T::PrecompilesValue::get();
Self::execute(
Expand Down
2 changes: 2 additions & 0 deletions primitives/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ evm = { workspace = true, features = ["with-codec"] }
num_enum = { workspace = true, default-features = false }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
log = { workspace = true }
serde = { workspace = true, optional = true }
# Substrate
frame-support = { workspace = true }
Expand All @@ -26,6 +27,7 @@ sp-std = { workspace = true }
default = ["std"]
std = [
"evm/std",
"log/std",
"evm/with-serde",
"num_enum/std",
"serde/std",
Expand Down
1 change: 1 addition & 0 deletions primitives/evm/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl<'config, E: From<TransactionValidationError>> CheckEvmTransaction<'config,
if self.config.is_transactional || fee > U256::zero() {
let total_payment = self.transaction.value.saturating_add(fee);
if who.balance < total_payment {
log::info!(target: "rpc", "bear: --- balance too low, is_transactional: {:?}, fee: {:?}, balance: {:?}, total_payment: {:?}", self.config.is_transactional ,fee, who.balance, total_payment);
return Err(TransactionValidationError::BalanceTooLow.into());
}
}
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
log = { workspace = true }

# Substrate
sp-api = { workspace = true }
Expand Down Expand Up @@ -68,6 +69,7 @@ with-paritydb-weights = []
std = [
"scale-codec/std",
"scale-info/std",
"log/std",
# Substrate
"sp-api/std",
"sp-block-builder/std",
Expand Down
5 changes: 5 additions & 0 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ impl_runtime_apis! {
);
let (weight_limit, proof_size_base_cost) = pallet_ethereum::Pallet::<Runtime>::transaction_weight(&transaction_data);

log::info!(target: "rpc", "bear: --- Ready to call the runner");
sp_std::if_std! {
println!("bear: --- Ready to call the runner");
}
<Runtime as pallet_evm::Config>::Runner::call(
from,
to,
Expand Down Expand Up @@ -753,6 +757,7 @@ impl_runtime_apis! {
);
let (weight_limit, proof_size_base_cost) = pallet_ethereum::Pallet::<Runtime>::transaction_weight(&transaction_data);

log::info!(target: "rpc", "bear: --- Ready to create the runner");
<Runtime as pallet_evm::Config>::Runner::create(
from,
data,
Expand Down
3 changes: 2 additions & 1 deletion ts-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"fmt": "prettier ./tests --write",
"build": "truffle compile",
"test": "mocha -r ts-node/register 'tests/**/*.ts'",
"test-sql": "FRONTIER_BACKEND_TYPE='sql' mocha -r ts-node/register 'tests/**/*.ts'"
"test-sql": "FRONTIER_BACKEND_TYPE='sql' mocha -r ts-node/register 'tests/**/*.ts'",
"test-s": "FRONTIER_BACKEND_TYPE='sql' mocha -r ts-node/register 'tests/**/test-contract.ts'"
},
"author": "",
"license": "ISC",
Expand Down
2 changes: 2 additions & 0 deletions ts-tests/tests/test-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describeWithFrontier("Frontier RPC (Contract)", (context) => {
});

it("eth_call contract create should return code", async function () {
console.log("bear: --- this is the second test case");
expect(
await context.web3.eth.call({
data: TEST_CONTRACT_BYTECODE,
Expand All @@ -65,6 +66,7 @@ describeWithFrontier("Frontier RPC (Contract)", (context) => {
});

it("eth_call at missing block returns error", async function () {
console.log("bear: --- this is the third test case");
const nonExistingBlockNumber = "999999";
return expect(
context.web3.eth.call(
Expand Down
1 change: 1 addition & 0 deletions ts-tests/tests/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export async function startFrontierNode(provider?: string): Promise<{
`--no-prometheus`,
`--sealing=Manual`,
`--no-grandpa`,
`--wasm-runtime-overrides=/home/bear/coding/rust-space/frontier/template/node/overridden-runtimes/`,
`--force-authoring`,
`-l${FRONTIER_LOG}`,
`--port=${PORT}`,
Expand Down

0 comments on commit 6a84b88

Please sign in to comment.