clean up some hf code (#6354)

* clean up some hf code

* fix comments

* fix ubsan

* Revert "fix ubsan"
This commit is contained in:
Mayukha Vadari
2026-02-13 11:27:50 -05:00
committed by GitHub
parent 6728ab52b7
commit f73d8a6cf2
5 changed files with 202 additions and 192 deletions

View File

@@ -326,9 +326,9 @@ struct Wasm_test : public beast::unit_test::suite
}
{ // fail because trying to access nonexistent field
struct BadTestHostFunctions : public TestHostFunctions
struct FieldNotFoundHostFunctions : public TestHostFunctions
{
explicit BadTestHostFunctions(Env& env) : TestHostFunctions(env)
explicit FieldNotFoundHostFunctions(Env& env) : TestHostFunctions(env)
{
}
Expected<Bytes, HostFunctionError>
@@ -338,15 +338,15 @@ struct Wasm_test : public beast::unit_test::suite
}
};
std::shared_ptr<HostFunctions> hfs(new BadTestHostFunctions(env));
std::shared_ptr<HostFunctions> hfs(new FieldNotFoundHostFunctions(env));
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000);
checkResult(re, -201, 28'965);
}
{ // fail because trying to allocate more than MAX_PAGES memory
struct BadTestHostFunctions : public TestHostFunctions
struct OversizedFieldHostFunctions : public TestHostFunctions
{
explicit BadTestHostFunctions(Env& env) : TestHostFunctions(env)
explicit OversizedFieldHostFunctions(Env& env) : TestHostFunctions(env)
{
}
Expected<Bytes, HostFunctionError>
@@ -356,7 +356,7 @@ struct Wasm_test : public beast::unit_test::suite
}
};
std::shared_ptr<HostFunctions> hfs(new BadTestHostFunctions(env));
std::shared_ptr<HostFunctions> hfs(new OversizedFieldHostFunctions(env));
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000);
checkResult(re, -201, 28'965);
}
@@ -574,7 +574,7 @@ struct Wasm_test : public beast::unit_test::suite
auto const codecovWasm = hexToBytes(codecovTestsWasmHex);
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
auto const allowance = 201'503;
auto const allowance = 202'724;
auto re = runEscrowWasm(codecovWasm, hfs, ESCROW_FUNCTION_NAME, {}, allowance);
checkResult(re, 1, allowance);