refactor: Use temINVALID_BYTECODE istead of temBAD_WASM (#8156)

This commit is contained in:
Sergey Kuznetsov
2026-09-02 11:41:36 +01:00
committed by GitHub
parent 74ec538296
commit ae87e88690
7 changed files with 19 additions and 19 deletions

View File

@@ -1271,7 +1271,7 @@ mod tests {
}
/// A panic during a check is its own status rather than one more malformed
/// module: the far side answers a node-local failure, not `temBAD_WASM`.
/// module: the far side answers a node-local failure, not `temINVALID_BYTECODE`.
#[test]
fn a_panic_during_a_check_becomes_a_status_instead_of_an_unwind() {
let crossed = guarded(

View File

@@ -132,7 +132,7 @@ enum TEMcodes : TERUnderlyingType {
temBAD_MPT,
temBAD_CIPHERTEXT,
temBAD_WASM,
temINVALID_BYTECODE,
};
//------------------------------------------------------------------------------

View File

@@ -37,7 +37,7 @@ runEscrowWasm(
// That is what makes this callable from a transactor's `preflight`, which has no view
// to build a host over.
//
// `temBAD_WASM` for every fault in the module - the transaction carries something this
// `temINVALID_BYTECODE` for every fault in the module - the transaction carries something this
// engine cannot run, so it is refused before it can reach the ledger.
// `telFAILED_PROCESSING` if the engine itself failed: nothing was learned about the
// module, and a defect here is not evidence that the transaction is malformed.

View File

@@ -205,7 +205,7 @@ transResults()
MAKE_ERROR(temBAD_TRANSFER_FEE, "Malformed: Transfer fee is outside valid range."),
MAKE_ERROR(temINVALID_INNER_BATCH, "Malformed: Invalid inner batch transaction."),
MAKE_ERROR(temBAD_CIPHERTEXT, "Malformed: Invalid ciphertext."),
MAKE_ERROR(temBAD_WASM, "Malformed: Provided WASM code is invalid."),
MAKE_ERROR(temINVALID_BYTECODE, "Malformed: Provided byte code is invalid."),
MAKE_ERROR(terRETRY, "Retry transaction."),
MAKE_ERROR(terFUNDS_SPENT, "DEPRECATED."),

View File

@@ -104,7 +104,7 @@ verdict(CheckStatus status)
case CheckStatus::EntryPoint:
case CheckStatus::Memory:
case CheckStatus::Table:
return temBAD_WASM;
return temINVALID_BYTECODE;
// The engine panicked: a defect in the engine, reported rather than fatal to
// the node, and not the transaction's fault.

View File

@@ -62,8 +62,8 @@ TEST_F(PreflightTest, RunnableContractPasses)
TEST_F(PreflightTest, GarbageIsRefused)
{
EXPECT_EQ(preflightBytes(Bytes{}), temBAD_WASM);
EXPECT_EQ(preflightBytes(Bytes{0x00, 0x61, 0x73, 0x6d}), temBAD_WASM);
EXPECT_EQ(preflightBytes(Bytes{}), temINVALID_BYTECODE);
EXPECT_EQ(preflightBytes(Bytes{0x00, 0x61, 0x73, 0x6d}), temINVALID_BYTECODE);
}
// The engine takes wasm binaries, and text is not one. The suite writes its modules as text
@@ -73,7 +73,7 @@ TEST_F(PreflightTest, TextFormatModuleIsRefused)
{
Bytes const text{kRunnableWat.begin(), kRunnableWat.end()};
EXPECT_EQ(preflightBytes(text), temBAD_WASM);
EXPECT_EQ(preflightBytes(text), temINVALID_BYTECODE);
EXPECT_EQ(preflight(kRunnableWat), tesSUCCESS) << "the same module, assembled first";
}
@@ -86,7 +86,7 @@ TEST_F(PreflightTest, ImportOfAnUnknownHostFunctionIsRefused)
(func (export "escrow_finish") (result i32) (call $f (i32.const 0))))
)wat";
EXPECT_EQ(preflight(wat), temBAD_WASM);
EXPECT_EQ(preflight(wat), temINVALID_BYTECODE);
EXPECT_THAT(logged(), testing::HasSubstr("no host function 'no_such_function'"));
}
@@ -101,7 +101,7 @@ TEST_F(PreflightTest, ImportFromAnotherModuleIsRefused)
(func (export "escrow_finish") (result i32) (i32.const 0)))
)wat";
EXPECT_EQ(preflight(wat), temBAD_WASM);
EXPECT_EQ(preflight(wat), temINVALID_BYTECODE);
EXPECT_THAT(logged(), testing::HasSubstr("is not from 'host_lib'"));
}
@@ -115,7 +115,7 @@ TEST_F(PreflightTest, MemoryPastTheCapIsRefused)
(func (export "escrow_finish") (result i32) (i32.const 0)))
)wat";
EXPECT_EQ(preflight(tooMuch), temBAD_WASM);
EXPECT_EQ(preflight(tooMuch), temINVALID_BYTECODE);
EXPECT_THAT(logged(), testing::HasSubstr("memory: initial memory of 129 pages"));
constexpr std::string_view atTheCap = R"wat(
@@ -139,7 +139,7 @@ TEST_F(PreflightTest, TablePastTheCapIsRefused)
(func (export "escrow_finish") (result i32) (i32.const 0)))
)wat";
EXPECT_EQ(preflight(tooMuch), temBAD_WASM);
EXPECT_EQ(preflight(tooMuch), temINVALID_BYTECODE);
EXPECT_THAT(logged(), testing::HasSubstr("table: initial table of 1025 elements"));
constexpr std::string_view atTheCap = R"wat(
@@ -160,7 +160,7 @@ TEST_F(PreflightTest, MissingEntryPointIsRefused)
(func (export "other") (result i32) (i32.const 0)))
)wat";
EXPECT_EQ(preflight(wat), temBAD_WASM);
EXPECT_EQ(preflight(wat), temINVALID_BYTECODE);
EXPECT_THAT(logged(), testing::HasSubstr("no entry point 'escrow_finish'"));
}
@@ -172,7 +172,7 @@ TEST_F(PreflightTest, EntryPointOfTheWrongTypeIsRefused)
(func (export "escrow_finish") (result i64) (i64.const 0)))
)wat";
EXPECT_EQ(preflight(wat), temBAD_WASM);
EXPECT_EQ(preflight(wat), temINVALID_BYTECODE);
EXPECT_THAT(logged(), testing::HasSubstr("has the wrong signature"));
}
@@ -187,18 +187,18 @@ TEST_F(PreflightTest, EntryPointIsTheNameTheCallerGives)
)wat";
EXPECT_EQ(preflight(wat, "other"), tesSUCCESS);
EXPECT_EQ(preflight(wat), temBAD_WASM);
EXPECT_EQ(preflight(wat), temINVALID_BYTECODE);
}
// Every refusal is logged with the engine's own description and the TER: without it a node
// operator has a `temBAD_WASM` and no way to tell a contract author which of the three
// operator has a `temINVALID_BYTECODE` and no way to tell a contract author which of the three
// stages refused the module.
TEST_F(PreflightTest, RefusalNamesTheReasonAndTheTer)
{
EXPECT_EQ(preflightBytes(Bytes{0x00, 0x61, 0x73, 0x6d}), temBAD_WASM);
EXPECT_EQ(preflightBytes(Bytes{0x00, 0x61, 0x73, 0x6d}), temINVALID_BYTECODE);
EXPECT_THAT(logged(), testing::HasSubstr("compile: "));
EXPECT_THAT(logged(), testing::HasSubstr(transToken(temBAD_WASM)));
EXPECT_THAT(logged(), testing::HasSubstr(transToken(temINVALID_BYTECODE)));
}
// A module that passes screening still has to pass the run's own stages, and one that fails

View File

@@ -136,7 +136,7 @@ TEST_F(WasmVMTest, ModuleThatWillNotInstantiateIsChargedToTheContract)
EXPECT_TRUE(outcome.error().cost.has_value());
}
// Preflight is meant to refuse these with `temBAD_WASM`; reaching apply means the screening
// Preflight is meant to refuse these with `temINVALID_BYTECODE`; reaching apply means the screening
// did not happen, which is the node's fault and not the transaction's.
TEST_F(WasmVMTest, UnrunnableModuleIsNodeSideFault)
{